Skip to content

Conversation

dlitz
Copy link
Contributor

@dlitz dlitz commented Oct 14, 2022

Given .git_archival.txt content like this:

node: 3634907645428b9542cfb4fd1ceef08f14526cb8
node-date: 2022-10-13T20:38:09-06:00
describe-name: v0.0.5
ref-names: HEAD -> main, tag: v0.0.5

setuptools_scm fails with an exception like this:

$ python3 -m setuptools_scm
Traceback (most recent call last):
  [..snip..]
  File ".../setuptools_scm/git.py", line 312, in parse_archival
    return archival_to_version(data, config=config)
  File ".../setuptools_scm/git.py", line 286, in archival_to_version
    tag, number, node, _ = _git_parse_describe(archival_describe)
  File ".../setuptools_scm/git.py", line 245, in _git_parse_describe
    tag, number, node = describe_output.rsplit("-", 2)
ValueError: not enough values to unpack (expected 3, got 1)

The problem here is that the describe-name field is "v0.0.5" instead of
something like "v0.0.5-0-g3634907", so the tuple unpacking fails.

So, it works correctly with untagged versions of the repo:

$ tmpdir=$(mktemp -d)
$ git archive HEAD | tar -C "$tmpdir" -xf -
$ ( cd "$tmpdir" ; python3 -m setuptools_scm )
0.0.1.dev7+gb03bd8b

But if we tag the repo and create another archive, the exception occurs:

$ git tag v0.0.1 HEAD
$ tmpdir=$(mktemp -d)
$ git archive HEAD | tar -C "$tmpdir" -xf -
$ ( cd "$tmpdir" ; python3 -m setuptools_scm )
Traceback (most recent call last):
  [..snip..]
  File "/usr/lib/python3/dist-packages/setuptools_scm/git.py", line 316, in parse_archival
    return archival_to_version(data, config=config)
  File "/usr/lib/python3/dist-packages/setuptools_scm/git.py", line 290, in archival_to_version
    tag, number, node, _ = _git_parse_describe(archival_describe)
  File "/usr/lib/python3/dist-packages/setuptools_scm/git.py", line 245, in _git_parse_describe
    tag, number, node = describe_output.rsplit("-", 2)
ValueError: not enough values to unpack (expected 3, got 1)

Version information:

$ pip show setuptools_scm | grep ^Version
Version: 7.0.5
$ dpkg -s python3-setuptools-scm | grep ^Version
Version: 7.0.5-1

The first commit of the pull-request proposes a fix for that.

The second commit fixes #759.

dlitz added 2 commits October 14, 2022 03:46
Given .git_archival.txt content like this:

    node: 3634907645428b9542cfb4fd1ceef08f14526cb8
    node-date: 2022-10-13T20:38:09-06:00
    describe-name: v0.0.5
    ref-names: HEAD -> main, tag: v0.0.5

we would previously fail with an exception like this:

    $ python3 -m setuptools_scm
    Traceback (most recent call last):
      [..snip..]
      File ".../setuptools_scm/git.py", line 312, in parse_archival
        return archival_to_version(data, config=config)
      File ".../setuptools_scm/git.py", line 286, in archival_to_version
        tag, number, node, _ = _git_parse_describe(archival_describe)
      File ".../setuptools_scm/git.py", line 245, in _git_parse_describe
        tag, number, node = describe_output.rsplit("-", 2)
    ValueError: not enough values to unpack (expected 3, got 1)

The problem is that the describe-name field is "v0.0.5" instead of
looking like "v0.0.5-0-g3634907".

When we invoke git-describe ourselves, we specify the --long option, but
the format-strings implemented by git-archive do not currently give us
any way to force long-output in a .git_archival.txt file.

This change detects this condition and returns None for the missing
fields.
…h how we invoke git-describe

This covers `--tags` and `--match '*[0-9]*'` (and `--dirty` is unnecessary).
There is unfortunately no format-string equivalent to git-describe's
`--long` option,

Archives made from this repository after this change should now get
versioned correctly.

Fixes: pypa#759
Copy link
Contributor

@RonnyPfannschmidt RonnyPfannschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lovely thanks!

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

Successfully merging this pull request may close these issues.

The suggested contents of .git_archival.txt do not include the --match flag (like the default git describe)

2 participants