From a951a0f383afd3f1e19aa704136f1ad923d4aa75 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sun, 20 Oct 2024 01:35:40 -0400 Subject: [PATCH 1/3] chore: add a few nox checks Signed-off-by: Henry Schreiner --- nox/_parametrize.py | 12 +++++------ nox/command.py | 2 +- nox/sessions.py | 24 +++++++++------------- nox/virtualenv.py | 5 ++--- pyproject.toml | 46 ++++++++++++++++++++---------------------- tests/test_sessions.py | 3 +-- 6 files changed, 40 insertions(+), 52 deletions(-) diff --git a/nox/_parametrize.py b/nox/_parametrize.py index 24b87868..281607fc 100644 --- a/nox/_parametrize.py +++ b/nox/_parametrize.py @@ -60,18 +60,16 @@ def call_spec(self) -> dict[str, Any]: def __str__(self) -> str: if self.id: return self.id - else: - call_spec = self.call_spec - args = [f"{k}={call_spec[k]!r}" for k in call_spec] - return ", ".join(args) + call_spec = self.call_spec + args = [f"{k}={call_spec[k]!r}" for k in call_spec] + return ", ".join(args) __repr__ = __str__ def copy(self) -> Param: - new = self.__class__( + return self.__class__( *self.args, arg_names=self.arg_names, id=self.id, tags=self.tags ) - return new def update(self, other: Param) -> None: self.id = ", ".join([str(self), str(other)]) @@ -87,7 +85,7 @@ def __eq__(self, other: object) -> bool: and self.id == other.id and self.tags == other.tags ) - elif isinstance(other, dict): + if isinstance(other, dict): return dict(zip(self.arg_names, self.args)) == other return NotImplemented diff --git a/nox/command.py b/nox/command.py index 671875cb..ce8f0271 100644 --- a/nox/command.py +++ b/nox/command.py @@ -112,7 +112,7 @@ def run( " this." ) raise CommandFailed("External program disallowed.") - elif external is False: + if external is False: logger.warning( f"Warning: {cmd} is not installed into the virtualenv, it is" f" located at {cmd_path}. This might cause issues! Pass" diff --git a/nox/sessions.py b/nox/sessions.py index 5bf3eab6..05c0b6a1 100644 --- a/nox/sessions.py +++ b/nox/sessions.py @@ -109,14 +109,12 @@ def _dblquote_pkg_install_arg(pkg_req_str: str) -> str: if pkg_req_str[0] == pkg_req_str[-1] == '"': # already double-quoted string return pkg_req_str - else: - # need to double-quote string - if '"' in pkg_req_str: - raise ValueError(f"Cannot escape requirement string: {pkg_req_str}") - return f'"{pkg_req_str}"' - else: - # no dangerous char: no need to double-quote string - return pkg_req_str + # need to double-quote string + if '"' in pkg_req_str: + raise ValueError(f"Cannot escape requirement string: {pkg_req_str}") + return f'"{pkg_req_str}"' + # no dangerous char: no need to double-quote string + return pkg_req_str # double-quote all args that need to be and return the result return tuple(_dblquote_pkg_install_arg(a) for a in args) @@ -917,8 +915,7 @@ def __init__( def description(self) -> str | None: doc = self.func.__doc__ if doc: - first_line = doc.strip().split("\n")[0] - return first_line + return doc.strip().split("\n")[0] return None def __str__(self) -> str: @@ -1041,11 +1038,8 @@ def execute(self) -> Result: except nox.virtualenv.InterpreterNotFound as exc: if self.global_config.error_on_missing_interpreters: return Result(self, Status.FAILED, reason=str(exc)) - else: - logger.warning( - "Missing interpreters will error by default on CI systems." - ) - return Result(self, Status.SKIPPED, reason=str(exc)) + logger.warning("Missing interpreters will error by default on CI systems.") + return Result(self, Status.SKIPPED, reason=str(exc)) except _SessionQuit as exc: return Result(self, Status.ABORTED, reason=str(exc)) diff --git a/nox/virtualenv.py b/nox/virtualenv.py index 6e367d83..514b2f3e 100644 --- a/nox/virtualenv.py +++ b/nox/virtualenv.py @@ -83,9 +83,8 @@ def uv_version() -> version.Version: if ret.returncode == 0 and ret.stdout: return version.Version(json.loads(ret.stdout).get("version")) - else: - logger.info("Failed to establish uv's version.") - return version.Version("0.0") + logger.info("Failed to establish uv's version.") + return version.Version("0.0") def uv_install_python(python_version: str) -> bool: diff --git a/pyproject.toml b/pyproject.toml index ce852f8f..3781be77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,28 +65,28 @@ metadata.allow-ambiguous-features = true # disable normalization (tox-to-nox) fo [tool.ruff] lint.extend-select = [ - "B", # flake8-bugbear - "C4", # flake8-comprehensions - "EXE", # flake8-executable - "I", # isort - "ICN", # flake8-import-conventions - "ISC", # flake8-implicit-str-concat - "PGH", # pygrep-hooks - "PIE", # flake8-pie - "PL", # pylint - "RUF", # Ruff-specific - "SIM", # flake8-simplify - "UP", # pyupgrade - "YTT", # flake8-2020 + "B", # flake8-bugbear + "C4", # flake8-comprehensions + "EXE", # flake8-executable + "FURB", # refurb + "I", # isort + "ICN", # flake8-import-conventions + "ISC", # flake8-implicit-str-concat + "PGH", # pygrep-hooks + "PIE", # flake8-pie + "PL", # pylint + "RET", # flake8-return + "RUF", # Ruff-specific + "SIM", # flake8-simplify + "UP", # pyupgrade + "YTT", # flake8-2020 ] lint.ignore = [ "ISC001", # Conflicts with formatter "PLR09", # Too many X "PLR2004", # Magic value used in comparison ] - -[tool.isort] -profile = "black" +lint.typing-modules = [ "nox._typing" ] [tool.pyproject-fmt] max_supported_python = "3.13" @@ -99,14 +99,12 @@ filterwarnings = [ "error" ] log_cli_level = "info" testpaths = [ "tests" ] -[tool.coverage.run] -branch = true -omit = [ "nox/_typing.py" ] -relative_files = true -source_pkgs = [ "nox" ] - -[tool.coverage.report] -exclude_also = [ "def __dir__()", "if TYPE_CHECKING:", "@overload" ] +[tool.coverage] +run.branch = true +run.omit = [ "nox/_typing.py" ] +run.relative_files = true +run.source_pkgs = [ "nox" ] +report.exclude_also = [ "def __dir__()", "if TYPE_CHECKING:", "@overload" ] [tool.mypy] files = [ "nox/**/*.py", "noxfile.py" ] diff --git a/tests/test_sessions.py b/tests/test_sessions.py index 19827d64..23ef9f59 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -965,7 +965,7 @@ def make_runner(self): func.python = None func.venv_backend = None func.reuse_venv = False - runner = nox.sessions.SessionRunner( + return nox.sessions.SessionRunner( name="test", signatures=["test(1, 2)"], func=func, @@ -978,7 +978,6 @@ def make_runner(self): ), manifest=mock.create_autospec(nox.manifest.Manifest), ) - return runner def test_properties(self): runner = self.make_runner() From 4570f9dd2a5c66b2b4daa67b96115b97af390a96 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sun, 20 Oct 2024 01:39:21 -0400 Subject: [PATCH 2/3] chore: add a few things from preview ruff Signed-off-by: Henry Schreiner --- nox/__init__.py | 8 ++++---- nox/_option_set.py | 2 +- tests/test_virtualenv.py | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/nox/__init__.py b/nox/__init__.py index 2e47ad57..87d12fb4 100644 --- a/nox/__init__.py +++ b/nox/__init__.py @@ -24,11 +24,11 @@ needs_version: str | None = None __all__ = [ + "Session", "needs_version", - "parametrize", - "param", - "session", "options", - "Session", + "param", + "parametrize", "project", + "session", ] diff --git a/nox/_option_set.py b/nox/_option_set.py index ef989d7a..5e8a1a6c 100644 --- a/nox/_option_set.py +++ b/nox/_option_set.py @@ -38,7 +38,7 @@ class OptionGroup: kwargs: Passed through to``ArgumentParser.add_argument_group``. """ - __slots__ = ("name", "args", "kwargs") + __slots__ = ("args", "kwargs", "name") def __init__(self, name: str, *args: Any, **kwargs: Any) -> None: self.name = name diff --git a/tests/test_virtualenv.py b/tests/test_virtualenv.py index 962f3e93..94b7b58e 100644 --- a/tests/test_virtualenv.py +++ b/tests/test_virtualenv.py @@ -15,6 +15,7 @@ from __future__ import annotations import functools +import operator import os import re import shutil @@ -617,7 +618,7 @@ def find_uv_bin(): return find_uv_bin_result monkeypatch.setattr(shutil, "which", lambda _: which_result) - monkeypatch.setattr(Path, "samefile", lambda a, b: a == b) + monkeypatch.setattr(Path, "samefile", operator.eq) monkeypatch.setitem( sys.modules, "uv", types.SimpleNamespace(find_uv_bin=find_uv_bin) ) From a91dbe2356a42bf8d2f03021ccd3b19a903484c8 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sun, 20 Oct 2024 01:51:35 -0400 Subject: [PATCH 3/3] Apply suggestions from code review --- tests/test_virtualenv.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_virtualenv.py b/tests/test_virtualenv.py index 94b7b58e..962f3e93 100644 --- a/tests/test_virtualenv.py +++ b/tests/test_virtualenv.py @@ -15,7 +15,6 @@ from __future__ import annotations import functools -import operator import os import re import shutil @@ -618,7 +617,7 @@ def find_uv_bin(): return find_uv_bin_result monkeypatch.setattr(shutil, "which", lambda _: which_result) - monkeypatch.setattr(Path, "samefile", operator.eq) + monkeypatch.setattr(Path, "samefile", lambda a, b: a == b) monkeypatch.setitem( sys.modules, "uv", types.SimpleNamespace(find_uv_bin=find_uv_bin) )