cold-vr-15232
02/26/2023, 10:12 PMenough-analyst-54434
02/27/2023, 2:01 AMvcs_version
target in metadata, this is how you'd do it if you use setuptools to package your project (this is the pyproject.toml setup, but you can do it with setup.cfg too if that's what you like):
+ https://www.pantsbuild.org/docs/reference-vcs_version#codegenerate_tocode
+ https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata
To debug, run `pants --keep-sandboxes=always package ...`and inspect the package sandbox to observe the relative path of the version file as well as its contents and play with the version
configuration in pyproject.toml
until you have things working how you'd like.cold-vr-15232
02/27/2023, 8:37 AMcold-vr-15232
02/27/2023, 3:28 PMenough-analyst-54434
02/27/2023, 3:41 PMcold-vr-15232
02/27/2023, 3:46 PMenough-analyst-54434
02/27/2023, 3:50 PMpython_artifact
target? The whole point is to not do that.cold-vr-15232
02/27/2023, 3:55 PMEngine traceback:
`in package
goal`
`InvalidSetupPyArgs: Missing a version
kwarg in the provides
field for libs/lib2:lib2. See https://www.pantsbuild.org/v2.15/docs/python-distributions.`enough-analyst-54434
02/27/2023, 3:58 PMcold-vr-15232
02/27/2023, 4:06 PMenough-analyst-54434
02/27/2023, 4:16 PMenv("X")
in BUILD files + .pants.bootstrap
which is a bash file sourced for env var exports.enough-analyst-54434
02/27/2023, 4:19 PMvcs_version
target is provided, but the rule code still forces you to specify a manual version - that clearly makes no sense / does not integrate.enough-analyst-54434
02/27/2023, 4:21 PMenv
is, in fact, python_distribution
version: https://github.com/pantsbuild/pants/blob/main/docs/markdown/Using%20Pants/concepts/targets.md#environment-variablesenough-analyst-54434
02/27/2023, 5:01 PMvcs_version
does work as advertised but you must explicitly set generate_setup=False
in your python_distribution
target. That seems like a minor bug, but I'm sure I don't understand the details.
This works in the Pants repo:
$ cat setup.cfg
[metadata]
name = test-project
version = file: _version.txt
author = Zaphod Beeblebrox
author_email = <mailto:prez@galaxy.gov|prez@galaxy.gov>
description = Smoke out vcs_version use in practice.
license = BSD-3-Clause
$ cat setup.py
from setuptools import setup
setup()
$ cat BUILD.setup
vcs_version(
name="version",
generate_to="_version.txt",
tag_regex=r"^release_(?P<version>.+)(?:(?:rc|a|.dev)\d+)?$",
template="{version}",
)
resources(
name="project_metadata",
sources=["setup.cfg", "setup.py"],
)
python_distribution(
name="test-project",
provides=python_artifact(
name="test-project",
),
generate_setup=False,
dependencies=[
":version",
":project_metadata",
]
)
$ pants package //:test-project
08:57:51.59 [INFO] Completed: Run setuptools_scm for //:version
08:57:51.59 [INFO] Wrote dist/test-project-2.16.1.dev37+geb9eda8364.tar.gz
08:57:51.59 [INFO] Wrote dist/test_project-2.16.1.dev37+geb9eda8364-py3-none-any.whl
$ unzip -qc dist/test_project-2.16.1.dev37+geb9eda8364-py3-none-any.whl test_project-2.16.1.dev37+geb9eda8364.dist-info/METADATA | grep Version
Metadata-Version: 2.1
Version: 2.16.1.dev37+geb9eda8364
enough-analyst-54434
02/27/2023, 5:03 PMtag_regex
that can handle Pants tagging convention and extract such a semver. It seems to require the X.Y.Z because it auto-bumps the version if not on the exact tag, but one or more commits after the closest tag.enough-analyst-54434
02/27/2023, 5:10 PMenough-analyst-54434
02/27/2023, 5:13 PMjsirois@Gill-Windows:~/dev/pantsbuild/jsirois-pants ((release_2.15.0)) $ ./pants package //:test-project
09:11:11.24 [INFO] Completed: Run setuptools_scm for //:version
09:11:13.40 [INFO] Completed: Building build_backend.pex from setuptools_default.lock
09:11:13.58 [INFO] Wrote dist/test-project-2.15.0.tar.gz
09:11:13.58 [INFO] Wrote dist/test_project-2.15.0-py3-none-any.whl
So it just seems like the patch bump + .dev... is overzealous since there is no such thing as the patch bump version to offset from, its the tagged version that is offset from. If you do end up using this vcs_version
@cold-vr-15232 and you have an opinion on that bump behavior, definitely speak up.cold-vr-15232
02/28/2023, 9:33 AM