setuptools_scm icon indicating copy to clipboard operation
setuptools_scm copied to clipboard

SETUPTOOLS_SCM_PRETEND_VERSION: parse node & distance

Open casperdcl opened this issue 1 year ago • 7 comments
trafficstars

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.

casperdcl avatar Jul 25 '24 12:07 casperdcl

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

RonnyPfannschmidt avatar Jul 25 '24 14:07 RonnyPfannschmidt

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)
"""

casperdcl avatar Jul 26 '24 09:07 casperdcl

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

RonnyPfannschmidt avatar Jul 26 '24 16:07 RonnyPfannschmidt

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

casperdcl avatar Jul 29 '24 09:07 casperdcl

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

RonnyPfannschmidt avatar Jul 29 '24 09:07 RonnyPfannschmidt

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

casperdcl avatar Jul 30 '24 08:07 casperdcl

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

RonnyPfannschmidt avatar Jul 30 '24 09:07 RonnyPfannschmidt