Skip to content

Commit 193a066

Browse files
committed
drop python<=3.7 support
According to https://endoflife.date/python python 3.7 has been EOSed 27 Jun 2023. Filter all code over `pyupgrade --py38-plus`. Signed-off-by: Tomasz Kłoczko <[email protected]>
1 parent 9ec1751 commit 193a066

16 files changed

+246
-279
lines changed

src/scikit_build_core/_compat/importlib/metadata.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
import sys
44
import typing
55

6-
if sys.version_info < (3, 8):
7-
import importlib_metadata as _metadata
8-
from importlib_metadata import PathDistribution, version
9-
else:
10-
import importlib.metadata as _metadata
11-
from importlib.metadata import PathDistribution, version
6+
import importlib.metadata as _metadata
7+
from importlib.metadata import PathDistribution, version
128

139

1410
if typing.TYPE_CHECKING:

src/scikit_build_core/_compat/typing.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
import sys
44
import typing
55

6-
if sys.version_info < (3, 8):
7-
from typing_extensions import (
8-
Literal,
9-
Protocol,
10-
)
11-
else:
12-
from typing import Literal, Protocol
6+
from typing import Literal, Protocol
137

148
if sys.version_info < (3, 9):
159
from typing_extensions import Annotated, get_args, get_origin

src/scikit_build_core/_logging.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ def __repr__(self) -> str:
3737
)
3838

3939

40-
if sys.version_info < (3, 8):
41-
opts: Any = {}
42-
else:
43-
opts: Any = {"stacklevel": 2}
40+
opts: Any = {"stacklevel": 2}
4441

4542

4643
class ScikitBuildLogger:

tests/conftest.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,8 @@
1212

1313
import virtualenv as _virtualenv
1414

15-
if sys.version_info < (3, 8):
16-
import importlib_metadata as metadata
17-
from typing_extensions import Literal, overload
18-
else:
19-
from importlib import metadata
20-
from typing import Literal, overload
15+
from importlib import metadata
16+
from typing import Literal, overload
2117

2218
if sys.version_info < (3, 11):
2319
import tomli as tomllib

tests/test_custom_modules.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ def test_ep(isolated):
2323
contents = Path(script).read_text()
2424
assert contents.startswith(f"#!{pysys}")
2525

26-
if sys.version_info >= (3, 8):
27-
assert (
28-
isolated.execute(
29-
"from importlib import metadata; print(metadata.version('custom_modules'), end='')"
30-
)
31-
== "2.3.4"
26+
assert (
27+
isolated.execute(
28+
"from importlib import metadata; print(metadata.version('custom_modules'), end='')"
3229
)
30+
== "2.3.4"
31+
)

tests/test_dynamic_metadata.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -236,24 +236,23 @@ def test_pep517_wheel(virtualenv):
236236
assert wheel == dist / out
237237

238238
virtualenv.install(wheel)
239-
if sys.version_info >= (3, 8):
240-
license = virtualenv.execute(
241-
"from importlib.metadata import metadata; print(metadata('dynamic')['License'])"
242-
)
243-
assert license == "MIT License"
244-
245-
with wheel.open("rb") as f:
246-
p = zipfile.Path(f)
247-
file_names = {x.name for x in p.iterdir()}
248-
dynamic_pkg = {x.name for x in p.joinpath("dynamic").iterdir()}
249-
250-
filtered_pkg = {x for x in dynamic_pkg if not x.startswith("_module")}
251-
252-
assert len(filtered_pkg) == len(dynamic_pkg) - 1
253-
assert {"dynamic-0.0.2.dist-info", "dynamic"} == file_names
254-
assert {
255-
"__init__.py",
256-
} == filtered_pkg
239+
license = virtualenv.execute(
240+
"from importlib.metadata import metadata; print(metadata('dynamic')['License'])"
241+
)
242+
assert license == "MIT License"
243+
244+
with wheel.open("rb") as f:
245+
p = zipfile.Path(f)
246+
file_names = {x.name for x in p.iterdir()}
247+
dynamic_pkg = {x.name for x in p.joinpath("dynamic").iterdir()}
248+
249+
filtered_pkg = {x for x in dynamic_pkg if not x.startswith("_module")}
250+
251+
assert len(filtered_pkg) == len(dynamic_pkg) - 1
252+
assert {"dynamic-0.0.2.dist-info", "dynamic"} == file_names
253+
assert {
254+
"__init__.py",
255+
} == filtered_pkg
257256

258257
version = virtualenv.execute("from dynamic import square; print(square(2))")
259258
assert version == "4.0"

tests/test_fortran.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,17 @@ def test_pep517_wheel(tmp_path, monkeypatch, virtualenv):
5050
assert wheel == dist / out
5151
print(wheel)
5252

53-
if sys.version_info >= (3, 8):
54-
with wheel.open("rb") as f:
55-
p = zipfile.Path(f)
56-
file_names = [p.name for p in p.iterdir()]
53+
with wheel.open("rb") as f:
54+
p = zipfile.Path(f)
55+
file_names = [p.name for p in p.iterdir()]
5756

58-
assert len(file_names) == 2
59-
assert "fibby-0.0.1.dist-info" in file_names
60-
file_names.remove("fibby-0.0.1.dist-info")
61-
(so_file,) = file_names
57+
assert len(file_names) == 2
58+
assert "fibby-0.0.1.dist-info" in file_names
59+
file_names.remove("fibby-0.0.1.dist-info")
60+
(so_file,) = file_names
6261

63-
assert so_file.startswith("fibby")
64-
print("SOFILE:", so_file)
62+
assert so_file.startswith("fibby")
63+
print("SOFILE:", so_file)
6564

6665
virtualenv.install(wheel)
6766

tests/test_pyproject_abi3.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,29 @@ def test_abi3_wheel(tmp_path, monkeypatch, virtualenv):
4040
else:
4141
assert "-cp37-abi3-" not in out
4242

43-
if sys.version_info >= (3, 8):
44-
with wheel.open("rb") as f:
45-
p = zipfile.Path(f)
46-
file_names = [p.name for p in p.iterdir()]
43+
with wheel.open("rb") as f:
44+
p = zipfile.Path(f)
45+
file_names = [p.name for p in p.iterdir()]
4746

48-
assert len(file_names) == 2
49-
assert "abi3_example-0.0.1.dist-info" in file_names
50-
file_names.remove("abi3_example-0.0.1.dist-info")
51-
(so_file,) = file_names
47+
assert len(file_names) == 2
48+
assert "abi3_example-0.0.1.dist-info" in file_names
49+
file_names.remove("abi3_example-0.0.1.dist-info")
50+
(so_file,) = file_names
5251

53-
if sysconfig.get_platform().startswith("win"):
54-
if sys.implementation.name == "cpython":
55-
assert so_file == "abi3_example.pyd"
56-
else:
57-
assert so_file.endswith(".pyd")
58-
elif sys.platform.startswith("cygwin"):
59-
if abi3:
60-
assert so_file == "abi3_example.abi3.dll"
61-
else:
62-
assert so_file != "abi3_example.abi3.dll"
63-
elif abi3:
64-
assert so_file == "abi3_example.abi3.so"
52+
if sysconfig.get_platform().startswith("win"):
53+
if sys.implementation.name == "cpython":
54+
assert so_file == "abi3_example.pyd"
6555
else:
66-
assert so_file != "abi3_example.abi3.so"
56+
assert so_file.endswith(".pyd")
57+
elif sys.platform.startswith("cygwin"):
58+
if abi3:
59+
assert so_file == "abi3_example.abi3.dll"
60+
else:
61+
assert so_file != "abi3_example.abi3.dll"
62+
elif abi3:
63+
assert so_file == "abi3_example.abi3.so"
64+
else:
65+
assert so_file != "abi3_example.abi3.so"
6766

6867
virtualenv.install(wheel)
6968

tests/test_pyproject_extra_dirs.py

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,32 @@ def test_pep517_wheel_extra_dirs(monkeypatch):
2727
(wheel,) = dist.glob("cmake_dirs-0.0.1-*.whl")
2828
assert wheel == dist / out
2929

30-
if sys.version_info >= (3, 8):
31-
with wheel.open("rb") as f:
32-
p = zipfile.Path(f)
33-
file_names = {p.name for p in p.iterdir()}
34-
data_dir = {p.name for p in p.joinpath("cmake_dirs-0.0.1.data").iterdir()}
35-
package = {p.name for p in p.joinpath("cmake_dirs").iterdir()}
36-
data = {p.name for p in p.joinpath("cmake_dirs-0.0.1.data/data").iterdir()}
37-
headers = {
38-
p.name for p in p.joinpath("cmake_dirs-0.0.1.data/headers").iterdir()
39-
}
40-
scripts = {
41-
p.name for p in p.joinpath("cmake_dirs-0.0.1.data/scripts").iterdir()
42-
}
30+
with wheel.open("rb") as f:
31+
p = zipfile.Path(f)
32+
file_names = {p.name for p in p.iterdir()}
33+
data_dir = {p.name for p in p.joinpath("cmake_dirs-0.0.1.data").iterdir()}
34+
package = {p.name for p in p.joinpath("cmake_dirs").iterdir()}
35+
data = {p.name for p in p.joinpath("cmake_dirs-0.0.1.data/data").iterdir()}
36+
headers = {
37+
p.name for p in p.joinpath("cmake_dirs-0.0.1.data/headers").iterdir()
38+
}
39+
scripts = {
40+
p.name for p in p.joinpath("cmake_dirs-0.0.1.data/scripts").iterdir()
41+
}
4342

44-
assert {
45-
"cmake_dirs-0.0.1.dist-info",
46-
"cmake_dirs-0.0.1.data",
47-
"cmake_dirs",
48-
"random_file.py",
49-
} == file_names
43+
assert {
44+
"cmake_dirs-0.0.1.dist-info",
45+
"cmake_dirs-0.0.1.data",
46+
"cmake_dirs",
47+
"random_file.py",
48+
} == file_names
5049

51-
assert data_dir == {"data", "headers", "scripts"}
50+
assert data_dir == {"data", "headers", "scripts"}
5251

53-
assert package == {"main.py"}
54-
assert data == {"in_data.txt"}
55-
assert headers == {"in_headers.h"}
56-
assert scripts == {"in_scripts.py"}
52+
assert package == {"main.py"}
53+
assert data == {"in_data.txt"}
54+
assert headers == {"in_headers.h"}
55+
assert scripts == {"in_scripts.py"}
5756

5857

5958
@pytest.mark.usefixtures("package_filepath_pure")

tests/test_pyproject_pep517.py

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -198,31 +198,30 @@ def test_pep517_wheel(virtualenv):
198198
(wheel,) = dist.glob("cmake_example-0.0.1-*.whl")
199199
assert wheel == dist / out
200200

201-
if sys.version_info >= (3, 8):
202-
with wheel.open("rb") as f:
203-
p = zipfile.Path(f)
204-
file_names = [p.name for p in p.iterdir()]
205-
metadata = p.joinpath("cmake_example-0.0.1.dist-info/METADATA").read_text()
206-
entry_points = p.joinpath(
207-
"cmake_example-0.0.1.dist-info/entry_points.txt"
208-
).read_text()
209-
assert p.joinpath("cmake_example-0.0.1.dist-info/licenses/LICENSE").exists()
210-
211-
assert len(file_names) == 2
212-
assert "cmake_example-0.0.1.dist-info" in file_names
213-
file_names.remove("cmake_example-0.0.1.dist-info")
214-
(so_file,) = file_names
215-
216-
assert so_file.startswith("cmake_example")
217-
print("SOFILE:", so_file)
218-
219-
print(entry_points == ENTRYPOINTS)
220-
assert 'Requires-Dist: pytest>=6.0; extra == "test"' in metadata
221-
assert "Metadata-Version: 2.1" in metadata
222-
assert "Name: CMake.Example" in metadata
223-
assert "Version: 0.0.1" in metadata
224-
assert "Requires-Python: >=3.7" in metadata
225-
assert "Provides-Extra: test" in metadata
201+
with wheel.open("rb") as f:
202+
p = zipfile.Path(f)
203+
file_names = [p.name for p in p.iterdir()]
204+
metadata = p.joinpath("cmake_example-0.0.1.dist-info/METADATA").read_text()
205+
entry_points = p.joinpath(
206+
"cmake_example-0.0.1.dist-info/entry_points.txt"
207+
).read_text()
208+
assert p.joinpath("cmake_example-0.0.1.dist-info/licenses/LICENSE").exists()
209+
210+
assert len(file_names) == 2
211+
assert "cmake_example-0.0.1.dist-info" in file_names
212+
file_names.remove("cmake_example-0.0.1.dist-info")
213+
(so_file,) = file_names
214+
215+
assert so_file.startswith("cmake_example")
216+
print("SOFILE:", so_file)
217+
218+
print(entry_points == ENTRYPOINTS)
219+
assert 'Requires-Dist: pytest>=6.0; extra == "test"' in metadata
220+
assert "Metadata-Version: 2.1" in metadata
221+
assert "Name: CMake.Example" in metadata
222+
assert "Version: 0.0.1" in metadata
223+
assert "Requires-Python: >=3.7" in metadata
224+
assert "Provides-Extra: test" in metadata
226225

227226
virtualenv.install(wheel)
228227

@@ -246,39 +245,38 @@ def test_pep517_wheel_source_dir(virtualenv):
246245
(wheel,) = dist.glob("cmake_example-0.0.1-*.whl")
247246
assert wheel == dist / out
248247

249-
if sys.version_info >= (3, 8):
250-
with wheel.open("rb") as f:
251-
p = zipfile.Path(f)
252-
file_names = [p.name for p in p.iterdir()]
253-
metadata = p.joinpath("cmake_example-0.0.1.dist-info/METADATA").read_text()
254-
wheel_metadata = p.joinpath(
255-
"cmake_example-0.0.1.dist-info/WHEEL"
256-
).read_text()
257-
entry_points = p.joinpath(
258-
"cmake_example-0.0.1.dist-info/entry_points.txt"
259-
).read_text()
260-
assert p.joinpath("cmake_example-0.0.1.dist-info/licenses/LICENSE").exists()
261-
262-
assert len(file_names) == 2
263-
assert "cmake_example-0.0.1.dist-info" in file_names
264-
file_names.remove("cmake_example-0.0.1.dist-info")
265-
(so_file,) = file_names
266-
267-
assert so_file.startswith("cmake_example")
268-
print("SOFILE:", so_file)
269-
270-
print(entry_points == ENTRYPOINTS)
271-
assert 'Requires-Dist: pytest>=6.0; extra == "test"' in metadata
272-
assert "Metadata-Version: 2.1" in metadata
273-
assert "Name: CMake.Example" in metadata
274-
assert "Version: 0.0.1" in metadata
275-
assert "Requires-Python: >=3.7" in metadata
276-
assert "Provides-Extra: test" in metadata
277-
278-
assert "Build: 1foo" in wheel_metadata
279-
assert "Wheel-Version: 1.0" in wheel_metadata
280-
assert "Generator: scikit-build" in wheel_metadata
281-
assert "Root-Is-Purelib: false" in wheel_metadata
248+
with wheel.open("rb") as f:
249+
p = zipfile.Path(f)
250+
file_names = [p.name for p in p.iterdir()]
251+
metadata = p.joinpath("cmake_example-0.0.1.dist-info/METADATA").read_text()
252+
wheel_metadata = p.joinpath(
253+
"cmake_example-0.0.1.dist-info/WHEEL"
254+
).read_text()
255+
entry_points = p.joinpath(
256+
"cmake_example-0.0.1.dist-info/entry_points.txt"
257+
).read_text()
258+
assert p.joinpath("cmake_example-0.0.1.dist-info/licenses/LICENSE").exists()
259+
260+
assert len(file_names) == 2
261+
assert "cmake_example-0.0.1.dist-info" in file_names
262+
file_names.remove("cmake_example-0.0.1.dist-info")
263+
(so_file,) = file_names
264+
265+
assert so_file.startswith("cmake_example")
266+
print("SOFILE:", so_file)
267+
268+
print(entry_points == ENTRYPOINTS)
269+
assert 'Requires-Dist: pytest>=6.0; extra == "test"' in metadata
270+
assert "Metadata-Version: 2.1" in metadata
271+
assert "Name: CMake.Example" in metadata
272+
assert "Version: 0.0.1" in metadata
273+
assert "Requires-Python: >=3.7" in metadata
274+
assert "Provides-Extra: test" in metadata
275+
276+
assert "Build: 1foo" in wheel_metadata
277+
assert "Wheel-Version: 1.0" in wheel_metadata
278+
assert "Generator: scikit-build" in wheel_metadata
279+
assert "Root-Is-Purelib: false" in wheel_metadata
282280

283281
virtualenv.install(wheel)
284282

0 commit comments

Comments
 (0)