Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SETUPTOOLS_SCM_PRETEND_VERSION: parse node & distance #1059

Open
casperdcl opened this issue Jul 25, 2024 · 7 comments
Open

SETUPTOOLS_SCM_PRETEND_VERSION: parse node & distance #1059

casperdcl opened this issue Jul 25, 2024 · 7 comments

Comments

@casperdcl
Copy link

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 added a commit to TomographicImaging/CIL that referenced this issue Jul 25, 2024
@RonnyPfannschmidt
Copy link
Contributor

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

casperdcl added a commit to TomographicImaging/CIL that referenced this issue Jul 26, 2024
@casperdcl
Copy link
Author

casperdcl commented Jul 26, 2024

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
Copy link
Contributor

RonnyPfannschmidt commented Jul 26, 2024

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

@casperdcl
Copy link
Author

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

@RonnyPfannschmidt
Copy link
Contributor

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
Copy link
Author

casperdcl commented Jul 30, 2024

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

@RonnyPfannschmidt
Copy link
Contributor

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

casperdcl added a commit to TomographicImaging/CIL that referenced this issue Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants