diff options
author | Armin Rigo <arigo@tunes.org> | 2015-08-01 16:07:28 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2015-08-01 16:07:28 +0200 |
commit | c8d920c34838d7e5eb3f89795b4d0885b9f1c73e (patch) | |
tree | bcce55767adaefa80b5b284fe36a023e2f80968b /cffi/setuptools_ext.py | |
parent | f8ad569ffe3d0924d6ab11196d8828d691992553 (diff) | |
download | cffi-c8d920c34838d7e5eb3f89795b4d0885b9f1c73e.tar.gz |
From https://github.com/pyca/cryptography/pull/2156: add the pre_run()
hook that is called just before writing C code. Limited to
setuptools-based setup.py files.
Diffstat (limited to 'cffi/setuptools_ext.py')
-rw-r--r-- | cffi/setuptools_ext.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/cffi/setuptools_ext.py b/cffi/setuptools_ext.py index 40ff08b..9c6436d 100644 --- a/cffi/setuptools_ext.py +++ b/cffi/setuptools_ext.py @@ -81,10 +81,16 @@ def _add_c_module(dist, ffi, module_name, source, source_extension, kwds): allsources.extend(kwds.pop('sources', [])) ext = Extension(name=module_name, sources=allsources, **kwds) - def make_mod(tmpdir): + def make_mod(tmpdir, pre_run=None): c_file = os.path.join(tmpdir, module_name + source_extension) log.info("generating cffi module %r" % c_file) mkpath(tmpdir) + # a setuptools-only, API-only hook: called with the "ext" and "ffi" + # arguments just before we turn the ffi into C code. To use it, + # subclass the 'distutils.command.build_ext.build_ext' class and + # add a method 'def pre_run(self, ext, ffi)'. + if pre_run is not None: + pre_run(ext, ffi) updated = recompiler.make_c_source(ffi, module_name, source, c_file) if not updated: log.info("already up-to-date") @@ -98,7 +104,8 @@ def _add_c_module(dist, ffi, module_name, source, source_extension, kwds): class build_ext_make_mod(base_class): def run(self): if ext.sources[0] == '$PLACEHOLDER': - ext.sources[0] = make_mod(self.build_temp) + pre_run = getattr(self, 'pre_run', None) + ext.sources[0] = make_mod(self.build_temp, pre_run) base_class.run(self) dist.cmdclass['build_ext'] = build_ext_make_mod # NB. multiple runs here will create multiple 'build_ext_make_mod' |