From d4db7de3db3e711b840a354a0beb9399509ccd5d Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 23 Feb 2024 17:18:23 -0500 Subject: [PATCH 1/2] chore: cleanup Ruff a bit Signed-off-by: Henry Schreiner --- docs/conf.py | 2 +- nox/_option_set.py | 2 +- nox/_options.py | 6 ++---- nox/_parametrize.py | 6 +++--- nox/_version.py | 2 +- nox/logger.py | 13 ++++++------- nox/sessions.py | 4 ++-- pyproject.toml | 9 +++++---- tests/test_main.py | 2 +- 9 files changed, 22 insertions(+), 24 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 7982f61b..e3e34506 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -17,7 +17,7 @@ import sys try: - import importlib.metadata as metadata + from importlib import metadata except ImportError: import importlib_metadata as metadata diff --git a/nox/_option_set.py b/nox/_option_set.py index e85c5746..0ade4ed0 100644 --- a/nox/_option_set.py +++ b/nox/_option_set.py @@ -21,7 +21,7 @@ import argparse import collections import functools -from argparse import ArgumentError as ArgumentError +from argparse import ArgumentError as ArgumentError # noqa: PLC0414 from argparse import ArgumentParser, Namespace from collections.abc import Callable, Iterable from typing import Any diff --git a/nox/_options.py b/nox/_options.py index 7c4b89e8..f6dd828d 100644 --- a/nox/_options.py +++ b/nox/_options.py @@ -128,10 +128,8 @@ def _force_venv_backend_merge_func( raise ValueError( "You can not use `--no-venv` with a non-none `--force-venv-backend`" ) - else: - return "none" - else: - return command_args.force_venv_backend or noxfile_args.force_venv_backend # type: ignore[no-any-return] + return "none" + return command_args.force_venv_backend or noxfile_args.force_venv_backend # type: ignore[no-any-return] def _envdir_merge_func( diff --git a/nox/_parametrize.py b/nox/_parametrize.py index ad83b53a..865cb19b 100644 --- a/nox/_parametrize.py +++ b/nox/_parametrize.py @@ -168,7 +168,7 @@ def update_param_specs( combined_specs = [] for new_spec in new_specs: for spec in param_specs: - spec = spec.copy() - spec.update(new_spec) - combined_specs.append(spec) + spec_copy = spec.copy() + spec_copy.update(new_spec) + combined_specs.append(spec_copy) return combined_specs diff --git a/nox/_version.py b/nox/_version.py index 261a298e..e8c3b0eb 100644 --- a/nox/_version.py +++ b/nox/_version.py @@ -22,7 +22,7 @@ from packaging.version import InvalidVersion, Version if sys.version_info >= (3, 8): - import importlib.metadata as metadata + from importlib import metadata else: import importlib_metadata as metadata diff --git a/nox/logger.py b/nox/logger.py index f98d8033..333d8bdb 100644 --- a/nox/logger.py +++ b/nox/logger.py @@ -27,13 +27,12 @@ def _get_format(colorlog: bool, add_timestamp: bool) -> str: if colorlog: if add_timestamp: return "%(cyan)s%(name)s > [%(asctime)s] %(log_color)s%(message)s" - else: - return "%(cyan)s%(name)s > %(log_color)s%(message)s" - else: - if add_timestamp: - return "%(name)s > [%(asctime)s] %(message)s" - else: - return "%(name)s > %(message)s" + return "%(cyan)s%(name)s > %(log_color)s%(message)s" + + if add_timestamp: + return "%(name)s > [%(asctime)s] %(message)s" + + return "%(name)s > %(message)s" class NoxFormatter(logging.Formatter): diff --git a/nox/sessions.py b/nox/sessions.py index f29e6bfc..f3c2540f 100644 --- a/nox/sessions.py +++ b/nox/sessions.py @@ -562,7 +562,7 @@ def conda_install( raise ValueError("At least one argument required to install().") if self._runner.global_config.no_install and venv._reused: - return None + return # Escape args that should be (conda-specific; pip install does not need this) args = _dblquote_pkg_install_args(args) @@ -645,7 +645,7 @@ def install(self, *args: str, **kwargs: Any) -> None: raise ValueError("At least one argument required to install().") if self._runner.global_config.no_install and venv._reused: - return None + return if "silent" not in kwargs: kwargs["silent"] = True diff --git a/pyproject.toml b/pyproject.toml index f3dc7264..389e3206 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -74,20 +74,21 @@ extend-select = [ "C4", # flake8-comprehensions "ICN", # flake8-import-conventions "ISC", # flake8-implicit-str-concat + "PL", # pylint "PGH", # pygrep-hooks "PIE", # flake8-pie "RUF", # Ruff-specific "SIM", # flake8-simplify "UP", # pyupgrade "YTT", # flake8-2020 + "EXE", # flake8-executable ] ignore = [ - "ISC001", # Conflicts with formatter + "ISC001", # Conflicts with formatter + "PLR09", # Too many X + "PLR2004", # Magic value used in comparison ] -[tool.ruff] -target-version = "py37" - [tool.isort] profile = "black" diff --git a/tests/test_main.py b/tests/test_main.py index e33277b3..6361f389 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -29,7 +29,7 @@ import nox.sessions try: - import importlib.metadata as metadata + from importlib import metadata except ImportError: import importlib_metadata as metadata From dad766ac18b06dc5ddd29a0a1703ede5813e0afc Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 23 Feb 2024 17:26:28 -0500 Subject: [PATCH 2/2] chore: use static import version check Signed-off-by: Henry Schreiner --- docs/conf.py | 4 ++-- tests/test_main.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index e3e34506..ff265aa5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -16,9 +16,9 @@ import os import sys -try: +if sys.version_info >= (3, 8): from importlib import metadata -except ImportError: +else: import importlib_metadata as metadata # If extensions (or modules to document with autodoc) are in another directory, diff --git a/tests/test_main.py b/tests/test_main.py index 6361f389..158702f3 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -28,9 +28,9 @@ import nox.registry import nox.sessions -try: +if sys.version_info >= (3, 8): from importlib import metadata -except ImportError: +else: import importlib_metadata as metadata