Skip to content

Commit 618b824

Browse files
committed
Upgrade tools and deps
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
1 parent 3e08f54 commit 618b824

11 files changed

Lines changed: 77 additions & 62 deletions

File tree

.pre-commit-config.yaml

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,28 @@ repos:
44
hooks:
55
- id: end-of-file-fixer
66
- id: trailing-whitespace
7+
- repo: https://github.com/codespell-project/codespell
8+
rev: v2.2.6
9+
hooks:
10+
- id: codespell
11+
additional_dependencies: [ "tomli>=2.0.1" ]
12+
- repo: https://github.com/PyCQA/docformatter
13+
rev: v1.7.5
14+
hooks:
15+
- id: docformatter
16+
additional_dependencies: [ "tomli>=2.0.1" ]
17+
args: [ "--in-place", "--config", "./pyproject.toml" ]
718
- repo: https://github.com/astral-sh/ruff-pre-commit
8-
rev: "v0.1.14"
19+
rev: "v0.1.15"
920
hooks:
1021
- id: ruff-format
1122
- id: ruff
12-
args: ["--fix", "--unsafe-fixes", "--exit-non-zero-on-fix"]
13-
- repo: https://github.com/tox-dev/tox-ini-fmt
14-
rev: "1.3.1"
15-
hooks:
16-
- id: tox-ini-fmt
17-
args: ["-p", "fix"]
23+
args: [ "--fix", "--unsafe-fixes", "--exit-non-zero-on-fix" ]
1824
- repo: https://github.com/tox-dev/pyproject-fmt
1925
rev: "1.7.0"
2026
hooks:
2127
- id: pyproject-fmt
22-
additional_dependencies: ["tox>=4.11.4"]
23-
- repo: https://github.com/asottile/blacken-docs
24-
rev: 1.16.0
25-
hooks:
26-
- id: blacken-docs
27-
additional_dependencies: [black==23.11]
28-
- repo: https://github.com/pre-commit/pygrep-hooks
29-
rev: v1.10.0
30-
hooks:
31-
- id: rst-backticks
28+
additional_dependencies: ["tox>=4.12.1"]
3229
- repo: meta
3330
hooks:
3431
- id: check-hooks-apply

pyproject.toml

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ dependencies = [
4646
'typing-extensions>=4.7.1; python_version < "3.11"',
4747
]
4848
optional-dependencies.docs = [
49-
"furo>=2023.9.10",
49+
"furo>=2024.1.29",
5050
"sphinx<7.2",
51-
"sphinx-autodoc-typehints>=1.25.2",
51+
"sphinx-autodoc-typehints>=1.25.3",
5252
]
5353
optional-dependencies.testing = [
5454
"covdefaults>=2.3",
55-
"pytest>=7.4.3",
55+
"pytest>=7.4.4",
5656
"pytest-cov>=4.1",
5757
"pytest-mock>=3.11.1",
5858
"setuptools>=68",
@@ -65,33 +65,48 @@ urls.Tracker = "https://github.com/tox-dev/py-discovery/issues"
6565
build.hooks.vcs.version-file = "src/py_discovery/_version.py"
6666
version.source = "vcs"
6767

68-
[tool.black]
69-
line-length = 120
70-
7168
[tool.ruff]
7269
select = ["ALL"]
7370
line-length = 120
7471
target-version = "py37"
75-
isort = {known-first-party = ["py_discovery"], required-imports = ["from __future__ import annotations"]}
72+
isort = { known-first-party = ["py_discovery"], required-imports = ["from __future__ import annotations"] }
7673
ignore = [
77-
"INP001", # no implicit namespaces here
78-
"ANN101", # Missing type annotation for `self` in method
79-
"ANN102", # Missing type annotation for `cls` in classmethod"
80-
"ANN401", # Dynamically typed expressions
81-
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
82-
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
83-
"S104", # Possible binding to all interfaces
74+
"INP001", # no implicit namespaces here
75+
"ANN101", # Missing type annotation for `self` in method
76+
"ANN102", # Missing type annotation for `cls` in classmethod"
77+
"ANN401", # Dynamically typed expressions
78+
"D203", # `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible
79+
"D212", # `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible
80+
"S104", # Possible binding to all interfaces
81+
"CPY", # no copyright
8482
]
83+
format.preview = true
84+
lint.preview = true
8585
[tool.ruff.per-file-ignores]
8686
"tests/**/*.py" = [
87-
"S101", # asserts allowed in tests
88-
"FBT", # don't care about booleans as positional arguments in tests
89-
"INP001", # no implicit namespace
90-
"D", # don't care about documentation in tests
91-
"S603", # `subprocess` call: check for execution of untrusted input
92-
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
87+
"S101", # asserts allowed in tests
88+
"FBT", # don't care about booleans as positional arguments in tests
89+
"INP001", # no implicit namespace
90+
"D", # don't care about documentation in tests
91+
"S603", # `subprocess` call: check for execution of untrusted input
92+
"PLR2004", # Magic value used in comparison, consider replacing with a constant variable
93+
"PLC2701", # Private imports
94+
"PLR0917", # too many positional arguments
95+
"PLC0415", # import at top
9396
]
9497

98+
[tool.codespell]
99+
builtin = "clear,usage,en-GB_to_en-US"
100+
count = true
101+
quiet-level = 3
102+
103+
[tool.docformatter]
104+
blank = true
105+
recursive = true
106+
pre-summary-newline = true
107+
wrap-descriptions = 120
108+
wrap-summaries = 120
109+
95110
[tool.coverage]
96111
report.fail_under = 87
97112
html.show_contexts = true
@@ -110,7 +125,7 @@ run.parallel = true
110125
run.plugins = ["covdefaults"]
111126

112127
[tool.mypy]
113-
python_version = "3.7"
128+
python_version = "3.8"
114129
show_error_codes = true
115130
strict = true
116131
overrides = [{ module = ["setuptools.*"], ignore_missing_imports = true }]

src/py_discovery/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Python discovery."""
2+
23
from __future__ import annotations
34

45
from ._builtin import Builtin, PathPythonInfo, get_interpreter
@@ -10,12 +11,12 @@
1011
__version__ = version #: version of the package
1112

1213
__all__ = [
13-
"PythonInfo",
14-
"VersionInfo",
15-
"PythonSpec",
16-
"Discover",
1714
"Builtin",
15+
"Discover",
1816
"PathPythonInfo",
19-
"get_interpreter",
17+
"PythonInfo",
18+
"PythonSpec",
19+
"VersionInfo",
2020
"__version__",
21+
"get_interpreter",
2122
]

src/py_discovery/_builtin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def propose_interpreters( # noqa: C901, PLR0912
110110

111111
# 3. otherwise fallbacks to platform default logic
112112
if sys.platform == "win32":
113-
from ._windows import propose_interpreters
113+
from ._windows import propose_interpreters # noqa: PLC0415
114114

115115
for interpreter in propose_interpreters(spec, env):
116116
yield interpreter, True
@@ -184,11 +184,11 @@ def possible_specs(spec: PythonSpec) -> Iterator[tuple[str, bool]]:
184184

185185

186186
class PathPythonInfo(PythonInfo):
187-
"""python info from a path."""
187+
"""Python info from a path."""
188188

189189

190190
__all__ = [
191-
"get_interpreter",
192191
"Builtin",
193192
"PathPythonInfo",
193+
"get_interpreter",
194194
]

src/py_discovery/_discover.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def add_parser_arguments(cls, parser: ArgumentParser) -> None:
1818
Add CLI arguments for this discovery mechanisms.
1919
2020
:param parser: The CLI parser.
21+
2122
"""
2223
raise NotImplementedError
2324

@@ -26,6 +27,7 @@ def __init__(self, options: Namespace) -> None:
2627
Create a new discovery mechanism.
2728
2829
:param options: The parsed options as defined within the :meth:`add_parser_arguments`.
30+
2931
"""
3032
self._has_run = False
3133
self._interpreter: PythonInfo | None = None
@@ -37,6 +39,7 @@ def run(self) -> PythonInfo | None:
3739
Discovers an interpreter.
3840
3941
:return: The interpreter ready to use for virtual environment creation
42+
4043
"""
4144
raise NotImplementedError
4245

src/py_discovery/_info.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
The PythonInfo contains information about a concrete instance of a Python interpreter.
33
44
Note: this file is also used to query target interpreters, so can only use standard library methods
5+
56
"""
67

78
from __future__ import annotations
@@ -20,7 +21,7 @@
2021
from random import choice
2122
from shlex import quote
2223
from string import ascii_lowercase, ascii_uppercase, digits
23-
from subprocess import PIPE, Popen
24+
from subprocess import PIPE, Popen # noqa: S404
2425
from tempfile import NamedTemporaryFile
2526
from typing import TYPE_CHECKING, Any, Iterator, Mapping, MutableMapping
2627

@@ -152,7 +153,7 @@ def abs_path(v: str | None) -> str | None:
152153
def _fast_get_system_executable(self) -> str | None:
153154
"""Try to get the system executable by just looking at properties."""
154155
# if this is a virtual environment
155-
if self.real_prefix or self.base_prefix is not None and self.base_prefix != self.prefix:
156+
if self.real_prefix or (self.base_prefix is not None and self.base_prefix != self.prefix): # noqa: PLR1702
156157
if self.real_prefix is None:
157158
# some platforms may set this to help us
158159
base_executable: str | None = getattr(sys, "_base_executable", None)
@@ -196,8 +197,8 @@ def _distutils_install() -> dict[str, str]:
196197
with warnings.catch_warnings(): # disable warning for PEP-632
197198
warnings.simplefilter("ignore")
198199
try:
199-
from distutils import dist
200-
from distutils.command.install import SCHEME_KEYS
200+
from distutils import dist # noqa: PLC0415
201+
from distutils.command.install import SCHEME_KEYS # noqa: PLC0415
201202
except ImportError: # if removed or not installed ignore
202203
return {}
203204

@@ -275,9 +276,6 @@ def system_exec_prefix(self) -> str:
275276
assert res is not None # noqa: S101
276277
return res
277278

278-
def __unicode__(self) -> str:
279-
return repr(self)
280-
281279
def __repr__(self) -> str:
282280
return "{}({!r})".format(
283281
self.__class__.__name__,
@@ -357,6 +355,7 @@ def current(cls) -> PythonInfo:
357355
Locate the current host interpreter information.
358356
359357
This might be different than what we run into in case the host python has been upgraded from underneath us.
358+
360359
"""
361360
if cls._current is None:
362361
cls._current = cls.from_exe(sys.executable, raise_on_error=True, resolve_to_host=False)
@@ -369,6 +368,7 @@ def current_system(cls) -> PythonInfo:
369368
Locate the current host interpreter information.
370369
371370
This might be different than what we run into in case the host python has been upgraded from underneath us.
371+
372372
"""
373373
if cls._current_system is None:
374374
cls._current_system = cls.from_exe(sys.executable, raise_on_error=True, resolve_to_host=True)
@@ -380,7 +380,7 @@ def _to_json(self) -> str:
380380
return json.dumps(self._to_dict(), indent=2)
381381

382382
def _to_dict(self) -> dict[str, Any]:
383-
data = {var: (getattr(self, var) if var not in ("_creators",) else None) for var in vars(self)}
383+
data = {var: (getattr(self, var) if var != "_creators" else None) for var in vars(self)}
384384

385385
data["version_info"] = data["version_info"]._asdict() # namedtuple to dictionary
386386
return data
@@ -683,10 +683,10 @@ def __repr__(self) -> str:
683683

684684

685685
__all__ = [
686+
"EXTENSIONS",
686687
"PythonInfo",
687688
"VersionInfo",
688689
"fs_is_case_sensitive",
689-
"EXTENSIONS",
690690
]
691691

692692

src/py_discovery/_spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class PythonSpec:
1616
"""Contains specification about a Python Interpreter."""
1717

18-
def __init__( # noqa: PLR0913
18+
def __init__( # noqa: PLR0913, PLR0917
1919
self,
2020
str_spec: str | None,
2121
implementation: str | None,
@@ -36,7 +36,7 @@ def __init__( # noqa: PLR0913
3636
@classmethod
3737
def from_string_spec(cls, string_spec: str) -> PythonSpec: # noqa: C901, PLR0912
3838
impl, major, minor, micro, arch, path = None, None, None, None, None, None
39-
if os.path.isabs(string_spec): # noqa: PTH117
39+
if os.path.isabs(string_spec): # noqa: PTH117, PLR1702
4040
path = string_spec
4141
else:
4242
ok = False

src/py_discovery/_windows/pep514.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ def __exit__(
4747
exc_type: type[BaseException] | None,
4848
exc_value: BaseException | None,
4949
traceback: TracebackType | None,
50-
) -> bool | None:
51-
...
50+
) -> bool | None: ...
5251

5352
def EnumKey(__key: _KeyType, __index: int) -> str: # noqa: N802
5453
return ""

tests/test_py_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_system_executable_no_exact_match( # noqa: PLR0913
160160
mocker: MockerFixture,
161161
caplog: pytest.LogCaptureFixture,
162162
) -> None:
163-
"""Here we should fallback to other compatible"""
163+
"""Here we should fallback to other compatible."""
164164
caplog.set_level(logging.DEBUG)
165165

166166
def _make_py_info(of: PyInfoMock) -> PythonInfo:

tests/windows/test_windows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_propose_interpreters(string_spec: str, expected_exe: str, mocker: Mocke
119119

120120

121121
def _mock_pyinfo(major: int | None, minor: int | None, arch: int | None, exe: str) -> PythonInfo:
122-
"""Return PythonInfo objects with essential metadata set for the given args"""
122+
"""Return PythonInfo objects with essential metadata set for the given args."""
123123
info = PythonInfo()
124124
info.base_prefix = str(Path(exe).parent)
125125
info.executable = info.original_executable = info.system_executable = exe

0 commit comments

Comments
 (0)