Skip to content

Commit 8a13f8d

Browse files
committed
ENH: drop importlib_resources dependency
Signed-off-by: Filipe Laíns <[email protected]>
1 parent 7b47bc1 commit 8a13f8d

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

mesonpy/__init__.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@
4242
else:
4343
import tomllib
4444

45-
if sys.version_info >= (3, 10):
46-
import importlib.resources as importlib_resources
47-
else:
48-
import importlib_resources
4945

5046
import mesonpy._compat
5147
import mesonpy._elf
@@ -56,7 +52,7 @@
5652

5753
from mesonpy._compat import (
5854
Collection, Iterable, Iterator, Literal, Mapping, ParamSpec, Path,
59-
cached_property, typing_get_args
55+
cached_property, read_binary, typing_get_args
6056
)
6157

6258

@@ -616,7 +612,7 @@ def build_editable(self, directory: Path, verbose: bool = False) -> pathlib.Path
616612
''').strip().encode()
617613
whl.writestr(
618614
f'{hook_module_name}.py',
619-
(importlib_resources.files('mesonpy') / '_editable.py').read_bytes() + hook_install_code,
615+
read_binary('mesonpy', '_editable.py') + hook_install_code,
620616
)
621617
# install .pth file
622618
whl.writestr(

mesonpy/_compat.py

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-FileCopyrightText: 2021 Filipe Laíns <[email protected]>
44

55
import functools
6+
import importlib.resources
67
import os
78
import pathlib
89
import sys
@@ -37,6 +38,13 @@
3738
cached_property = lambda x: property(functools.lru_cache(maxsize=None)(x)) # noqa: E731
3839

3940

41+
if sys.version_info >= (3, 9):
42+
def read_binary(package: str, resource: str) -> bytes:
43+
return importlib.resources.files(package).joinpath(resource).read_bytes()
44+
else:
45+
read_binary = importlib.resources.read_binary
46+
47+
4048
Path = Union[str, os.PathLike]
4149

4250

@@ -52,6 +60,7 @@ def is_relative_to(path: pathlib.Path, other: Union[pathlib.Path, str]) -> bool:
5260
__all__ = [
5361
'cached_property',
5462
'is_relative_to',
63+
'read_binary',
5564
'typing_get_args',
5665
'Collection',
5766
'Iterable',

pyproject.toml

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ requires = [
66
'pyproject-metadata>=0.6.1',
77
'tomli>=1.0.0; python_version<"3.11"',
88
'typing-extensions>=3.7.4; python_version<"3.10"',
9-
'importlib_resources>=5.0.0; python_version<"3.10"',
109
]
1110

1211
[project]
@@ -30,7 +29,6 @@ dependencies = [
3029
'pyproject-metadata>=0.6.1', # not a hard dependency, only needed for projects that use PEP 621 metadata
3130
'tomli>=1.0.0; python_version<"3.11"',
3231
'typing-extensions>=3.7.4; python_version<"3.10"',
33-
'importlib_resources>=5.0.0; python_version<"3.10"',
3432
]
3533

3634
dynamic = [

0 commit comments

Comments
 (0)