blob: 30146b717316373571a381a0d0b9c2dada153b5c [file] [log] [blame]
Alex Gaynorbfc06bc2013-08-06 19:36:19 -07001# Licensed under the Apache License, Version 2.0 (the "License");
2# you may not use this file except in compliance with the License.
3# You may obtain a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS,
9# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10# implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
Alex Gaynorc37feed2014-03-08 08:32:56 -080013
14from __future__ import absolute_import, division, print_function
15
Alex Gaynorf51f2c12014-01-03 07:33:01 -080016import os
Alex Stapletona39a3192014-03-14 20:03:12 +000017import subprocess
Alex Stapleton707b0082014-04-20 22:24:41 +010018import sys
Alex Stapleton4b610cc2014-03-22 08:49:35 +000019from distutils.command.build import build
Alex Stapletona39a3192014-03-14 20:03:12 +000020
21import pkg_resources
Alex Gaynor9a00f052014-01-02 13:09:34 -080022
Paul Kehrerafc1ccd2014-03-19 11:49:32 -040023from setuptools import find_packages, setup
Sascha Peilickec5492052014-03-31 17:59:37 +020024from setuptools.command.install import install
Alex Gaynoracac6a62014-03-04 15:24:03 -080025from setuptools.command.test import test
Donald Stufft446a4572013-08-11 17:38:13 -040026
Paul Kehrerafc1ccd2014-03-19 11:49:32 -040027
Alex Gaynor7630d6c2014-01-03 07:34:43 -080028base_dir = os.path.dirname(__file__)
29
Donald Stufft5f12a1b2013-08-11 16:37:43 -040030about = {}
Alex Gaynor7630d6c2014-01-03 07:34:43 -080031with open(os.path.join(base_dir, "cryptography", "__about__.py")) as f:
32 exec(f.read(), about)
Donald Stufft5f12a1b2013-08-11 16:37:43 -040033
34
Terry Chiada5dca82014-07-27 12:27:52 +080035SETUPTOOLS_DEPENDENCY = "setuptools"
Paul Kehrer7fcaa372014-01-10 23:39:58 -060036CFFI_DEPENDENCY = "cffi>=0.8"
Paul Kehrerc0242552013-09-10 18:54:13 -050037SIX_DEPENDENCY = "six>=1.4.1"
Alex Stapletona39a3192014-03-14 20:03:12 +000038VECTORS_DEPENDENCY = "cryptography_vectors=={0}".format(about['__version__'])
Donald Stufft5f12a1b2013-08-11 16:37:43 -040039
Alex Gaynor91f119e2014-01-02 13:12:59 -080040requirements = [
Donald Stufft5f12a1b2013-08-11 16:37:43 -040041 CFFI_DEPENDENCY,
Terry Chiada5dca82014-07-27 12:27:52 +080042 SIX_DEPENDENCY,
43 SETUPTOOLS_DEPENDENCY
Donald Stufft5f12a1b2013-08-11 16:37:43 -040044]
45
Paul Kehrer7ad18bc2014-03-26 13:13:38 -060046# If you add a new dep here you probably need to add it in the tox.ini as well
koobsff0dd1e2014-02-24 21:55:04 +110047test_requirements = [
48 "pytest",
Paul Kehrerd3e3df92014-04-30 11:13:17 -050049 "pyasn1",
koobsff0dd1e2014-02-24 21:55:04 +110050 "pretend",
Alex Stapleton0bd20e22014-03-14 19:58:07 +000051 "iso8601",
koobsff0dd1e2014-02-24 21:55:04 +110052]
53
Alex Stapletona39a3192014-03-14 20:03:12 +000054# If there's no vectors locally that probably means we are in a tarball and
55# need to go and get the matching vectors package from PyPi
56if not os.path.exists(os.path.join(base_dir, "vectors/setup.py")):
57 test_requirements.append(VECTORS_DEPENDENCY)
58
Alex Gaynor9a00f052014-01-02 13:09:34 -080059
Sascha Peilickec5492052014-03-31 17:59:37 +020060def get_ext_modules():
61 from cryptography.hazmat.bindings.commoncrypto.binding import (
62 Binding as CommonCryptoBinding
63 )
64 from cryptography.hazmat.bindings.openssl.binding import (
65 Binding as OpenSSLBinding
66 )
67 from cryptography.hazmat.primitives import constant_time, padding
68
69 ext_modules = [
70 OpenSSLBinding().ffi.verifier.get_extension(),
71 constant_time._ffi.verifier.get_extension(),
72 padding._ffi.verifier.get_extension()
73 ]
74 if CommonCryptoBinding.is_available():
75 ext_modules.append(CommonCryptoBinding().ffi.verifier.get_extension())
76 return ext_modules
77
78
Paul Kehrer5b6ce2a2014-02-24 20:16:10 -060079class CFFIBuild(build):
Alex Gaynor49697512014-01-03 15:08:45 -080080 """
81 This class exists, instead of just providing ``ext_modules=[...]`` directly
82 in ``setup()`` because importing cryptography requires we have several
83 packages installed first.
84
85 By doing the imports here we ensure that packages listed in
86 ``setup_requires`` are already installed.
87 """
88
Alex Gaynor9a00f052014-01-02 13:09:34 -080089 def finalize_options(self):
Sascha Peilickec5492052014-03-31 17:59:37 +020090 self.distribution.ext_modules = get_ext_modules()
Alex Gaynor9a00f052014-01-02 13:09:34 -080091 build.finalize_options(self)
92
koobs92a4cdb2014-02-24 22:13:17 +110093
Sascha Peilickec5492052014-03-31 17:59:37 +020094class CFFIInstall(install):
95 """
96 As a consequence of CFFIBuild and it's late addition of ext_modules, we
97 need the equivalent for the ``install`` command to install into platlib
98 install-dir rather than purelib.
99 """
100
101 def finalize_options(self):
102 self.distribution.ext_modules = get_ext_modules()
103 install.finalize_options(self)
104
105
Alex Gaynoracac6a62014-03-04 15:24:03 -0800106class PyTest(test):
koobsff0dd1e2014-02-24 21:55:04 +1100107 def finalize_options(self):
Alex Gaynor6858cd42014-03-04 15:33:13 -0800108 test.finalize_options(self)
koobsff0dd1e2014-02-24 21:55:04 +1100109 self.test_args = []
110 self.test_suite = True
koobs06671802014-02-24 22:33:07 +1100111
Alex Stapletona39a3192014-03-14 20:03:12 +0000112 # This means there's a vectors/ folder with the package in here.
113 # cd into it, install the vectors package and then refresh sys.path
114 if VECTORS_DEPENDENCY not in test_requirements:
Alex Gaynord9f9b752014-07-11 10:18:24 -0700115 subprocess.check_call(
116 [sys.executable, "setup.py", "install"], cwd="vectors"
117 )
Alex Stapletona39a3192014-03-14 20:03:12 +0000118 pkg_resources.get_distribution("cryptography_vectors").activate()
119
koobsff0dd1e2014-02-24 21:55:04 +1100120 def run_tests(self):
koobs92a4cdb2014-02-24 22:13:17 +1100121 # Import here because in module scope the eggs are not loaded.
koobsff0dd1e2014-02-24 21:55:04 +1100122 import pytest
123 errno = pytest.main(self.test_args)
124 sys.exit(errno)
125
Alex Gaynor9a00f052014-01-02 13:09:34 -0800126
Alex Gaynor7630d6c2014-01-03 07:34:43 -0800127with open(os.path.join(base_dir, "README.rst")) as f:
Alex Gaynorf51f2c12014-01-03 07:33:01 -0800128 long_description = f.read()
129
130
Alex Gaynorc62e91f2013-08-06 19:25:52 -0700131setup(
Donald Stufft5f12a1b2013-08-11 16:37:43 -0400132 name=about["__title__"],
133 version=about["__version__"],
134
135 description=about["__summary__"],
Alex Gaynorf51f2c12014-01-03 07:33:01 -0800136 long_description=long_description,
Donald Stufft5f12a1b2013-08-11 16:37:43 -0400137 license=about["__license__"],
138 url=about["__uri__"],
139
140 author=about["__author__"],
141 author_email=about["__email__"],
142
Christian Heimesf83ed1d2013-08-10 23:28:29 +0200143 classifiers=[
Christian Heimesf83ed1d2013-08-10 23:28:29 +0200144 "Intended Audience :: Developers",
145 "License :: OSI Approved :: Apache Software License",
146 "Natural Language :: English",
147 "Operating System :: MacOS :: MacOS X",
148 "Operating System :: POSIX",
149 "Operating System :: POSIX :: BSD",
150 "Operating System :: POSIX :: Linux",
151 "Operating System :: Microsoft :: Windows",
Christian Heimesf83ed1d2013-08-10 23:28:29 +0200152 "Programming Language :: Python",
153 "Programming Language :: Python :: 2",
154 "Programming Language :: Python :: 2.6",
155 "Programming Language :: Python :: 2.7",
156 "Programming Language :: Python :: 3",
157 "Programming Language :: Python :: 3.2",
158 "Programming Language :: Python :: 3.3",
Alex Gaynor7f8b2772014-03-17 10:22:41 -0700159 "Programming Language :: Python :: 3.4",
Christian Heimesf83ed1d2013-08-10 23:28:29 +0200160 "Programming Language :: Python :: Implementation :: CPython",
161 "Programming Language :: Python :: Implementation :: PyPy",
162 "Topic :: Security :: Cryptography",
163 ],
Donald Stufft5f12a1b2013-08-11 16:37:43 -0400164
Donald Stufft9ebb8ff2013-08-11 17:05:03 -0400165 packages=find_packages(exclude=["tests", "tests.*"]),
166
Alex Gaynor91f119e2014-01-02 13:12:59 -0800167 install_requires=requirements,
168 setup_requires=requirements,
koobsff0dd1e2014-02-24 21:55:04 +1100169 tests_require=test_requirements,
Donald Stufft5f12a1b2013-08-11 16:37:43 -0400170
171 # for cffi
172 zip_safe=False,
Alex Gaynor9a00f052014-01-02 13:09:34 -0800173 ext_package="cryptography",
174 cmdclass={
Paul Kehrer5b6ce2a2014-02-24 20:16:10 -0600175 "build": CFFIBuild,
Sascha Peilickec5492052014-03-31 17:59:37 +0200176 "install": CFFIInstall,
koobsff0dd1e2014-02-24 21:55:04 +1100177 "test": PyTest,
Terry Chiada5dca82014-07-27 12:27:52 +0800178 },
179
180 entry_points={
181 "cryptography.hazmat.backends": [
182 "commoncrypto = cryptography.hazmat.backends.commoncrypto:backend",
183 "openssl = cryptography.hazmat.backends.openssl:backend"
184 ],
185
186 "cryptography.hazmat.is_backend_available": [
187 "commoncrypto = cryptography.hazmat.bindings.commoncrypto."
188 "binding:Binding.is_available"
189 ]
Alex Gaynor9a00f052014-01-02 13:09:34 -0800190 }
Alex Gaynorc62e91f2013-08-06 19:25:52 -0700191)