diff --git a/docs/overview.rst b/docs/overview.rst index e4c9e30b..b291f636 100644 --- a/docs/overview.rst +++ b/docs/overview.rst @@ -177,6 +177,8 @@ different ABIs: The resulting filename is e.g. ``simple.hpy0.so``. + require backport ``importlib_resources>=5.0`` on ``CPython<3.10``. + HPy Hybrid ABI The HPy Hybrid ABI is essentially the same as the Universal ABI, with @@ -324,7 +326,7 @@ of features. As on April 2023, the following milestones have been reached: CPython. - it is possible to load HPy Universal extensions on CPython, thanks to the - ``hpy.universal`` package. + ``hpy.universal`` package (require ``importlib_resources>=5.0`` on ``CPython<3.10``). - it is possible to load HPy Universal extensions on PyPy (using the PyPy `hpy branch `_). diff --git a/hpy/devel/__init__.py b/hpy/devel/__init__.py index 3b7f6e6d..8472bb8e 100644 --- a/hpy/devel/__init__.py +++ b/hpy/devel/__init__.py @@ -201,18 +201,37 @@ def handle_hpy_ext_modules(dist, attr, hpy_ext_modules): _HPY_UNIVERSAL_MODULE_STUB_TEMPLATE = """ # DO NOT EDIT THIS FILE! # This file is automatically generated by hpy - def __bootstrap__(): - - from sys import modules - from os import environ - from pkg_resources import resource_filename + from sys import modules, version_info + from os import path, environ from hpy.universal import _load_bootstrap - ext_filepath = resource_filename(__name__, {ext_file!r}) - m = _load_bootstrap({module_name!r}, __name__, __package__, ext_filepath, - __loader__, __spec__, environ) + + ext_name = {ext_file!r} + module_name = {module_name!r} + + if version_info < (3, 10): + import importlib_resources as resources + else: + from importlib import resources + + if not __package__: + # directly called with python -m + ext_filepath = path.join(path.dirname(__file__), ext_name) + else: + ext_filepath = resources.files(__package__).joinpath(ext_name) + + m = _load_bootstrap( + module_name, + __name__, + __package__, + str(ext_filepath), + __loader__, + __spec__, + environ, + ) modules[__name__] = m + __bootstrap__() """ diff --git a/setup.py b/setup.py index 8dd6962d..9a3ce045 100644 --- a/setup.py +++ b/setup.py @@ -264,6 +264,9 @@ def build_libraries(self, libraries): cmdclass={"build_clib": build_clib_hpy}, use_scm_version=get_scm_config, setup_requires=['setuptools_scm'], - install_requires=['setuptools>=64.0'], + install_requires=[ + 'setuptools>=64.0', + 'importlib_resources>=5.0; python_version<"3.10"', + ], python_requires='>=3.8', )