From aabfba0b879be499d03f358ef37a67ae0f3e899b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Tue, 20 Sep 2022 14:45:23 +0200 Subject: [PATCH] Override setuptools `copy_extensions_to_source()` to keep our stubs This is needed due to setuptools 64.0.0 implementing PEP 660 and circumventing usage of `write_stub_file` in `copy_extensions_to_source` (see: pypa/setuptools#3392) In turn, we require setuptools 64.0.0 or higher. --- hpy/devel/__init__.py | 20 ++++++++++++++++++++ pyproject.toml | 2 +- setup.py | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/hpy/devel/__init__.py b/hpy/devel/__init__.py index 513d13806..64e93c395 100644 --- a/hpy/devel/__init__.py +++ b/hpy/devel/__init__.py @@ -112,6 +112,8 @@ def write_stub(resource, pyfile): if resource.endswith(".hpy.so"): log.info("stub file already created for %s", resource) return + else: + log.info("stub resource didn't match for %s", resource) write_stub.super(resource, pyfile) def build_ext_sanity_check(self, build_ext): @@ -365,6 +367,24 @@ def write_stub(self, output_dir, ext, compile=False): ext_file=ext_file, module_name=module_name) ) + def copy_extensions_to_source(self): + """Override from setuptools 64.0.0 to copy our stub instead of recreating it.""" + build_py = self.get_finalized_command('build_py') + build_lib = build_py.build_lib + for ext in self.extensions: + inplace_file, regular_file = self._get_inplace_equivalent(build_py, ext) + + # Always copy, even if source is older than destination, to ensure + # that the right extensions for the current Python/platform are + # used. + if os.path.exists(regular_file) or not ext.optional: + self.copy_file(regular_file, inplace_file, level=self.verbose) + + if ext._needs_stub: + source_stub = os.path.join(build_lib, *ext._full_name.split('.')) + '.py' + inplace_stub = self._get_equivalent_stub(ext, inplace_file) + self.copy_file(source_stub, inplace_stub, level=self.verbose) + def get_export_symbols(self, ext): """ Override .get_export_symbols to replace "PyInit_" with "HPyInit_. diff --git a/pyproject.toml b/pyproject.toml index 005355914..a3194aec7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,3 @@ [build-system] -requires = [ "setuptools>=40.6.0", "setuptools-scm[toml]>=6.0", "wheel>=0.34.2",] +requires = [ "setuptools>=64.0", "setuptools-scm[toml]>=6.0", "wheel>=0.34.2",] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index cb3ebbc45..0c3f3fece 100644 --- a/setup.py +++ b/setup.py @@ -162,5 +162,5 @@ def get_scm_config(): }, use_scm_version=get_scm_config, setup_requires=['setuptools_scm'], - install_requires=['setuptools>=60.2'], + install_requires=['setuptools>=64.0'], )