Skip to content

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

Open
@pelson

Description

@pelson

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions