From 90ea3d0acd1f41a95580699d6e1c4b58be979a89 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:07:28 +0100 Subject: [PATCH 1/8] pre-commit autoupdate (ruff) * The linter should not fix by default. The --fix option is passed by pre-commit. --- .pre-commit-config.yaml | 3 ++- pyproject.toml | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d28a324c..a9397bcf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,8 +5,9 @@ repos: - id: trailing-whitespace - id: check-yaml - id: debug-statements + - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.3.4 + rev: v0.9.1 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix, --show-fixes] diff --git a/pyproject.toml b/pyproject.toml index ba539651..acb04a3b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -118,7 +118,6 @@ version = { attr = "_own_version_helper.version"} [tool.ruff] src = ["src"] -fix = true lint.select = ["E", "F", "B", "UP", "YTT", "C", "DTZ", "PYI", "PT", "I", "FURB", "RUF"] lint.ignore = ["B028"] lint.preview = true From b46b99e67a24320c93703290d13454fdaeb285e6 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:11:24 +0100 Subject: [PATCH 2/8] Apply ruff/flake8-pyi rule PYI006 PYI006 Use `<` or `>=` for `sys.version_info` comparisons --- testing/test_integration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/test_integration.py b/testing/test_integration.py index 86c8cbee..957bf4c5 100644 --- a/testing/test_integration.py +++ b/testing/test_integration.py @@ -34,7 +34,7 @@ def wd(wd: WorkDir) -> WorkDir: def test_pyproject_support(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: - if sys.version_info <= (3, 10): + if sys.version_info < (3, 11): pytest.importorskip("tomli") monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG") pkg = tmp_path / "package" @@ -97,7 +97,7 @@ def test_pyproject_support(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> N @with_metadata_in def test_pyproject_support_with_git(wd: WorkDir, metadata_in: str) -> None: - if sys.version_info <= (3, 10): + if sys.version_info < (3, 11): pytest.importorskip("tomli") wd.write("pyproject.toml", PYPROJECT_FILES[metadata_in]) wd.write("setup.py", SETUP_PY_FILES[metadata_in]) From 31060f8c4c22907ed088217c5d340fb11ff552b4 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:13:49 +0100 Subject: [PATCH 3/8] Apply ruff rule RUF036 RUF036 `None` not at the end of the type annotation. --- src/setuptools_scm/git.py | 2 +- src/setuptools_scm/integration.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/setuptools_scm/git.py b/src/setuptools_scm/git.py index 7eccf198..b7c712ef 100644 --- a/src/setuptools_scm/git.py +++ b/src/setuptools_scm/git.py @@ -250,7 +250,7 @@ def parse_describe(output: str) -> ScmVersion: def _git_parse_inner( config: Configuration, wd: GitWorkdir | hg_git.GitWorkdirHgClient, - pre_parse: None | (Callable[[GitWorkdir | hg_git.GitWorkdirHgClient], None]) = None, + pre_parse: (Callable[[GitWorkdir | hg_git.GitWorkdirHgClient], None]) | None = None, describe_command: _t.CMD_TYPE | None = None, ) -> ScmVersion: if pre_parse: diff --git a/src/setuptools_scm/integration.py b/src/setuptools_scm/integration.py index 48874e38..b15d74a6 100644 --- a/src/setuptools_scm/integration.py +++ b/src/setuptools_scm/integration.py @@ -10,7 +10,7 @@ log = logging.getLogger(__name__) -def data_from_mime(path: _t.PathT, content: None | str = None) -> dict[str, str]: +def data_from_mime(path: _t.PathT, content: str | None = None) -> dict[str, str]: """return a mapping from mime/pseudo-mime content :param path: path to the mime file :param content: content of the mime file, if None, read from path From ecd74912cb76a1a893365d7e1687cb6c1b6e6c65 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:15:34 +0100 Subject: [PATCH 4/8] Apply ruff rule RUF043 RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw --- testing/test_functions.py | 2 +- testing/test_regressions.py | 2 +- testing/test_version.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/testing/test_functions.py b/testing/test_functions.py index 5f394b0b..d6c4e711 100644 --- a/testing/test_functions.py +++ b/testing/test_functions.py @@ -81,7 +81,7 @@ def test_dump_version_doesnt_bail_on_value_error(tmp_path: Path) -> None: write_to = "VERSION" version = str(VERSIONS["exact"].tag) scm_version = meta(VERSIONS["exact"].tag, config=c) - with pytest.raises(ValueError, match="^bad file format:"): + with pytest.raises(ValueError, match=r"^bad file format:"): dump_version(tmp_path, version, write_to, scm_version=scm_version) diff --git a/testing/test_regressions.py b/testing/test_regressions.py index d523f60c..385549c2 100644 --- a/testing/test_regressions.py +++ b/testing/test_regressions.py @@ -127,6 +127,6 @@ def test_write_to_absolute_path_passes_when_subdir_of_root(tmp_path: Path) -> No with pytest.raises( # todo: python version specific error list ValueError, - match=".*VERSION.py' .* .*subdir.*", + match=r".*VERSION.py' .* .*subdir.*", ): write_version_files(replace(c, root=subdir), "1.0", v) diff --git a/testing/test_version.py b/testing/test_version.py index 5233ef57..edbb9dae 100644 --- a/testing/test_version.py +++ b/testing/test_version.py @@ -235,7 +235,7 @@ def __str__(self) -> str: config = Configuration(version_cls=YikesVersion) # type: ignore[arg-type] with pytest.raises( ValueError, - match=".*does not end with a number to bump, " + match=r".*does not end with a number to bump, " "please correct or use a custom version scheme", ): guess_next_version(tag_version=meta("2.0.0-alpha.5-PMC", config=config)) From 2e6bbd25a20b9bdc9a194d7c0fd5f6abeaf9a85e Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:16:09 +0100 Subject: [PATCH 5/8] Apply ruff rule RUF052 RUF052 Local dummy variable is accessed --- src/setuptools_scm/git.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/setuptools_scm/git.py b/src/setuptools_scm/git.py index b7c712ef..246df477 100644 --- a/src/setuptools_scm/git.py +++ b/src/setuptools_scm/git.py @@ -145,12 +145,12 @@ def fetch_shallow(self) -> None: run_git(["fetch", "--unshallow"], self.path, check=True, timeout=240) def node(self) -> str | None: - _unsafe_short_node = operator.itemgetter(slice(7)) + unsafe_short_node = operator.itemgetter(slice(7)) return run_git( ["rev-parse", "--verify", "--quiet", "HEAD"], self.path ).parse_success( - parse=_unsafe_short_node, + parse=unsafe_short_node, ) def count_all_nodes(self) -> int: From e8c488f40a099b7be0c190dc9c44d4a0abe9cd78 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 15 Jan 2025 18:05:11 +0100 Subject: [PATCH 6/8] Run `ruff format` --- src/setuptools_scm/_integration/setuptools.py | 6 +++--- src/setuptools_scm/version.py | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/setuptools_scm/_integration/setuptools.py b/src/setuptools_scm/_integration/setuptools.py index 3ed48470..55ca1660 100644 --- a/src/setuptools_scm/_integration/setuptools.py +++ b/src/setuptools_scm/_integration/setuptools.py @@ -82,9 +82,9 @@ def version_keyword( assert isinstance(value, dict), "version_keyword expects a dict or True" overrides = value - assert ( - "dist_name" not in overrides - ), "dist_name may not be specified in the setup keyword " + assert "dist_name" not in overrides, ( + "dist_name may not be specified in the setup keyword " + ) dist_name: str | None = dist.metadata.name _log_hookstart("version_keyword", dist) diff --git a/src/setuptools_scm/version.py b/src/setuptools_scm/version.py index 43d23e54..ef36be4f 100644 --- a/src/setuptools_scm/version.py +++ b/src/setuptools_scm/version.py @@ -381,8 +381,7 @@ def guess_next_date_ver( if tag_date > head_date and match is not None: # warn on future times warnings.warn( - f"your previous tag ({tag_date})" - f" is ahead your node date ({head_date})" + f"your previous tag ({tag_date}) is ahead your node date ({head_date})" ) patch = 0 next_version = "{node_date:{date_fmt}}.{patch}".format( From febd01cf77332f6c0e08334150534ed10c59f210 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 15 Jan 2025 22:00:01 +0100 Subject: [PATCH 7/8] Apply ruff/flake8-pytest-style rule PT001 PT001 Use `@pytest.fixture` over `@pytest.fixture()` --- testing/conftest.py | 4 ++-- testing/test_git.py | 4 ++-- testing/test_integration.py | 2 +- testing/test_main.py | 2 +- testing/test_mercurial.py | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/testing/conftest.py b/testing/conftest.py index d1c96ed3..09b69c1a 100644 --- a/testing/conftest.py +++ b/testing/conftest.py @@ -79,14 +79,14 @@ def debug_mode() -> Iterator[DebugMode]: yield debug_mode -@pytest.fixture() +@pytest.fixture def wd(tmp_path: Path) -> WorkDir: target_wd = tmp_path.resolve() / "wd" target_wd.mkdir() return WorkDir(target_wd) -@pytest.fixture() +@pytest.fixture def repositories_hg_git(tmp_path: Path) -> tuple[WorkDir, WorkDir]: tmp_path = tmp_path.resolve() path_git = tmp_path / "repo_git" diff --git a/testing/test_git.py b/testing/test_git.py index 661dcb76..9186b1a6 100644 --- a/testing/test_git.py +++ b/testing/test_git.py @@ -307,7 +307,7 @@ def test_git_worktree_support(wd: WorkDir, tmp_path: Path) -> None: assert str(worktree) in res.stdout -@pytest.fixture() +@pytest.fixture def shallow_wd(wd: WorkDir, tmp_path: Path) -> Path: wd.commit_testfile() wd.commit_testfile() @@ -515,7 +515,7 @@ def test_git_getdate_git_2_45_0_plus( assert git_wd.get_head_date() == date(2024, 4, 30) -@pytest.fixture() +@pytest.fixture def signed_commit_wd(monkeypatch: pytest.MonkeyPatch, wd: WorkDir) -> WorkDir: if not has_command("gpg", args=["--version"], warn=False): pytest.skip("gpg executable not found") diff --git a/testing/test_integration.py b/testing/test_integration.py index 957bf4c5..ba1cdb67 100644 --- a/testing/test_integration.py +++ b/testing/test_integration.py @@ -23,7 +23,7 @@ c = Configuration() -@pytest.fixture() +@pytest.fixture def wd(wd: WorkDir) -> WorkDir: wd("git init") wd("git config user.email test@example.com") diff --git a/testing/test_main.py b/testing/test_main.py index ad9a2903..3c0ff3f8 100644 --- a/testing/test_main.py +++ b/testing/test_main.py @@ -20,7 +20,7 @@ def test_main() -> None: exec(code, ns) -@pytest.fixture() +@pytest.fixture def repo(wd: WorkDir) -> WorkDir: wd("git init") wd("git config user.email user@host") diff --git a/testing/test_mercurial.py b/testing/test_mercurial.py index b51c3fd9..57073716 100644 --- a/testing/test_mercurial.py +++ b/testing/test_mercurial.py @@ -21,7 +21,7 @@ ) -@pytest.fixture() +@pytest.fixture def wd(wd: WorkDir) -> WorkDir: wd("hg init") wd.add_command = "hg add ." @@ -153,7 +153,7 @@ def test_parse_no_worktree(tmp_path: Path) -> None: assert ret is None -@pytest.fixture() +@pytest.fixture def version_1_0(wd: WorkDir) -> WorkDir: wd("hg branch default") wd.commit_testfile() @@ -161,7 +161,7 @@ def version_1_0(wd: WorkDir) -> WorkDir: return wd -@pytest.fixture() +@pytest.fixture def pre_merge_commit_after_tag(version_1_0: WorkDir) -> WorkDir: wd = version_1_0 wd("hg branch testbranch") From 2d43b14457176a2ad2241a1e5eaf1a764bea52bf Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Wed, 15 Jan 2025 22:01:30 +0100 Subject: [PATCH 8/8] Apply ruff/flake8-pytest-style rule PT023 PT023 Use `@pytest.mark.skip_commit` over `@pytest.mark.skip_commit()` --- testing/test_file_finder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_file_finder.py b/testing/test_file_finder.py index 5af94fcf..cc1a08fd 100644 --- a/testing/test_file_finder.py +++ b/testing/test_file_finder.py @@ -212,7 +212,7 @@ def test_symlink_not_in_scm_while_target_is(inwd: WorkDir) -> None: @pytest.mark.issue(587) -@pytest.mark.skip_commit() +@pytest.mark.skip_commit def test_not_commited(inwd: WorkDir) -> None: assert find_files() == []