blob: 7f7ba9ef5f7940105bc441702af1a17ded9cb9f6 [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
koobs23690dd2014-02-24 22:26:23 +110017import sys
Alex Gaynor9a00f052014-01-02 13:09:34 -080018from distutils.command.build import build
19
Donald Stufft9ebb8ff2013-08-11 17:05:03 -040020from setuptools import setup, find_packages
Alex Gaynoracac6a62014-03-04 15:24:03 -080021from setuptools.command.test import test
Donald Stufft446a4572013-08-11 17:38:13 -040022
Alex Gaynor7630d6c2014-01-03 07:34:43 -080023base_dir = os.path.dirname(__file__)
24
Donald Stufft5f12a1b2013-08-11 16:37:43 -040025about = {}
Alex Gaynor7630d6c2014-01-03 07:34:43 -080026with open(os.path.join(base_dir, "cryptography", "__about__.py")) as f:
27 exec(f.read(), about)
Donald Stufft5f12a1b2013-08-11 16:37:43 -040028
29
Paul Kehrer7fcaa372014-01-10 23:39:58 -060030CFFI_DEPENDENCY = "cffi>=0.8"
Paul Kehrerc0242552013-09-10 18:54:13 -050031SIX_DEPENDENCY = "six>=1.4.1"
Donald Stufft5f12a1b2013-08-11 16:37:43 -040032
Alex Gaynor91f119e2014-01-02 13:12:59 -080033requirements = [
Donald Stufft5f12a1b2013-08-11 16:37:43 -040034 CFFI_DEPENDENCY,
Paul Kehrerc0242552013-09-10 18:54:13 -050035 SIX_DEPENDENCY
Donald Stufft5f12a1b2013-08-11 16:37:43 -040036]
37
koobsff0dd1e2014-02-24 21:55:04 +110038test_requirements = [
39 "pytest",
40 "pretend",
41 "iso8601"
42]
43
Alex Gaynor9a00f052014-01-02 13:09:34 -080044
Paul Kehrer5b6ce2a2014-02-24 20:16:10 -060045class CFFIBuild(build):
Alex Gaynor49697512014-01-03 15:08:45 -080046 """
47 This class exists, instead of just providing ``ext_modules=[...]`` directly
48 in ``setup()`` because importing cryptography requires we have several
49 packages installed first.
50
51 By doing the imports here we ensure that packages listed in
52 ``setup_requires`` are already installed.
53 """
54
Alex Gaynor9a00f052014-01-02 13:09:34 -080055 def finalize_options(self):
Alex Gaynordefc7f02014-01-19 23:44:31 -060056 from cryptography.hazmat.bindings.commoncrypto.binding import (
57 Binding as CommonCryptoBinding
58 )
59 from cryptography.hazmat.bindings.openssl.binding import (
60 Binding as OpenSSLBinding
61 )
Alex Gaynor9a00f052014-01-02 13:09:34 -080062 from cryptography.hazmat.primitives import constant_time, padding
63
64 self.distribution.ext_modules = [
Alex Gaynordefc7f02014-01-19 23:44:31 -060065 OpenSSLBinding().ffi.verifier.get_extension(),
Alex Gaynor9a00f052014-01-02 13:09:34 -080066 constant_time._ffi.verifier.get_extension(),
67 padding._ffi.verifier.get_extension()
68 ]
Alex Gaynordefc7f02014-01-19 23:44:31 -060069 if CommonCryptoBinding.is_available():
70 self.distribution.ext_modules.append(
71 CommonCryptoBinding().ffi.verifier.get_extension()
72 )
Alex Gaynor50f233e2014-01-06 11:10:40 -080073
Alex Gaynor9a00f052014-01-02 13:09:34 -080074 build.finalize_options(self)
75
koobs92a4cdb2014-02-24 22:13:17 +110076
Alex Gaynoracac6a62014-03-04 15:24:03 -080077class PyTest(test):
koobsff0dd1e2014-02-24 21:55:04 +110078 def finalize_options(self):
Alex Gaynor6858cd42014-03-04 15:33:13 -080079 test.finalize_options(self)
koobsff0dd1e2014-02-24 21:55:04 +110080 self.test_args = []
81 self.test_suite = True
koobs06671802014-02-24 22:33:07 +110082
koobsff0dd1e2014-02-24 21:55:04 +110083 def run_tests(self):
koobs92a4cdb2014-02-24 22:13:17 +110084 # Import here because in module scope the eggs are not loaded.
koobsff0dd1e2014-02-24 21:55:04 +110085 import pytest
86 errno = pytest.main(self.test_args)
87 sys.exit(errno)
88
Alex Gaynor9a00f052014-01-02 13:09:34 -080089
Alex Gaynor7630d6c2014-01-03 07:34:43 -080090with open(os.path.join(base_dir, "README.rst")) as f:
Alex Gaynorf51f2c12014-01-03 07:33:01 -080091 long_description = f.read()
92
93
Alex Gaynorc62e91f2013-08-06 19:25:52 -070094setup(
Donald Stufft5f12a1b2013-08-11 16:37:43 -040095 name=about["__title__"],
96 version=about["__version__"],
97
98 description=about["__summary__"],
Alex Gaynorf51f2c12014-01-03 07:33:01 -080099 long_description=long_description,
Donald Stufft5f12a1b2013-08-11 16:37:43 -0400100 license=about["__license__"],
101 url=about["__uri__"],
102
103 author=about["__author__"],
104 author_email=about["__email__"],
105
Christian Heimesf83ed1d2013-08-10 23:28:29 +0200106 classifiers=[
Christian Heimesf83ed1d2013-08-10 23:28:29 +0200107 "Intended Audience :: Developers",
108 "License :: OSI Approved :: Apache Software License",
109 "Natural Language :: English",
110 "Operating System :: MacOS :: MacOS X",
111 "Operating System :: POSIX",
112 "Operating System :: POSIX :: BSD",
113 "Operating System :: POSIX :: Linux",
114 "Operating System :: Microsoft :: Windows",
Christian Heimesf83ed1d2013-08-10 23:28:29 +0200115 "Programming Language :: Python",
116 "Programming Language :: Python :: 2",
117 "Programming Language :: Python :: 2.6",
118 "Programming Language :: Python :: 2.7",
119 "Programming Language :: Python :: 3",
120 "Programming Language :: Python :: 3.2",
121 "Programming Language :: Python :: 3.3",
122 "Programming Language :: Python :: Implementation :: CPython",
123 "Programming Language :: Python :: Implementation :: PyPy",
124 "Topic :: Security :: Cryptography",
125 ],
Donald Stufft5f12a1b2013-08-11 16:37:43 -0400126
Donald Stufft9ebb8ff2013-08-11 17:05:03 -0400127 packages=find_packages(exclude=["tests", "tests.*"]),
128
Alex Gaynor91f119e2014-01-02 13:12:59 -0800129 install_requires=requirements,
130 setup_requires=requirements,
koobsff0dd1e2014-02-24 21:55:04 +1100131 tests_require=test_requirements,
Donald Stufft5f12a1b2013-08-11 16:37:43 -0400132
133 # for cffi
134 zip_safe=False,
Alex Gaynor9a00f052014-01-02 13:09:34 -0800135 ext_package="cryptography",
136 cmdclass={
Paul Kehrer5b6ce2a2014-02-24 20:16:10 -0600137 "build": CFFIBuild,
koobsff0dd1e2014-02-24 21:55:04 +1100138 "test": PyTest,
Alex Gaynor9a00f052014-01-02 13:09:34 -0800139 }
Alex Gaynorc62e91f2013-08-06 19:25:52 -0700140)