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

家住魔仙堡 提交于 2020-01-21 19:42:27

问题


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 is plenty of information on the basic setup and configuration required:

  • SetupTools Documentation - setup() and setup.py configuration
  • Python Packaging User Guide - Installing Packages
  • PBR v3.1.1 documentation
  • StackOverflow: How to use version info generated using setuptools and pbr

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

i.e. I'm looking for whatever command finds the git tag with the version info and pulls it into the configuration info, so the source with that new version info can be distributed, and the version info is discoverable from the scripts, using a method like described in this answer.


Additional details

I'm working on a project that will be distributed to other developers only through a git repo, not through PyPi. The project will be released to users as an executable using pyinstaller, so this package distribution will only serve a few key purposes:

  1. Install/Setup the package for other developers so that dependencies/environment can be recreated cleanly.
  2. Manage versioning - Current plan is to use pbr to generate versions from the Git repo tags, so those tags can be our source of truth for versioning
  3. Use pbr for other auto generation of mundane items from Git, such as authors, manifest.in file, release notes, etc.

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.

I'm sure it exists somewhere in the documentation, but after several false starts I'm asking here. It is implied everywhere I look that everyone either knows how to do this or it just magically happens as a part of the process.

Am I just missing the obvious?


Update:

Based on sinoroc's answer, it appears I need to look into development mode installs. i.e. Anyone developing the project will clone from git, and then install via using setuptools development install mode.

This wasn't directly a part of the original question, but implied, and I believe will be of interest to people in the same situation (info I couldn't easily find).

More info is available in his answer on updating some of the metadata, and via this setuptools documentation link to working in "Development Mode"


回答1:


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.



来源:https://stackoverflow.com/questions/58491577/python-setuptools-and-pbr-how-to-create-a-package-release-using-the-git-tag-as

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!