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

前端 未结 2 1394
长情又很酷
长情又很酷 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条回答
  • 2020-12-19 16:50

    In short:

    • python3 setup.py sdist
    • python3 setup.py bdist_wheel

    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?

    The usual commands to create (source and wheel) distributions of your Python package with setuptools are: python3 setup.py sdist and python3 setup.py bdist_wheel. The distributions can then be found in the dist directory by default.

    Since setuptools docs focus on setting up a fully distributable and reusable package with PyPi and pip, and pbr docs only really tell you how to modify setuptools configuration to use pbr, I can't find the info on how to just run the distribution/release process.

    It is true that setuptools does not document this. It only documents the differences to distutils, and it is confusing indeed. See below for actual documentation...

    But where is the simple info on how to actually create the distro?

    • https://packaging.python.org/tutorials/packaging-projects/#generating-distribution-archives
    • https://docs.python.org/3/distutils/sourcedist.html
    • https://docs.python.org/3/distutils/builtdist.html

    Update

    Since you don't plan on publishing distributions of your project on an index such as PyPI, and you plan on using pyinstaller instead, then you can indeed most likely disregard the setuptools commands such as sdist and bdist_wheel.

    Still you might want to know these commands for the development phase:

    • Use commands such as python3 setup.py --version, python3 setup.py --fullname to figure out if setuptools (and in your case pbr) is catching the right info.
    • Use python3 setup.py develop (or pip install --editable .) to place a pseudo link (egg-link) in your site-packages that points at your work in progress. This way your changes are always installed and importable. Important: don't use python3 setup.py install, this would copy the current version to site-packages and newer changes would not be importable.

    Now I don't know how all this will work once you move on to pyinstaller. Especially since you mentioned that you want the meta info (such as the version number) to be discoverable from within your scripts. The technique with setuptools pkg_resources may or may not work in the pyinstaller context.

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题