Skip to content

Commit

Permalink
ENH: drop importlib_resources dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Filipe Laíns <[email protected]>
  • Loading branch information
FFY00 committed Dec 28, 2022
1 parent 7b47bc1 commit 8a13f8d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
8 changes: 2 additions & 6 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
else:
import tomllib

if sys.version_info >= (3, 10):
import importlib.resources as importlib_resources
else:
import importlib_resources

import mesonpy._compat
import mesonpy._elf
Expand All @@ -56,7 +52,7 @@

from mesonpy._compat import (
Collection, Iterable, Iterator, Literal, Mapping, ParamSpec, Path,
cached_property, typing_get_args
cached_property, read_binary, typing_get_args
)


Expand Down Expand Up @@ -616,7 +612,7 @@ def build_editable(self, directory: Path, verbose: bool = False) -> pathlib.Path
''').strip().encode()
whl.writestr(
f'{hook_module_name}.py',
(importlib_resources.files('mesonpy') / '_editable.py').read_bytes() + hook_install_code,
read_binary('mesonpy', '_editable.py') + hook_install_code,
)
# install .pth file
whl.writestr(
Expand Down
9 changes: 9 additions & 0 deletions mesonpy/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-FileCopyrightText: 2021 Filipe Laíns <[email protected]>

import functools
import importlib.resources
import os
import pathlib
import sys
Expand Down Expand Up @@ -37,6 +38,13 @@
cached_property = lambda x: property(functools.lru_cache(maxsize=None)(x)) # noqa: E731


if sys.version_info >= (3, 9):
def read_binary(package: str, resource: str) -> bytes:
return importlib.resources.files(package).joinpath(resource).read_bytes()
else:
read_binary = importlib.resources.read_binary


Path = Union[str, os.PathLike]


Expand All @@ -52,6 +60,7 @@ def is_relative_to(path: pathlib.Path, other: Union[pathlib.Path, str]) -> bool:
__all__ = [
'cached_property',
'is_relative_to',
'read_binary',
'typing_get_args',
'Collection',
'Iterable',
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ requires = [
'pyproject-metadata>=0.6.1',
'tomli>=1.0.0; python_version<"3.11"',
'typing-extensions>=3.7.4; python_version<"3.10"',
'importlib_resources>=5.0.0; python_version<"3.10"',
]

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

dynamic = [
Expand Down

0 comments on commit 8a13f8d

Please sign in to comment.