pypa / setuptools-scm

the blessed package to manage your versions by scm tags
https://setuptools-scm.readthedocs.io/en/latest/
MIT License
860 stars 211 forks source link

SETUPTOOLS_SCM_PRETEND_VERSION: parse node & distance #1059

Open casperdcl opened 3 months ago

casperdcl commented 3 months ago

pyproject.toml config:

[tool.setuptools_scm]
version_file = "src/version.py"
version_file_template = """
version = '{version}'
major = {version_tuple[0]}
minor = {version_tuple[1]}
patch = {version_tuple[2]}
commit_hash = '{scm_version.node}'
num_commit = {scm_version.distance}
"""

build:

SETUPTOOLS_SCM_PRETEND_VERSION="1.2.3.dev4+g1337beef" python -m build .
cat src/version.py

output:

version = '1.2.3.dev4+g1337beef'
major = 1
minor = 2
patch = 3
commit_hash = 'None'
num_commit = 0

It's odd that version is correctly parsed into version_tuple but not scm_version.node nor scm_version.distance.

RonnyPfannschmidt commented 3 months ago

pretend_version currently has no scm metadata avaliable, its a string and not turned back into a scm_version - there should be warnings

casperdcl commented 3 months ago

ok, FYI I'm using this work-around:

[tool.setuptools_scm]
version_file_template = """
version = '{version}'
commit_hash = '{scm_version.node}'
distance = {scm_version.distance}
# work-around for https://github.com/pypa/setuptools_scm/issues/1059
if (commit_hash, distance) == ('None', 0):
    import re
    if (_v := re.search(r'\\.dev(\\d+)\\+(\\w+)', version)):
        distance, commit_hash = int(_v.group(1)), _v.group(2)
"""
RonnyPfannschmidt commented 3 months ago

I think I need to introduce a mechanism to provide scm version metadata

casperdcl commented 3 months ago

Perhaps adding e.g. (?P<node>) and (?P<distance>) to DEFAULT_TAG_REGEX?

RonnyPfannschmidt commented 3 months ago

adding those to the tag regex will do no good

instead good default overrides as well as a utility helper to create the overrides from forge metadata will be required

casperdcl commented 3 months ago

you mean you'd prefer SETUPTOOLS_SCM_PRETEND_{NODE,DISTANCE}?

RonnyPfannschmidt commented 3 months ago

The idea would be to inject a toml mapping with the metadata