Passing --tag-build or --tag-date to setuptools PEP 517 builder
Asked Answered
B

2

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
Bedazzle answered 14/12, 2021 at 12:15 Comment(0)
V
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
Victory answered 23/3, 2022 at 12:8 Comment(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.<build tag> instead of the proper wheel format: 4.1.0-<build tag> (peps.python.org/pep-0427/#file-name-convention)Pulmotor
@Pulmotor that has something to do with Python packaging requirements for version. See 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...)Gregory
P
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.

Pulmotor answered 28/7, 2022 at 18:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.