Python Setuptools and PBR - how to create a package release using the git tag as the version?

前端 未结 2 1544
长情又很酷
长情又很酷 2020-12-19 16:25

How do I actually create a release/distro of a python package that uses a git repo tag for the versioning, using setuptools and pbr?

There

2条回答
  •  猫巷女王i
    2020-12-19 16:51

    This is how I solved the same issue, also having read several different links. I have created a setup.py file with this content:

    from setuptools import setup, find_packages
    
    def readme():
        with open('README.rst') as f:
            return f.read()
    
    def read_other_requirements(other_type):
        with open(other_type+'-requirements.txt') as f:
            return f.read()
    
    setup(
          setup_requires=read_other_requirements('setup'),
          pbr=True,
          packages=find_packages('src'),
          package_dir={'': 'src'},
          include_package_data=True,
          zip_safe=True
    )
    

    I have the source code in ./src. Also, I have a setup-requirements.txt, with content:

    pip==18.1
    pbr==5.1.1
    setuptools==40.7.0
    

    And a setup.cfg with this content:

    [metadata]
    name = XXXXX
    description = XXXXX
    description-file = README.rst
    home-page = https://github.com/XXXXX/XXXXX
    

    So first, you install the setup-requirements:

    pip install -r setup-requirements.txt

    Then, whenever you have locally a commit which was tagged in GitHub, you can install it using:

    python setup.py install

    and it will be installed with the tagged version. You can check it by doing:

    python setup.py --version

提交回复
热议问题