aboutsummaryrefslogtreecommitdiffstats
path: root/setup.py
diff options
context:
space:
mode:
authorSascha Peilicke <saschpe@mailbox.org>2014-03-31 17:59:37 +0200
committerSascha Peilicke <saschpe@mailbox.org>2014-04-01 15:19:18 +0200
commitc5492050001768fa861f8d24cd7e8f9b964f5bd8 (patch)
treeff608e3689618337e3c97c648cd0dceb5d333d98 /setup.py
parent476682af2d4a9438026e69b6c1f3500c19f2f200 (diff)
downloadcryptography-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.
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py52
1 files changed, 34 insertions, 18 deletions
diff --git a/setup.py b/setup.py
index ccb1e5f6..c1a6d642 100644
--- a/setup.py
+++ b/setup.py
@@ -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,
}
)