From 4c2cf6e3a369afa05131d6fb3d790822b019abf0 Mon Sep 17 00:00:00 2001 From: Darsey Litzenberger Date: Thu, 13 Oct 2022 21:28:52 -0600 Subject: Fix parsing .git_archival.txt for archives made from tagged commits. 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. --- src/setuptools_scm/git.py | 15 ++++++++++++--- testing/test_git.py | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/setuptools_scm/git.py b/src/setuptools_scm/git.py index 27cb159..f2afda9 100644 --- a/src/setuptools_scm/git.py +++ b/src/setuptools_scm/git.py @@ -232,9 +232,11 @@ def _git_parse_inner( ) -def _git_parse_describe(describe_output: str) -> tuple[str, int, str, bool]: +def _git_parse_describe(describe_output: str) -> tuple[str, int | None, str | None, bool]: # 'describe_output' looks e.g. like 'v1.5.0-0-g4060507' or # 'v1.15.1rc1-37-g9bd1298-dirty'. + # It may also just be a bare tag name if this is a tagged commit and we are + # parsing a .git_archival.txt file. if describe_output.endswith("-dirty"): dirty = True @@ -242,8 +244,15 @@ def _git_parse_describe(describe_output: str) -> tuple[str, int, str, bool]: else: dirty = False - tag, number, node = describe_output.rsplit("-", 2) - return tag, int(number), node, dirty + split = describe_output.rsplit("-", 2) + if len(split) < 3: # probably a tagged commit + tag = describe_output + number = None + node = None + else: + tag, number_, node = split + number = int(number_) + return tag, number, node, dirty def search_parent(dirname: _t.PathT) -> GitWorkdir | None: diff --git a/testing/test_git.py b/testing/test_git.py index 321d658..412ce75 100644 --- a/testing/test_git.py +++ b/testing/test_git.py @@ -523,6 +523,7 @@ def test_git_getdate_signed_commit(signed_commit_wd: WorkDir) -> None: ("0.0", {"node": "0" * 20}), ("1.2.2", {"describe-name": "release-1.2.2-0-g00000"}), ("1.2.2.dev0", {"ref-names": "tag: release-1.2.2.dev"}), + ("1.2.2", {"describe-name": "v1.2.2"}), ], ) @pytest.mark.filterwarnings("ignore:git archive did not support describe output") -- cgit v1.2.1 From 501d80c8d7194379d08a63375645d9c166707ff4 Mon Sep 17 00:00:00 2001 From: Darsey Litzenberger Date: Thu, 13 Oct 2022 21:46:23 -0600 Subject: Fix #759: Update .git_archival.txt templates to more closely match 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: https://github.com/pypa/setuptools_scm/issues/759 --- .git_archival.txt | 2 +- README.rst | 2 +- src/setuptools_scm/.git_archival.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.git_archival.txt b/.git_archival.txt index 37d637d..8fb235d 100644 --- a/.git_archival.txt +++ b/.git_archival.txt @@ -1,4 +1,4 @@ node: $Format:%H$ node-date: $Format:%cI$ -describe-name: $Format:%(describe)$ +describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ ref-names: $Format:%D$ diff --git a/README.rst b/README.rst index a02caf7..18f763c 100644 --- a/README.rst +++ b/README.rst @@ -316,7 +316,7 @@ and copy-paste this into it:: node: $Format:%H$ node-date: $Format:%cI$ - describe-name: $Format:%(describe:tags=true)$ + describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ ref-names: $Format:%D$ Create the ``.gitattributes`` file in the root directory of your repository diff --git a/src/setuptools_scm/.git_archival.txt b/src/setuptools_scm/.git_archival.txt index 37d637d..8fb235d 100644 --- a/src/setuptools_scm/.git_archival.txt +++ b/src/setuptools_scm/.git_archival.txt @@ -1,4 +1,4 @@ node: $Format:%H$ node-date: $Format:%cI$ -describe-name: $Format:%(describe)$ +describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$ ref-names: $Format:%D$ -- cgit v1.2.1 From 0e4def7cb63a869667d8278d8231e5f8514cd160 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 14 Oct 2022 09:47:13 +0000 Subject: [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/setuptools_scm/git.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/setuptools_scm/git.py b/src/setuptools_scm/git.py index f2afda9..16ca378 100644 --- a/src/setuptools_scm/git.py +++ b/src/setuptools_scm/git.py @@ -232,7 +232,9 @@ def _git_parse_inner( ) -def _git_parse_describe(describe_output: str) -> tuple[str, int | None, str | None, bool]: +def _git_parse_describe( + describe_output: str, +) -> tuple[str, int | None, str | None, bool]: # 'describe_output' looks e.g. like 'v1.5.0-0-g4060507' or # 'v1.15.1rc1-37-g9bd1298-dirty'. # It may also just be a bare tag name if this is a tagged commit and we are -- cgit v1.2.1 From a0e39fa5f115a713608f3a1aa5565cf991d29a9b Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Thu, 3 Nov 2022 11:34:10 +0100 Subject: pre-commit hooks upgrade --- .pre-commit-config.yaml | 13 +++++++------ setup.cfg | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index af10aef..9fe41b2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,12 +2,12 @@ default_language_version: python: python3.9 repos: - repo: https://github.com/psf/black - rev: 22.6.0 + rev: 22.10.0 hooks: - id: black args: [--safe, --quiet] - repo: https://github.com/asottile/reorder_python_imports - rev: v3.3.0 + rev: v3.9.0 hooks: - id: reorder-python-imports args: [ "--application-directories=.:src" , --py37-plus, --add-import, 'from __future__ import annotations'] @@ -19,20 +19,21 @@ repos: - id: check-yaml - id: debug-statements - repo: https://github.com/PyCQA/flake8 - rev: 4.0.1 + rev: 5.0.4 hooks: - id: flake8 - repo: https://github.com/asottile/pyupgrade - rev: v2.34.0 + rev: v3.2.0 hooks: - id: pyupgrade args: [--py37-plus] - repo: https://github.com/asottile/setup-cfg-fmt - rev: v1.20.1 + rev: v2.2.0 hooks: - id: setup-cfg-fmt + args: [ --include-version-classifiers ] - repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v0.961' + rev: 'v0.982' hooks: - id: mypy args: [--strict] diff --git a/setup.cfg b/setup.cfg index 06c51ea..795bb21 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,6 +19,7 @@ classifiers = Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 Topic :: Software Development :: Libraries Topic :: Software Development :: Version Control Topic :: System :: Software Distribution -- cgit v1.2.1