Skip to content

Commit

Permalink
Fix the CI
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Jan 11, 2024
1 parent 8406971 commit 3e842f6
Show file tree
Hide file tree
Showing 96 changed files with 260 additions and 186 deletions.
13 changes: 5 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ repos:
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
hooks:
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
Expand All @@ -21,20 +17,21 @@ repos:
- id: tox-ini-fmt
args: ["-p", "fix"]
- repo: https://github.com/tox-dev/pyproject-fmt
rev: 1.5.3
rev: 1.6.0
hooks:
- id: pyproject-fmt
additional_dependencies: ["tox>=4.11.4"]
- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.11]
additional_dependencies: [black==23.12.1]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
rev: v0.1.12
hooks:
- id: ruff-format
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --unsafe-fixes]
args: ["--fix", "--unsafe-fixes", "--exit-non-zero-on-fix"]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def resolve_xref( # noqa: PLR0913
tox_cfg = SourceFileLoader("tox_conf", str(here / "tox_conf.py")).load_module().ToxConfig
app.add_directive(tox_cfg.name, tox_cfg)

def check_uri(self: ExternalLinksChecker, refnode: reference) -> None: #
def check_uri(self: ExternalLinksChecker, refnode: reference) -> None:
if refnode.document.attributes["source"].endswith("index.rst"):
return None # do not use for the index file
return prev_check(self, refnode)
Expand Down
62 changes: 34 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
build-backend = "hatchling.build"
requires = [
"hatch-vcs>=0.4",
"hatchling>=1.18",
"hatchling>=1.21",
]

[project]
Expand Down Expand Up @@ -51,13 +51,13 @@ dependencies = [
"chardet>=5.2",
"colorama>=0.4.6",
"filelock>=3.13.1",
'importlib-metadata>=7; python_version < "3.8"',
'importlib-metadata>=7.0.1; python_version < "3.8"',
"packaging>=23.2",
"platformdirs>=4.1",
"pluggy>=1.3",
"pyproject-api>=1.6.1",
'tomli>=2.0.1; python_version < "3.11"',
'typing-extensions>=4.8; python_version < "3.8"',
'typing-extensions>=4.9; python_version < "3.8"',
"virtualenv>=20.25",
]
optional-dependencies.docs = [
Expand All @@ -75,13 +75,13 @@ optional-dependencies.testing = [
"covdefaults>=2.3",
"detect-test-pollution>=1.2",
"devpi-process>=1",
"diff-cover>=8.0.1",
"distlib>=0.3.7",
"diff-cover>=8.0.2",
"distlib>=0.3.8",
"flaky>=3.7",
"hatch-vcs>=0.4",
"hatchling>=1.18",
"psutil>=5.9.6",
"pytest>=7.4.3",
"hatchling>=1.21",
"psutil>=5.9.7",
"pytest>=7.4.4",
"pytest-cov>=4.1",
"pytest-mock>=3.12",
"pytest-xdist>=3.5",
Expand All @@ -106,34 +106,40 @@ version.source = "vcs"
select = ["ALL"]
line-length = 120
target-version = "py38"
isort = {known-first-party = ["tox", "tests"], required-imports = ["from __future__ import annotations"]}
isort = { known-first-party = ["tox", "tests"], required-imports = ["from __future__ import annotations"] }
ignore = [
"CPY", # No copyright header
"INP001", # no implicit namespaces here
"D", # ignore documentation for now
"D", # ignore documentation for now
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed in `arg`"
"ANN101", # Missing type annotation for `self` in method
"ANN102", # Missing type annotation for `cls` in classmethod"
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
"S104", # Possible binding to all interface
"COM812", # conflicts with formatter
"COM819", # conflicts with formatter
"E501", # conflicts with formatter
"ISC001", # conflicts with formatter
"Q000", # conflicts with formatter
"Q001", # conflicts with formatter
"Q002", # conflicts with formatter
"Q003", # conflicts with formatter
"W191", # conflicts with formatter
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
"S104", # Possible binding to all interfaces
"COM812", # conflicts with formatter
"COM819", # conflicts with formatter
"E501", # conflicts with formatter
"ISC001", # conflicts with formatter
"Q000", # conflicts with formatter
"Q001", # conflicts with formatter
"Q002", # conflicts with formatter
"Q003", # conflicts with formatter
"W191", # conflicts with formatter
"S404", # Using subprocess is alright.
"PLR0914", ## Too many local variables
"PLR0917", ## Too many positional arguments
]
format.preview = true
lint.preview = true
[tool.ruff.per-file-ignores]
"tests/**/*.py" = [
"S101", # asserts allowed in tests...
"FBT", # don"t care about booleans as positional arguments in tests
"INP001", # no implicit namespace
"D", # don"t care about documentation in tests
"S603", # `subprocess` call: check for execution of untrusted input
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
"S101", # asserts allowed in tests...
"FBT", # don"t care about booleans as positional arguments in tests
"INP001", # no implicit namespace
"D", # don"t care about documentation in tests
"S603", # `subprocess` call: check for execution of untrusted input
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
]

[tool.pytest.ini_options]
Expand Down
3 changes: 2 additions & 1 deletion src/tox/config/cli/env_var.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provides configuration values from the environment variables."""

from __future__ import annotations

import logging
Expand All @@ -24,7 +25,7 @@ def get_env_var(key: str, of_type: type[Any]) -> tuple[Any, str] | None:
value = os.environ[environ_key]
origin = getattr(of_type, "__origin__", of_type.__class__)
try:
if origin in (list, List):
if origin in {list, List}:
entry_type = of_type.__args__[0]
result = [CONVERT.to(raw=v, of_type=entry_type, factory=None) for v in value.split(";")]
else:
Expand Down
1 change: 1 addition & 0 deletions src/tox/config/cli/ini.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Provides configuration values from tox.ini files."""

from __future__ import annotations

import logging
Expand Down
7 changes: 4 additions & 3 deletions src/tox/config/cli/parse.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module pulls together this package: create and parse CLI arguments for tox."""

from __future__ import annotations

import os
Expand Down Expand Up @@ -51,7 +52,7 @@ def _get_base(args: Sequence[str]) -> tuple[int, ToxHandler, Source]:
... # ignore parse errors, such as -va raises ignored explicit argument 'a'
guess_verbosity = parsed.verbosity
handler = setup_report(guess_verbosity, parsed.is_colored)
from tox.plugin.manager import MANAGER # load the plugin system right after we set up report
from tox.plugin.manager import MANAGER # load the plugin system right after we set up report # noqa: PLC0415

source = discover_source(parsed.config_file, parsed.root_dir)

Expand All @@ -71,7 +72,7 @@ def _get_all(args: Sequence[str]) -> tuple[Parsed, dict[str, Callable[[State], i
def _get_parser() -> ToxParser:
tox_parser = ToxParser.core() # load the core options
# plus options setup by plugins
from tox.plugin.manager import MANAGER
from tox.plugin.manager import MANAGER # noqa: PLC0415

MANAGER.tox_add_option(tox_parser)
tox_parser.fix_defaults()
Expand All @@ -80,7 +81,7 @@ def _get_parser() -> ToxParser:

def _get_parser_doc() -> ToxParser:
# trigger register of tox env types (during normal run we call this later to handle plugins)
from tox.plugin.manager import MANAGER # pragma: no cover
from tox.plugin.manager import MANAGER # pragma: no cover # noqa: PLC0415

MANAGER.load_plugins(Path.cwd())

Expand Down
7 changes: 4 additions & 3 deletions src/tox/config/cli/parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Customize argparse logic for tox (also contains the base options)."""

from __future__ import annotations

import argparse
Expand Down Expand Up @@ -181,7 +182,7 @@ def add_command(

def add_argument_group(self, *args: Any, **kwargs: Any) -> Any:
result = super().add_argument_group(*args, **kwargs)
if self.of_cmd is None and args not in (("positional arguments",), ("optional arguments",)):
if self.of_cmd is None and args not in {("positional arguments",), ("optional arguments",)}:

def add_mutually_exclusive_group(**e_kwargs: Any) -> Any:
def add_argument(*a_args: str, of_type: type[Any] | None = None, **a_kwargs: Any) -> Action:
Expand Down Expand Up @@ -249,7 +250,7 @@ def parse_known_args( # type: ignore[override]
cmd_at = None
if cmd_at is not None: # if we found a command move it to the start
args = args[cmd_at], *args[:cmd_at], *args[cmd_at + 1 :]
elif args not in (("--help",), ("-h",)) and (self._cmd is not None and "legacy" in self._cmd.choices):
elif args not in {("--help",), ("-h",)} and (self._cmd is not None and "legacy" in self._cmd.choices):
# on help no mangling needed, and we also want to insert once we have legacy to insert
args = "legacy", *args
result = Parsed() if namespace is None else namespace
Expand All @@ -258,7 +259,7 @@ def parse_known_args( # type: ignore[override]


def add_verbosity_flags(parser: ArgumentParser) -> None:
from tox.report import LEVELS
from tox.report import LEVELS # noqa: PLC0415

level_map = "|".join(f"{c}={logging.getLevelName(level)}" for c, level in sorted(LEVELS.items()))
verbosity_group = parser.add_argument_group("verbosity")
Expand Down
4 changes: 2 additions & 2 deletions src/tox/config/loader/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .section import Section


class Override:
class Override: # noqa: PLW1641
"""An override for config definitions."""

def __init__(self, value: str) -> None:
Expand Down Expand Up @@ -127,7 +127,7 @@ def load( # noqa: PLR0913
:param args: the config load arguments
:return: the converted type
"""
from tox.config.set_env import SetEnv
from tox.config.set_env import SetEnv # noqa: PLC0415

override = self.overrides.get(key)
if override:
Expand Down
10 changes: 5 additions & 5 deletions src/tox/config/loader/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def to(self, raw: T, of_type: type[V], factory: Factory[V]) -> V: # noqa: PLR09
:return: the converted type
"""
from_module = getattr(of_type, "__module__", None)
if from_module in ("typing", "typing_extensions"):
if from_module in {"typing", "typing_extensions"}:
return self._to_typing(raw, of_type, factory)
if issubclass(of_type, Path):
return self.to_path(raw) # type: ignore[return-value]
Expand All @@ -49,13 +49,13 @@ def to(self, raw: T, of_type: type[V], factory: Factory[V]) -> V: # noqa: PLR09
def _to_typing(self, raw: T, of_type: type[V], factory: Factory[V]) -> V: # noqa: C901
origin = getattr(of_type, "__origin__", of_type.__class__)
result: Any = _NO_MAPPING
if origin in (list, List):
if origin in {list, List}:
entry_type = of_type.__args__[0] # type: ignore[attr-defined]
result = [self.to(i, entry_type, factory) for i in self.to_list(raw, entry_type)]
elif origin in (set, Set):
elif origin in {set, Set}:
entry_type = of_type.__args__[0] # type: ignore[attr-defined]
result = {self.to(i, entry_type, factory) for i in self.to_set(raw, entry_type)}
elif origin in (dict, Dict):
elif origin in {dict, Dict}:
key_type, value_type = of_type.__args__[0], of_type.__args__[1] # type: ignore[attr-defined]
result = OrderedDict(
(self.to(k, key_type, factory), self.to(v, value_type, factory))
Expand All @@ -72,7 +72,7 @@ def _to_typing(self, raw: T, of_type: type[V], factory: Factory[V]) -> V: # noq
else:
new_type = next(i for i in args if i != none) # type: ignore[comparison-overlap] # pragma: no cover
result = self.to(raw, new_type, factory)
elif origin in (Literal, type(Literal)):
elif origin in {Literal, type(Literal)}:
choice = of_type.__args__ # type: ignore[attr-defined]
if raw not in choice:
msg = f"{raw} must be one of {choice}"
Expand Down
1 change: 1 addition & 0 deletions src/tox/config/loader/ini/factor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Expand tox factor expressions to tox environment list."""

from __future__ import annotations

import re
Expand Down
3 changes: 2 additions & 1 deletion src/tox/config/loader/ini/replace.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Apply value substitution (replacement) on tox strings."""

from __future__ import annotations

import logging
Expand Down Expand Up @@ -57,7 +58,7 @@ def replace(conf: Config, loader: IniLoader, value: str, args: ConfigLoadArgs, d
return Replacer(conf, loader, conf_args=args, depth=depth).join(find_replace_expr(value))


class MatchExpression:
class MatchExpression: # noqa: PLW1641
"""An expression that is handled specially by the Replacer."""

def __init__(self, expr: Sequence[MatchArg], term_pos: int | None = None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/tox/config/loader/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing_extensions import Self


class Section:
class Section: # noqa: PLW1641
"""tox configuration section."""

SEP = ":" #: string used to separate the prefix and the section in the key
Expand Down
5 changes: 3 additions & 2 deletions src/tox/config/loader/str_convert.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Convert string configuration values to tox python configuration objects."""

from __future__ import annotations

import shlex
Expand Down Expand Up @@ -65,7 +66,7 @@ def _win32_process_path_backslash(value: str, escape: str, special_chars: str) -
if last_char == escape:
continue
next_char = value[ix + 1 : ix + 2]
if next_char not in (escape, *special_chars):
if next_char not in {escape, *special_chars}:
result.append(escape) # escape escapes that are not themselves escaping a special character
return "".join(result)

Expand Down Expand Up @@ -109,7 +110,7 @@ def to_command(value: str) -> Command:

@staticmethod
def to_env_list(value: str) -> EnvList:
from tox.config.loader.ini.factor import extend_factors
from tox.config.loader.ini.factor import extend_factors # noqa: PLC0415

elements = list(chain.from_iterable(extend_factors(expr) for expr in value.split("\n")))
return EnvList(elements)
Expand Down
7 changes: 4 additions & 3 deletions src/tox/config/of_type.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Group together configuration values (such as base tox configuration, tox environment configs)."""

from __future__ import annotations

from abc import ABC, abstractmethod
Expand All @@ -16,7 +17,7 @@
V = TypeVar("V")


class ConfigDefinition(ABC, Generic[T]):
class ConfigDefinition(ABC, Generic[T]): # noqa: PLW1641
"""Abstract base class for configuration definitions."""

def __init__(self, keys: Iterable[str], desc: str) -> None:
Expand All @@ -34,7 +35,7 @@ def __ne__(self, o: object) -> bool:
return not (self == o)


class ConfigConstantDefinition(ConfigDefinition[T]):
class ConfigConstantDefinition(ConfigDefinition[T]): # noqa: PLW1641
"""A configuration definition whose value is defined upfront (such as the tox environment name)."""

def __init__(
Expand All @@ -61,7 +62,7 @@ def __eq__(self, o: object) -> bool:
_PLACE_HOLDER = object()


class ConfigDynamicDefinition(ConfigDefinition[T]):
class ConfigDynamicDefinition(ConfigDefinition[T]): # noqa: PLW1641
"""A configuration definition that comes from a source (such as in memory, an ini file, a toml file, etc.)."""

def __init__( # noqa: PLR0913
Expand Down
4 changes: 2 additions & 2 deletions src/tox/config/set_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, raw: str, name: str, env_name: str | None, root: Path) -> Non
self._env_files: list[str] = []
self._replacer: Replacer = lambda s, c: s # noqa: ARG005
self._name, self._env_name, self._root = name, env_name, root
from .loader.ini.replace import MatchExpression, find_replace_expr
from .loader.ini.replace import MatchExpression, find_replace_expr # noqa: PLC0415

for line in raw.splitlines():
if line.strip():
Expand Down Expand Up @@ -82,7 +82,7 @@ def load(self, item: str, args: ConfigLoadArgs | None = None) -> str:
return result

def __contains__(self, item: object) -> bool:
return isinstance(item, str) and item in self.__iter__()
return isinstance(item, str) and item in iter(self)

def __iter__(self) -> Iterator[str]:
# start with the materialized ones, maybe we don't need to materialize the raw ones
Expand Down

0 comments on commit 3e842f6

Please sign in to comment.