diff --git a/pyproject.toml b/pyproject.toml index 5a9f181..e5b9021 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -107,19 +107,7 @@ ignore = [ "INP001", # "is part of an implicit namespace package", all false positives "ISC001", # conflicts with COM812 on format "PLW2901", # PLW2901: Redefined loop variable - "RET504", # Unnecessary variable assignment before `return` statement - # temporary disabled until we fix them: - "ANN", - "ARG001", - "PTH109", - "PTH112", - "PTH113", - "PTH123", - "S603", - "S605", - "S607", - "SIM117", - "UP022" + "RET504" # Unnecessary variable assignment before `return` statement ] select = ["ALL"] diff --git a/src/tox_extra/bindep.py b/src/tox_extra/bindep.py index 5b455eb..3c9ee34 100644 --- a/src/tox_extra/bindep.py +++ b/src/tox_extra/bindep.py @@ -3,7 +3,6 @@ from __future__ import annotations import logging -import os import subprocess import sys from functools import cache @@ -21,17 +20,16 @@ def check_bindep(path: Path, profiles: Iterable[str] | None = None) -> None: """Check bindeps requirements or exit.""" if profiles is None: # pragma: no cover profiles = [] - if os.path.isfile(path / "bindep.txt"): + if (path / "bindep.txt").is_file(): # as 'bindep --profiles' does not show user defined profiles like 'test' # it makes no sense to list them. cmd = [sys.executable, "-m", "bindep", "-b", *sorted(profiles)] - result = subprocess.run( + result = subprocess.run( # noqa: S603 cmd, check=False, text=True, - stderr=subprocess.PIPE, - stdout=subprocess.PIPE, + capture_output=True, cwd=path, ) if result.returncode: diff --git a/src/tox_extra/hooks.py b/src/tox_extra/hooks.py index 3ffec6a..d37feba 100644 --- a/src/tox_extra/hooks.py +++ b/src/tox_extra/hooks.py @@ -4,6 +4,7 @@ import os import pathlib +import shutil import sys from typing import TYPE_CHECKING, Any @@ -30,17 +31,18 @@ def is_git_dirty(path: str) -> bool: """Reports if the git repository at the given path is dirty.""" - if os.path.isdir(f"{path}/.git"): + git_path = shutil.which("git") + if pathlib.Path(f"{path}/.git").is_dir(): _environ = dict(os.environ) try: - repo = git.Repo(os.getcwd()) + repo = git.Repo(pathlib.Path.cwd()) if repo.is_dirty(untracked_files=True): - os.system("git status -s") + os.system(f"{git_path} status -s") # noqa: S605 # We want to display long diff only on non-interactive shells, # like CI/CD pipelines because on local shell, the user can # decide to run it himself if the status line was not enogh. if not os.isatty(sys.stdout.fileno()): - os.system("git --no-pager diff -U0 --minimal") + os.system(f"{git_path} --no-pager diff -U0 --minimal") # noqa: S605 return True finally: os.environ.clear() @@ -63,9 +65,9 @@ def tox_add_option(parser: ArgumentParser) -> None: # pylint: disable=unused-argument def tox_on_install( tox_env: ToxEnv, - arguments: Any, - section: str, - of_type: str, + arguments: Any, # noqa: ARG001,ANN401 + section: str, # noqa: ARG001 + of_type: str, # noqa: ARG001 ) -> None: """Runs just before installing package.""" if os.environ.get("TOX_EXTRA_BINDEP", "1") != "0": @@ -87,8 +89,8 @@ def tox_on_install( # pylint: disable=unused-argument def tox_after_run_commands( tox_env: ToxEnv, - exit_code: int, - outcomes: list[Outcome], + exit_code: int, # noqa: ARG001 + outcomes: list[Outcome], # noqa: ARG001 ) -> None: """Hook that runs after test commands.""" allow_dirty = getattr(tox_env.options, "allow_dirty", False) diff --git a/tests/__init__.py b/tests/__init__.py index e7241b5..d619454 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,14 +2,16 @@ import functools import os +from pathlib import Path +from typing import Any, Callable -def preserve_cwd(function): +def preserve_cwd(function: Callable) -> Callable: """Decorator for restoring cwd.""" @functools.wraps(function) - def decorator(*args, **kwargs): - cwd = os.getcwd() + def decorator(*args: Any, **kwargs: Any): # noqa: ANN202, ANN401 + cwd = Path.cwd() try: return function(*args, **kwargs) finally: diff --git a/tests/test_bindep.py b/tests/test_bindep.py index 897b86d..f919c56 100644 --- a/tests/test_bindep.py +++ b/tests/test_bindep.py @@ -21,8 +21,7 @@ def test_bindep(folder: str, expected_rc: int) -> None: """Tests that running tox with a bindep file that is missing deps fails.""" os.chdir(folder) - with patch("sys.argv", ["tox"]): - with pytest.raises(SystemExit) as exc: - run_module("tox", run_name="__main__") + with patch("sys.argv", ["tox"]), pytest.raises(SystemExit) as exc: + run_module("tox", run_name="__main__") assert exc.type is SystemExit assert exc.value.code == expected_rc diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 6b03f51..f749653 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -16,7 +16,7 @@ @preserve_cwd -def test_fail_if_dirty(tmp_path, monkeypatch: pytest.MonkeyPatch) -> None: +def test_fail_if_dirty(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: """Validated that it fails when drity.""" # We need to mock sys.argv because run_module will look at it and fail # as the argv received of pytest would leak into our tox module call. @@ -26,7 +26,7 @@ def test_fail_if_dirty(tmp_path, monkeypatch: pytest.MonkeyPatch) -> None: os.chdir(path) # add tox.ini and .gitignore files (untracked) - with open(Path(tmp_path) / "tox.ini", "w", encoding="utf-8") as file: + with (Path(tmp_path) / "tox.ini").open("w", encoding="utf-8") as file: file.write(TOX_SAMPLE) # check running tox w/o git repo is passing @@ -47,7 +47,7 @@ def test_fail_if_dirty(tmp_path, monkeypatch: pytest.MonkeyPatch) -> None: output = check_output("git status --porcelain", shell=True, universal_newlines=True) assert output == "" - with open(Path(tmp_path) / ".gitignore", "w", encoding="utf-8") as file: + with (Path(tmp_path) / ".gitignore").open("w", encoding="utf-8") as file: file.write(".tox\n") result = run(