diff --git a/src/setuptools_scm/_run_cmd.py b/src/setuptools_scm/_run_cmd.py index f2a82852..b0617abb 100644 --- a/src/setuptools_scm/_run_cmd.py +++ b/src/setuptools_scm/_run_cmd.py @@ -201,7 +201,7 @@ def has_command( else: res = not p.returncode if not res and warn: - warnings.warn("%r was not found" % name, category=RuntimeWarning) + warnings.warn(f"{name!r} was not found", category=RuntimeWarning) return res diff --git a/src/setuptools_scm/git.py b/src/setuptools_scm/git.py index eb1d519a..7eccf198 100644 --- a/src/setuptools_scm/git.py +++ b/src/setuptools_scm/git.py @@ -2,6 +2,7 @@ import dataclasses import logging +import operator import os import re import shlex @@ -144,8 +145,7 @@ def fetch_shallow(self) -> None: run_git(["fetch", "--unshallow"], self.path, check=True, timeout=240) def node(self) -> str | None: - def _unsafe_short_node(node: str) -> str: - return node[:7] + _unsafe_short_node = operator.itemgetter(slice(7)) return run_git( ["rev-parse", "--verify", "--quiet", "HEAD"], self.path diff --git a/src/setuptools_scm/version.py b/src/setuptools_scm/version.py index 0a367423..43d23e54 100644 --- a/src/setuptools_scm/version.py +++ b/src/setuptools_scm/version.py @@ -216,7 +216,7 @@ def meta( ) -> ScmVersion: parsed_version = _parse_tag(tag, preformatted, config) log.info("version %s -> %s", tag, parsed_version) - assert parsed_version is not None, "Can't parse version %s" % tag + assert parsed_version is not None, f"Can't parse version {tag}" return ScmVersion( parsed_version, distance=distance, diff --git a/testing/test_git.py b/testing/test_git.py index 15f4d097..1ba19ad0 100644 --- a/testing/test_git.py +++ b/testing/test_git.py @@ -299,7 +299,7 @@ def test_git_dirty_notag( def test_git_worktree_support(wd: WorkDir, tmp_path: Path) -> None: wd.commit_testfile() worktree = tmp_path / "work_tree" - wd("git worktree add -b work-tree %s" % worktree) + wd(f"git worktree add -b work-tree {worktree}") res = run([sys.executable, "-m", "setuptools_scm", "ls"], cwd=worktree) assert "test.txt" in res.stdout diff --git a/testing/test_version.py b/testing/test_version.py index 371c7546..10a8f9a8 100644 --- a/testing/test_version.py +++ b/testing/test_version.py @@ -432,10 +432,10 @@ def __init__(self, tag_str: str) -> None: self.tag = tag_str def __str__(self) -> str: - return "Custom %s" % self.tag + return f"Custom {self.tag}" def __repr__(self) -> str: - return "MyVersion" % self.tag + return f"MyVersion" config = Configuration(version_cls=MyVersion) # type: ignore[arg-type] scm_version = meta("1.0.0-foo", config=config)