diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fe32143b5..5b1b23e2d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.28.1 + rev: 0.28.2 hooks: - id: check-github-workflows args: [ "--verbose" ] @@ -20,12 +20,12 @@ repos: - id: tox-ini-fmt args: ["-p", "fix"] - repo: https://github.com/tox-dev/pyproject-fmt - rev: "1.7.0" + rev: "1.8.0" hooks: - id: pyproject-fmt - additional_dependencies: ["tox>=4.12.1"] + additional_dependencies: ["tox>=4.14.2"] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.3.5" + rev: "v0.4.1" hooks: - id: ruff-format - id: ruff @@ -34,7 +34,7 @@ repos: rev: 1.16.0 hooks: - id: blacken-docs - additional_dependencies: [black==23.12.1] + additional_dependencies: [black==24.4] - repo: https://github.com/pre-commit/pygrep-hooks rev: v1.10.0 hooks: diff --git a/src/tox/config/loader/convert.py b/src/tox/config/loader/convert.py index ece9864a7..f7cf4e380 100644 --- a/src/tox/config/loader/convert.py +++ b/src/tox/config/loader/convert.py @@ -64,13 +64,13 @@ def _to_typing(self, raw: T, of_type: type[V], factory: Factory[V]) -> V: # noq elif origin == Union: # handle Optional values args: list[type[Any]] = of_type.__args__ # type: ignore[attr-defined] none = type(None) - if len(args) == 2 and none in args: # type: ignore[comparison-overlap] # noqa: PLR2004 + if len(args) == 2 and none in args: # noqa: PLR2004 if isinstance(raw, str): raw = raw.strip() # type: ignore[assignment] if not raw: result = None else: - new_type = next(i for i in args if i != none) # type: ignore[comparison-overlap] # pragma: no cover + new_type = next(i for i in args if i != none) # pragma: no cover result = self.to(raw, new_type, factory) elif origin in {Literal, type(Literal)}: choice = of_type.__args__ # type: ignore[attr-defined] diff --git a/src/tox/session/cmd/show_config.py b/src/tox/session/cmd/show_config.py index 7408c2d1a..7bc79c210 100644 --- a/src/tox/session/cmd/show_config.py +++ b/src/tox/session/cmd/show_config.py @@ -95,7 +95,7 @@ def print_key_value(is_colored: bool, key: str, value: str, multi_line: bool = F def print_conf(is_colored: bool, conf: ConfigSet, keys: Iterable[str]) -> None: # noqa: FBT001 - for key in keys if keys else conf: + for key in keys or conf: if key not in conf: continue key = conf.primary_key(key) # noqa: PLW2901 diff --git a/src/tox/tox_env/python/pip/pip_install.py b/src/tox/tox_env/python/pip/pip_install.py index f09d98d03..38b39bd6f 100644 --- a/src/tox/tox_env/python/pip/pip_install.py +++ b/src/tox/tox_env/python/pip/pip_install.py @@ -1,6 +1,7 @@ from __future__ import annotations import logging +import operator from collections import defaultdict from pathlib import Path from typing import TYPE_CHECKING, Any, Callable, Sequence @@ -132,7 +133,9 @@ def _install_requirement_file(self, arguments: PythonDeps, section: str, of_type if not eq: # pragma: no branch if old is not None: self._recreate_if_diff("install flag(s)", new_options, old["options"], lambda i: i) - self._recreate_if_diff("constraint(s)", new_constraints, old["constraints"], lambda i: i[3:]) + self._recreate_if_diff( + "constraint(s)", new_constraints, old["constraints"], operator.itemgetter(slice(3, None)) + ) missing_requirement = set(old["requirements"]) - set(new_requirements) if missing_requirement: msg = f"requirements removed: {' '.join(missing_requirement)}" diff --git a/src/tox/util/cpu.py b/src/tox/util/cpu.py index f076c26f5..3d20b7c47 100644 --- a/src/tox/util/cpu.py +++ b/src/tox/util/cpu.py @@ -10,7 +10,7 @@ def auto_detect_cpus() -> int: n: int | None = multiprocessing.cpu_count() except NotImplementedError: n = None - return n if n else 1 + return n or 1 __all__ = ("auto_detect_cpus",) diff --git a/tests/util/test_ci.py b/tests/util/test_ci.py index 36ee2ca6a..228689a2f 100644 --- a/tests/util/test_ci.py +++ b/tests/util/test_ci.py @@ -1,5 +1,7 @@ from __future__ import annotations +import operator + import pytest from tox.util.ci import _ENV_VARS, is_ci # noqa: PLC2701 @@ -22,7 +24,7 @@ "TEAMCITY_VERSION": None, # TeamCity "TRAVIS": "true", # Travis CI }.items(), - ids=lambda v: v[0], + ids=operator.itemgetter(0), ) def test_is_ci(env_var: tuple[str, str | None], monkeypatch: pytest.MonkeyPatch) -> None: for var in _ENV_VARS: @@ -41,7 +43,7 @@ def test_is_ci(env_var: tuple[str, str | None], monkeypatch: pytest.MonkeyPatch) "GITHUB_ACTIONS": "", # GitHub Actions "TRAVIS": "", # Travis CI }.items(), - ids=lambda v: v[0], + ids=operator.itemgetter(0), ) def test_is_ci_bad_set(env_var: tuple[str, str], monkeypatch: pytest.MonkeyPatch) -> None: for var in _ENV_VARS: diff --git a/tox.ini b/tox.ini index 43e3d2162..3d2d1c21f 100644 --- a/tox.ini +++ b/tox.ini @@ -40,7 +40,7 @@ commands = description = format the code base to adhere to our styles, and complain about what we cannot do automatically skip_install = true deps = - pre-commit>=3.6 + pre-commit>=3.7 pass_env = {[testenv]passenv} PROGRAMDATA @@ -51,7 +51,7 @@ commands = [testenv:type] description = run type check on code base deps = - mypy==1.8 + mypy==1.9 types-cachetools>=5.3.0.7 types-chardet>=5.0.4.6 commands = @@ -71,9 +71,9 @@ commands = description = check that the long description is valid skip_install = true deps = - build[virtualenv]>=1.0.3 + build[virtualenv]>=1.2.1 check-wheel-contents>=0.6 - twine>=4.0.2 + twine>=5 commands = python -m build -o {envtmpdir} -s -w . twine check {envtmpdir}{/}* @@ -83,8 +83,8 @@ commands = description = do a release, required posarg of the version number skip_install = true deps = - gitpython>=3.1.41 - packaging>=23.2 + gitpython>=3.1.43 + packaging>=24 towncrier>=23.11 commands = python {toxinidir}/tasks/release.py --version {posargs}