5

I am trying to create a snapshot/daily build of my Python package, using Setuptools and Build (the PEP 517 build module).

I have tried adapting this section of the Setuptools documentation: https://setuptools.pypa.io/en/latest/userguide/distribution.html#tagging-and-daily-build-or-snapshot-releases

However, none of the following commands worked:

python -m build --config-setting=--tag-date myproject
python -m build --config-setting=tag-date myproject
python -m build --tag-date myproject

The first two build the package without the version tag, while the third is an error. The results are the same when I use --tag-build instead of --tag-date.

How can I tell Setuptools to add the version tag, if none of the above options work?

I do not have a setup.py, only a setup.cfg. I cannot use setup.py bdist_wheel --tag-date, this command will say "File not found" because setup.py does not exist in my project.

EDIT after searching through Setuptools issue tracker, I also tried the following commands, with no success:

python -m build --config-setting=--global-options=--tag-date myproject
python -m build --config-setting=--global-options=tag-date myproject
python -m build --config-setting=global-options=--tag-date myproject
python -m build --config-setting=global-options=tag-date myproject

2 Answers2

6

Digging through the setuptools code, it looks like the --tag-date and the --tag-build options are available if passed to egg_info.

Example:

python setup.py egg_info --tag-date --tag-build=dev bdist_wheel

As for combining setuptools with build, you were almost there, it's just that you had to chain egg_info and --tag-date together:

python -m build -C--global-option=egg_info -C--global-option=--tag-date --wheel 

Note that --tag-date doesn't take any value, it will just add date stamp (e.g. 20050528) to version number

Resources:

Source code for setuptools: https://github.com/pypa/setuptools/blob/00fbad0f93ffdba0a4d5c3f2012fd7c3de9af04d/setuptools/command/egg_info.py#L159

Package version:

build            0.7.0
setuptools       60.10.0
Saba
  • 81
  • 1
  • 4
  • 2
    Works, thanks, but unfortunately, it puts it in the wrong place!!! it overwrites the last part of the version number i.e. 4.1.0 -> 4.1. instead of the proper wheel format: 4.1.0- (https://peps.python.org/pep-0427/#file-name-convention) – Marc Jul 28 '22 at 18:19
  • @Marc that has something to do with Python `packaging` requirements for version. See https://github.com/pypa/packaging/blob/main/src/packaging/version.py for information on how it looks for appropriate version names. (Not saying you aren't right that this is confusing and unhelpful...) – abroekhof Apr 04 '23 at 21:04
0
python -m build -C--global-option=bdist_wheel -C--global-option=--build-number=<build-number>

Adds the pep427 approved build number after your version number. (<version>-<build-number>)

I haven't tried it with a string tag.

Marc
  • 3,259
  • 4
  • 30
  • 41