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

Unable to handle tags with dashes in the name, tag_regex config not helping #825

Open
pelson opened this issue Mar 24, 2023 · 5 comments
Open
Labels

Comments

@pelson
Copy link
Contributor

pelson commented Mar 24, 2023

When using setuptools-scm with tags containing dashes, I'm unable to configure setuptools-scm to parse the version correctly. I have been able to configure the git describe phase, but the subsequent parsing of the tag does not appear to be using the tag_regex specified.

I tested against master at fb26133, and on many of the recent releases, and put together a build script which can create a simple case:

rm -rf example
mkdir -p example/prj1
cd example
git init
cd prj1

cat <<-EOF > pyproject.toml

[project]
name = "Thing"
dynamic = ["version"]

[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]

[tool.setuptools_scm]
root=".."
tag_regex = '^(tag\-with\-dash\/v)?(?P<version>\d+[^\+]*)$'
git_describe_command = 'git describe --tags --match tag-with-dash/v*'


EOF

git add pyproject.toml
git commit -m "Make the project"
git tag tag-with-dash/v1.2.3

python -m setuptools_scm

Note that if you remove the dashes from the tag, everything works as expected (even if you don't specify a tag_regex).

Traceback:

Traceback (most recent call last):
  File "runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "setuptools_scm/src/setuptools_scm/__main__.py", line 6, in <module>
    main()
  File "setuptools_scm/src/setuptools_scm/_cli.py", line 34, in main
    version = _get_version(config)
  File "setuptools_scm/src/setuptools_scm/__init__.py", line 145, in _get_version
    parsed_version = _do_parse(config)
  File "setuptools_scm/src/setuptools_scm/__init__.py", line 88, in _do_parse
    parsed_version = _version_from_entrypoints(config) or _version_from_entrypoints(
  File "setuptools_scm/src/setuptools_scm/_entrypoints.py", line 40, in _version_from_entrypoints
    maybe_version: version.ScmVersion | None = fn(root, config=config)
  File "src/setuptools_scm/git.py", line 179, in parse
    config, wd, describe_command=describe_command, pre_parse=pre_parse
  File "setuptools_scm/src/setuptools_scm/git.py", line 204, in _git_parse_inner
    tag, distance, node, dirty = _git_parse_describe(out)
  File "setuptools_scm/src/setuptools_scm/git.py", line 253, in _git_parse_describe
    number = int(number_)
ValueError: invalid literal for int() with base 10: 'with'

I dug a little, and can't see how the tag_regex is expected to work in _git_parse_describe, since the config isn't passed down from https://github.com/pypa/setuptools_scm/blob/fb261332d9b46aa5a258042d85baa5aa7b9f4fa2/src/setuptools_scm/git.py. Have I misunderstood the purpose of tag_regex perhaps?

@RonnyPfannschmidt
Copy link
Contributor

tag regex shouldn't be needed inside of _parse_describe,

i suspect a bug/regression

please include the output with SETUPTOOLS_SCM_DEBUG=1

@pelson
Copy link
Contributor Author

pelson commented Mar 24, 2023

abs root {'root': '.', 'relative_to': 'setuptools_scm/support/example/pyproject.toml'}
file setuptools_scm/support/example/pyproject.toml
root 'setuptools_scm/support/example'
relative_to 'setuptools_scm/support/example/pyproject.toml'
dist name: Thing
version_from_ep setuptools_scm.parse_scm setuptools_scm/support/example
looking for ep setuptools_scm.parse_scm setuptools_scm/support/example
found ep EntryPoint(name='.git', value='setuptools_scm.git:parse', group='setuptools_scm.parse_scm') in setuptools_scm/support/example
----
cmd:
     git --git-dir setuptools_scm/support/example/.git rev-parse --show-prefix
 in: setuptools_scm/support/example
out:
 

real root setuptools_scm/support/example
----
cmd:
     git describe --tags --match tag-with-dash/v*
 in: setuptools_scm/support/example
out:
     tag-with-dash/v1.2.3

@RonnyPfannschmidt
Copy link
Contributor

Thanks, it's clearly a oversight right from the start (i never anticipated tags with dashes)

I have a basic idea for a bugfix

@RonnyPfannschmidt
Copy link
Contributor

RonnyPfannschmidt commented Mar 24, 2023

@pelson based on

$ git tag i-have-dashes/v1.0
$ git describe --tags
i-have-dashes/v1.0
$ git describe --tags --long
i-have-dashes/v1.0-0-g8e83078
$

i recommend adding the --long option as a starting point, - i need to investigate always adding it

@pelson
Copy link
Contributor Author

pelson commented Mar 27, 2023

Yes, this did it - thanks! Indeed, ensuring that the --long is always specified is essential to ensure that the logic in https://github.com/pypa/setuptools_scm/blob/fb261332d9b46aa5a258042d85baa5aa7b9f4fa2/src/setuptools_scm/git.py#L247-L253 is always valid. Having said that, I saw that git_describe_tag doesn't always need to be a git command... #804 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants