Skip to content

Commit

Permalink
Preprocess all extensions at once before compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Oct 19, 2023
1 parent c1a622e commit 2cb5c61
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions setuptools/command/build_ext.py
Expand Up @@ -251,26 +251,30 @@ def get_export_symbols(self, ext):
return ext.export_symbols
return _build_ext.get_export_symbols(self, ext)

def _preprocess_and_build(self, ext):
def _preprocess(self, ext):
if isinstance(ext, PreprocessedExtension):
target = ext.preprocess(self) # may be missing build info
updates = self._update_ext_info(target)
target.__dict__.update(updates)
ext.__dict__.update(updates) # ... for the sake of consistency ...
else:
target = ext
return target

return ext

_build_ext.build_extension(self, target)
def build_extensions(self):
self.extensions[:] = [self._preprocess(ext) for ext in self.extensions]
# ^-- We may have to pre-process all the extensions first, before proceeding
# to the compilation step, since they may generate files that depend
# at at other during compile-time (e.g. headers).
super().build_extensions()

def build_extension(self, ext):
ext._convert_pyx_sources_to_lang()
_compiler = self.compiler
try:
if isinstance(ext, Library):
self.compiler = self.shlib_compiler

self._preprocess_and_build(ext)

_build_ext.build_extension(self, ext)
if ext._needs_stub:
build_lib = self.get_finalized_command('build_py').build_lib
self.write_stub(build_lib, ext)
Expand Down
4 changes: 2 additions & 2 deletions setuptools/extension.py
Expand Up @@ -169,8 +169,8 @@ def preprocess(self, build_ext: BuildExt) -> Extension: # pragma: no cover
If necessary, a temporary directory **name** can be accessed via
``build_ext.build_temp`` (this directory might not have been created yet).
You can also access other attributes like ``build_ext.inplace`` or
``build_ext.editable_mode``.
You can also access other attributes like ``build_ext.parallel``,
``build_ext.inplace`` or ``build_ext.editable_mode``.
"""
raise NotImplementedError # needs to be implemented by the relevant plugin.

Expand Down

0 comments on commit 2cb5c61

Please sign in to comment.