Skip to content

Commit 1be23f9

Browse files
Merge pull request #133 from r1chardj0n3s/rm-imp-again
Support Python 3.12
2 parents 7a42481 + 99e1d32 commit 1be23f9

File tree

7 files changed

+45
-41
lines changed

7 files changed

+45
-41
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jobs:
2222
# These versions match the minimum and maximum versions of pip in
2323
# requirements.txt.
2424
# An empty string here represents the latest version.
25-
pip-version: ['==21.2.4', '']
25+
pip-version: ['==23.2', '']
2626
# The minimum version should be represented in setup.py.
27-
python-version: ["3.8", "3.9", "3.10", "3.11"]
27+
python-version: ["3.9", "3.10", "3.11", "3.12-dev"]
2828

2929
steps:
3030
- uses: actions/checkout@v4
@@ -53,15 +53,20 @@ jobs:
5353
# We avoid "--upgrade" as we do version tests for the "pip" dependency.
5454
python -m pip install --ignore-installed --editable .[dev]
5555
56-
- name: "Lint"
56+
# Separate Pylint as it fails on Python 3.12 for unrelated reasons.
57+
- name: "Lint without pylint"
5758
run: |
5859
mypy .
5960
ruff .
6061
black --check .
61-
pylint pip_check_reqs tests
6262
pip-extra-reqs pip_check_reqs
6363
pip-missing-reqs pip_check_reqs
6464
65+
- name: "Lint pylint"
66+
if: matrix.python-version != '3.12-dev'
67+
run: |
68+
pylint pip_check_reqs tests
69+
6570
- name: "Run tests"
6671
run: |
6772
pytest -s -vvv --cov-fail-under 100 --cov=pip_check_reqs/ --cov=tests tests/ --cov-report=xml

CHANGELOG.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
Release History
33
---------------
44

5+
2.5.0
6+
7+
- Support Python 3.10.
8+
- Remove support for Python 3.8.
9+
- Bump `pip` requirement to 23.2.
10+
511
2.4.4
612

7-
- Bump `packaging` requirement to >= 20.5. Older versions of `pip-check-reqs` may be broken with the previously-specified version requirements.
13+
- Bump `packaging` requirement to >= 20.5. Older versions of `pip-check-reqs` may be broken with the previously-specified version requirements.
814

915
2.4.3
1016

pip_check_reqs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Package for finding missing and extra requirements."""
22

3-
__version__ = "2.4.4"
3+
__version__ = "2.5.0"

pip_check_reqs/common.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import ast
66
import fnmatch
7-
import imp
7+
import importlib
88
import logging
99
import os
1010
import re
@@ -77,41 +77,32 @@ def _add_module(self, modname: str, lineno: int) -> None:
7777
return
7878
path = None
7979
progress = []
80-
modpath = last_modpath = None
80+
modpath = None
8181
for modname_part in modname.split("."):
82-
try:
83-
_, modpath, _ = imp.find_module(modname_part, path)
84-
except ImportError:
85-
# the component specified at this point is not importable
86-
# (is just an attribute of the module)
87-
# *or* it's not actually installed, so we don't care either
88-
break
89-
90-
# success! we found *something*
91-
progress.append(modname_part)
82+
find_spec_result = importlib.util.find_spec(
83+
name=modname_part,
84+
package=path,
85+
)
9286

93-
# we might have previously seen a useful path though...
94-
if modpath is None:
95-
# the `sys` module will hit this code path, and `os` will on
96-
# 3.11+.
97-
# Possibly others will, but I've not discovered them.
98-
modpath = last_modpath
87+
if find_spec_result is None:
88+
# The component specified at this point is not installed.
9989
break
10090

101-
# ... though it might not be a file, so not interesting to us
102-
if not Path(modpath).is_dir():
103-
break
91+
modpath = find_spec_result.origin
10492

105-
path = [modpath]
106-
last_modpath = modpath
93+
# success! we found *something*
94+
progress.append(modname_part)
10795

10896
if modpath is None:
10997
# the module doesn't actually appear to exist on disk
11098
return
11199

112100
modname = ".".join(progress)
113101
if modname not in self._modules:
114-
self._modules[modname] = FoundModule(modname, modpath)
102+
self._modules[modname] = FoundModule(
103+
modname=modname,
104+
filename=str(Path(modpath).parent),
105+
)
115106
assert isinstance(self._location, str)
116107
self._modules[modname].locations.append((self._location, lineno))
117108

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
packaging >= 20.5
22
# Pinned pip versions are matched in the GitHub workflows CI matrix.
3-
pip >= 21.2.4
3+
pip >= 23.2

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ def _get_dependencies(requirements_file: Path) -> list[str]:
5151
"Intended Audience :: Developers",
5252
"Topic :: Software Development :: Build Tools",
5353
"License :: OSI Approved :: MIT License",
54-
"Programming Language :: Python :: 3.8",
5554
"Programming Language :: Python :: 3.9",
5655
"Programming Language :: Python :: 3.10",
5756
"Programming Language :: Python :: 3.11",
57+
"Programming Language :: Python :: 3.12",
5858
],
59-
python_requires=">=3.8.0",
59+
python_requires=">=3.9.0",
6060
packages=["pip_check_reqs"],
6161
entry_points={
6262
"console_scripts": [

tests/test_common.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_found_module() -> None:
4444
("import ast, pathlib", ["ast", "pathlib"]),
4545
("from pathlib import Path", ["pathlib"]),
4646
("from string import hexdigits", ["string"]),
47-
("import distutils.command.check", ["distutils.command.check"]),
47+
("import urllib.request", ["urllib"]),
4848
("import spam", []), # don't break because bad programmer
4949
("from .foo import bar", []), # don't break on relative imports
5050
("from . import baz", []),
@@ -94,24 +94,26 @@ def test_pyfiles_package(tmp_path: Path) -> None:
9494
]
9595

9696

97-
# Beware - using `sys` or `os` here can have weird results.
98-
# See the comment in the implementation.
99-
# We don't mind so much as we only really use this for third party packages.
10097
@pytest.mark.parametrize(
10198
("ignore_ham", "ignore_hashlib", "expect", "locs"),
10299
[
103100
(
104101
False,
105102
False,
106-
["ast", "pathlib", "hashlib"],
103+
["ast", "pathlib", "hashlib", "sys"],
107104
[
108105
("spam.py", 2),
109106
("ham.py", 2),
110107
],
111108
),
112-
(False, True, ["ast", "pathlib"], [("spam.py", 2), ("ham.py", 2)]),
113-
(True, False, ["ast"], [("spam.py", 2)]),
114-
(True, True, ["ast"], [("spam.py", 2)]),
109+
(
110+
False,
111+
True,
112+
["ast", "pathlib", "sys"],
113+
[("spam.py", 2), ("ham.py", 2)],
114+
),
115+
(True, False, ["ast", "sys"], [("spam.py", 2)]),
116+
(True, True, ["ast", "sys"], [("spam.py", 2)]),
115117
],
116118
)
117119
def test_find_imported_modules(

0 commit comments

Comments
 (0)