From 964537307af0fec778674b9cfd0efcc2be0d41a0 Mon Sep 17 00:00:00 2001 From: Andreas Poehlmann Date: Thu, 2 May 2024 11:36:08 +0200 Subject: [PATCH 1/3] tests: add git get_head_date test for isoformat dates ending with Z --- testing/test_git.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/testing/test_git.py b/testing/test_git.py index 7918f47c..f10bea98 100644 --- a/testing/test_git.py +++ b/testing/test_git.py @@ -498,6 +498,21 @@ def test_git_getdate_badgit( assert git_wd.get_head_date() is None + +def test_git_getdate_git_2_45_0_plus( + wd: WorkDir, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch +) -> None: + wd.commit_testfile() + git_wd = git.GitWorkdir(wd.cwd) + fake_date_result = CompletedProcess(args=[], stdout="2024-04-30T22:33:10Z", stderr="", returncode=0) + with patch.object( + git, + "run_git", + Mock(return_value=fake_date_result), + ): + assert git_wd.get_head_date() == date(2024, 4, 30) + + @pytest.fixture() def signed_commit_wd(monkeypatch: pytest.MonkeyPatch, wd: WorkDir) -> WorkDir: if not has_command("gpg", args=["--version"], warn=False): From 49a89c9181f92c9e436b7b45a6388a536acac026 Mon Sep 17 00:00:00 2001 From: Andreas Poehlmann Date: Thu, 2 May 2024 11:37:16 +0200 Subject: [PATCH 2/3] setuptools_scm.git: fix handling of dates in isoformat ending with Z --- src/setuptools_scm/git.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/setuptools_scm/git.py b/src/setuptools_scm/git.py index 8f5c77e2..eb1d519a 100644 --- a/src/setuptools_scm/git.py +++ b/src/setuptools_scm/git.py @@ -5,6 +5,7 @@ import os import re import shlex +import sys import warnings from datetime import date @@ -119,6 +120,8 @@ def parse_timestamp(timestamp_text: str) -> date | None: if "%c" in timestamp_text: log.warning("git too old -> timestamp is %r", timestamp_text) return None + if sys.version_info < (3, 11) and timestamp_text.endswith("Z"): + timestamp_text = timestamp_text[:-1] + "+00:00" return datetime.fromisoformat(timestamp_text).date() res = run_git( From 3e613cd6c88fb9ea6f2e25a432a51a473c960941 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 2 May 2024 10:26:41 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- testing/test_git.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testing/test_git.py b/testing/test_git.py index f10bea98..15f4d097 100644 --- a/testing/test_git.py +++ b/testing/test_git.py @@ -498,13 +498,14 @@ def test_git_getdate_badgit( assert git_wd.get_head_date() is None - def test_git_getdate_git_2_45_0_plus( wd: WorkDir, caplog: pytest.LogCaptureFixture, monkeypatch: pytest.MonkeyPatch ) -> None: wd.commit_testfile() git_wd = git.GitWorkdir(wd.cwd) - fake_date_result = CompletedProcess(args=[], stdout="2024-04-30T22:33:10Z", stderr="", returncode=0) + fake_date_result = CompletedProcess( + args=[], stdout="2024-04-30T22:33:10Z", stderr="", returncode=0 + ) with patch.object( git, "run_git",