Skip to content

Commit

Permalink
Override setuptools copy_extensions_to_source() to keep our stubs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ambv committed Sep 21, 2022
1 parent 4606936 commit aabfba0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
20 changes: 20 additions & 0 deletions hpy/devel/__init__.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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_<module_name>"
with "HPyInit_<module_name>.
Expand Down
2 changes: 1 addition & 1 deletion 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"
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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'],
)

0 comments on commit aabfba0

Please sign in to comment.