diff options
author | Sascha Peilicke <saschpe@mailbox.org> | 2014-03-31 17:59:37 +0200 |
---|---|---|
committer | Sascha Peilicke <saschpe@mailbox.org> | 2014-04-01 15:19:18 +0200 |
commit | c5492050001768fa861f8d24cd7e8f9b964f5bd8 (patch) | |
tree | ff608e3689618337e3c97c648cd0dceb5d333d98 | |
parent | 476682af2d4a9438026e69b6c1f3500c19f2f200 (diff) | |
download | cryptography-c5492050001768fa861f8d24cd7e8f9b964f5bd8.tar.gz cryptography-c5492050001768fa861f8d24cd7e8f9b964f5bd8.tar.bz2 cryptography-c5492050001768fa861f8d24cd7e8f9b964f5bd8.zip |
Add custom 'install' command class
CFFIBuild adds ext_modules late in the configuration phase. However,
distutils default 'install' command also parses setup.py and thus misses
that cffi contains several extension modules rather than being pure. As
a consequence, add a CFFIInstall with a proper finalize_options method
and use it.
-rw-r--r-- | setup.py | 52 |
1 files changed, 34 insertions, 18 deletions
@@ -21,6 +21,7 @@ import subprocess import pkg_resources from setuptools import find_packages, setup +from setuptools.command.install import install from setuptools.command.test import test @@ -53,6 +54,25 @@ if not os.path.exists(os.path.join(base_dir, "vectors/setup.py")): test_requirements.append(VECTORS_DEPENDENCY) +def get_ext_modules(): + from cryptography.hazmat.bindings.commoncrypto.binding import ( + Binding as CommonCryptoBinding + ) + from cryptography.hazmat.bindings.openssl.binding import ( + Binding as OpenSSLBinding + ) + from cryptography.hazmat.primitives import constant_time, padding + + ext_modules = [ + OpenSSLBinding().ffi.verifier.get_extension(), + constant_time._ffi.verifier.get_extension(), + padding._ffi.verifier.get_extension() + ] + if CommonCryptoBinding.is_available(): + ext_modules.append(CommonCryptoBinding().ffi.verifier.get_extension()) + return ext_modules + + class CFFIBuild(build): """ This class exists, instead of just providing ``ext_modules=[...]`` directly @@ -64,27 +84,22 @@ class CFFIBuild(build): """ def finalize_options(self): - from cryptography.hazmat.bindings.commoncrypto.binding import ( - Binding as CommonCryptoBinding - ) - from cryptography.hazmat.bindings.openssl.binding import ( - Binding as OpenSSLBinding - ) - from cryptography.hazmat.primitives import constant_time, padding - - self.distribution.ext_modules = [ - OpenSSLBinding().ffi.verifier.get_extension(), - constant_time._ffi.verifier.get_extension(), - padding._ffi.verifier.get_extension() - ] - if CommonCryptoBinding.is_available(): - self.distribution.ext_modules.append( - CommonCryptoBinding().ffi.verifier.get_extension() - ) - + self.distribution.ext_modules = get_ext_modules() build.finalize_options(self) +class CFFIInstall(install): + """ + As a consequence of CFFIBuild and it's late addition of ext_modules, we + need the equivalent for the ``install`` command to install into platlib + install-dir rather than purelib. + """ + + def finalize_options(self): + self.distribution.ext_modules = get_ext_modules() + install.finalize_options(self) + + class PyTest(test): def finalize_options(self): test.finalize_options(self) @@ -154,6 +169,7 @@ setup( ext_package="cryptography", cmdclass={ "build": CFFIBuild, + "install": CFFIInstall, "test": PyTest, } ) |