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

前端 未结 2 1393
长情又很酷
长情又很酷 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.

提交回复
热议问题