setuptools_scm
setuptools_scm copied to clipboard
SETUPTOOLS_SCM_PRETEND_VERSION: parse node & distance
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.
pretend_version currently has no scm metadata avaliable, its a string and not turned back into a scm_version - there should be warnings
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)
"""
I think I need to introduce a mechanism to provide scm version metadata
Perhaps adding e.g. (?P<node>) and (?P<distance>) to DEFAULT_TAG_REGEX?
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
you mean you'd prefer SETUPTOOLS_SCM_PRETEND_{NODE,DISTANCE}?
The idea would be to inject a toml mapping with the metadata