Skip to content

Commit 6dac34f

Browse files
committed
Fix a bunch of ruff errors
1 parent a4eb63c commit 6dac34f

File tree

8 files changed

+46
-31
lines changed

8 files changed

+46
-31
lines changed

pip_check_reqs/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
"""Common functions."""
23

34
import ast

pip_check_reqs/find_extra_reqs.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
"""Find extra requirements."""
22

3+
from __future__ import annotations
4+
35
import argparse
46
import collections
57
import importlib.metadata
68
import logging
79
import os
810
import sys
911
from pathlib import Path
10-
from typing import Callable, Iterable, List, Optional, Union
12+
from typing import TYPE_CHECKING, Callable, Iterable
1113
from unittest import mock
1214

1315
from packaging.utils import canonicalize_name
1416
from pip._internal.commands.show import search_packages_info
15-
from pip._internal.req.req_file import ParsedRequirement
1617

1718
from pip_check_reqs import common
1819
from pip_check_reqs.common import version_info
1920

21+
if TYPE_CHECKING:
22+
from pip._internal.req.req_file import ParsedRequirement
23+
2024
log = logging.getLogger(__name__)
2125

2226

@@ -26,10 +30,10 @@ def find_extra_reqs(
2630
ignore_files_function: Callable[[str], bool],
2731
ignore_modules_function: Callable[[str], bool],
2832
ignore_requirements_function: Callable[
29-
[Union[str, ParsedRequirement]], bool,
33+
[str | ParsedRequirement], bool,
3034
],
3135
skip_incompatible: bool,
32-
) -> List[str]:
36+
) -> list[str]:
3337
# 1. find files used by imports in the code (as best we can without
3438
# executing)
3539
used_modules = common.find_imported_modules(
@@ -112,7 +116,7 @@ def find_extra_reqs(
112116
return [name for name in explicit if name not in used]
113117

114118

115-
def main(arguments: Optional[List[str]] = None) -> None:
119+
def main(arguments: list[str] | None = None) -> None:
116120
"""Main entry point."""
117121
usage = "usage: %prog [options] files or directories"
118122
parser = argparse.ArgumentParser(usage)

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ line-length = 79
9595
strict = true
9696

9797
[tool.ruff]
98+
99+
target-version = "py38"
100+
98101
select = ["ALL"]
99102

100103
ignore = [

setup.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
from codecs import open
2-
from os import path
1+
from __future__ import annotations
2+
33
from pathlib import Path
4-
from typing import List
54

65
from setuptools import setup
76

87
from pip_check_reqs import __version__
98

10-
here = path.abspath(path.dirname(__file__))
9+
here = Path.resolve(Path(__file__).parent)
1110

1211

13-
def _get_dependencies(requirements_file: Path) -> List[str]:
12+
def _get_dependencies(requirements_file: Path) -> list[str]:
1413
"""Return requirements from a requirements file.
14+
1515
This expects a requirements file with no ``--find-links`` lines.
1616
"""
1717
lines = requirements_file.read_text().strip().split("\n")
1818
return [line for line in lines if not line.startswith("#")]
1919

2020

21-
with open(path.join(here, "README.rst"), encoding="utf-8") as f:
22-
long_description = f.read()
23-
24-
with open(path.join(here, "CHANGELOG.rst"), encoding="utf-8") as f:
25-
long_description += f.read()
21+
readme = here / "README.rst"
22+
readme_content = readme.read_text(encoding="utf-8")
23+
changelog = here / "CHANGELOG.rst"
24+
changelog_content = changelog.read_text(encoding="utf-8")
25+
long_description = readme_content + "\n\n" + changelog_content
2626

2727
INSTALL_REQUIRES = _get_dependencies(
2828
requirements_file=Path("requirements.txt"),

tests/__init__.py

Whitespace-only changes.

tests/test_common.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for `common.py`."""
22

3+
from __future__ import annotations
34

45
import ast
56
import builtins
@@ -8,7 +9,7 @@
89
import textwrap
910
from copy import copy
1011
from pathlib import Path
11-
from typing import Any, List, Tuple
12+
from typing import Any
1213

1314
import pytest
1415
from pytest import MonkeyPatch
@@ -53,7 +54,7 @@ def test_found_module() -> None:
5354
("from . import baz", []),
5455
],
5556
)
56-
def test_import_visitor(stmt: str, result: List[str]) -> None:
57+
def test_import_visitor(stmt: str, result: list[str]) -> None:
5758
vis = common._ImportVisitor( # pylint: disable=protected-access
5859
ignore_modules_function=common.ignorer(ignore_cfg=[]),
5960
)
@@ -118,8 +119,8 @@ def test_find_imported_modules(
118119
caplog: pytest.LogCaptureFixture,
119120
ignore_ham: bool,
120121
ignore_hashlib: bool,
121-
expect: List[str],
122-
locs: List[Tuple[str, int]],
122+
expect: list[str],
123+
locs: list[tuple[str, int]],
123124
tmp_path: Path,
124125
) -> None:
125126
root = tmp_path
@@ -188,7 +189,7 @@ def ignore_mods(module: str) -> bool:
188189
)
189190
def test_ignorer(
190191
monkeypatch: MonkeyPatch,
191-
ignore_cfg: List[str],
192+
ignore_cfg: list[str],
192193
candidate: str,
193194
result: bool,
194195
) -> None:

tests/test_find_extra_reqs.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
"""Tests for `find_extra_reqs.py`."""
22

3+
from __future__ import annotations
34

45
import logging
56
import textwrap
6-
from pathlib import Path
7-
from typing import Set
7+
from typing import TYPE_CHECKING
88

99
import black
1010
import pytest
1111

1212
from pip_check_reqs import common, find_extra_reqs
1313

14+
if TYPE_CHECKING:
15+
from pathlib import Path
16+
1417

1518
def test_find_extra_reqs(tmp_path: Path) -> None:
1619
installed_not_imported_required_package = pytest
@@ -87,26 +90,28 @@ def test_main_no_spec(capsys: pytest.CaptureFixture[str]) -> None:
8790
with pytest.raises(SystemExit) as excinfo:
8891
find_extra_reqs.main(arguments=[])
8992

90-
assert excinfo.value.code == 2
93+
expected_code = 2
94+
assert excinfo.value.code == expected_code
9195
err = capsys.readouterr().err
9296
assert err.endswith("error: no source files or directories specified\n")
9397

9498

9599
@pytest.mark.parametrize(
96-
("verbose_cfg", "debug_cfg", "expected_log_levels"),
100+
("expected_log_levels", "verbose_cfg", "debug_cfg"),
97101
[
98-
(False, False, {logging.WARNING}),
99-
(True, False, {logging.INFO, logging.WARNING}),
100-
(False, True, {logging.DEBUG, logging.INFO, logging.WARNING}),
101-
(True, True, {logging.DEBUG, logging.INFO, logging.WARNING}),
102+
({logging.WARNING}, False, False),
103+
({logging.INFO, logging.WARNING}, True, False),
104+
({logging.DEBUG, logging.INFO, logging.WARNING}, False, True),
105+
({logging.DEBUG, logging.INFO, logging.WARNING}, True, True),
102106
],
103107
)
104108
def test_logging_config(
105109
caplog: pytest.LogCaptureFixture,
110+
expected_log_levels: set[int],
111+
tmp_path: Path,
112+
*,
106113
verbose_cfg: bool,
107114
debug_cfg: bool,
108-
expected_log_levels: Set[int],
109-
tmp_path: Path,
110115
) -> None:
111116
source_dir = tmp_path / "source"
112117
source_dir.mkdir()

tests/test_find_missing_reqs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ def test_main_no_spec(capsys: pytest.CaptureFixture[str]) -> None:
107107
with pytest.raises(SystemExit) as excinfo:
108108
find_missing_reqs.main(arguments=[])
109109

110-
assert excinfo.value.code == 2
110+
expected_code = 2
111+
assert excinfo.value.code == expected_code
111112
err = capsys.readouterr().err
112113
assert err.endswith("error: no source files or directories specified\n")
113114

0 commit comments

Comments
 (0)