blob: ccb1e5f6cd2ccee9a63782d9b89897e7ce57fef2 [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
Paul Kehrer8443a922014-03-19 13:09:31 -040018from distutils.command.build import build
Alex Stapletona39a3192014-03-14 20:03:12 +000019import subprocess
20
21import pkg_resources
Alex Gaynor9a00f052014-01-02 13:09:34 -080022
Paul Kehrerafc1ccd2014-03-19 11:49:32 -040023from setuptools import find_packages, setup
Alex Gaynoracac6a62014-03-04 15:24:03 -080024from setuptools.command.test import test
Donald Stufft446a4572013-08-11 17:38:13 -040025
Paul Kehrerafc1ccd2014-03-19 11:49:32 -040026
Alex Gaynor7630d6c2014-01-03 07:34:43 -080027base_dir = os.path.dirname(__file__)
28
Donald Stufft5f12a1b2013-08-11 16:37:43 -040029about = {}
Alex Gaynor7630d6c2014-01-03 07:34:43 -080030with open(os.path.join(base_dir, "cryptography", "__about__.py")) as f:
31 exec(f.read(), about)
Donald Stufft5f12a1b2013-08-11 16:37:43 -040032
33
Paul Kehrer7fcaa372014-01-10 23:39:58 -060034CFFI_DEPENDENCY = "cffi>=0.8"
Paul Kehrerc0242552013-09-10 18:54:13 -050035SIX_DEPENDENCY = "six>=1.4.1"
Alex Stapletona39a3192014-03-14 20:03:12 +000036VECTORS_DEPENDENCY = "cryptography_vectors=={0}".format(about['__version__'])
Donald Stufft5f12a1b2013-08-11 16:37:43 -040037
Alex Gaynor91f119e2014-01-02 13:12:59 -080038requirements = [
Donald Stufft5f12a1b2013-08-11 16:37:43 -040039 CFFI_DEPENDENCY,
Paul Kehrerc0242552013-09-10 18:54:13 -050040 SIX_DEPENDENCY
Donald Stufft5f12a1b2013-08-11 16:37:43 -040041]
42
Paul Kehrer7ad18bc2014-03-26 13:13:38 -060043# 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 +110044test_requirements = [
45 "pytest",
46 "pretend",
Alex Stapleton0bd20e22014-03-14 19:58:07 +000047 "iso8601",
koobsff0dd1e2014-02-24 21:55:04 +110048]
49
Alex Stapletona39a3192014-03-14 20:03:12 +000050# If there's no vectors locally that probably means we are in a tarball and
51# need to go and get the matching vectors package from PyPi
52if not os.path.exists(os.path.join(base_dir, "vectors/setup.py")):
53 test_requirements.append(VECTORS_DEPENDENCY)
54
Alex Gaynor9a00f052014-01-02 13:09:34 -080055
Paul Kehrer5b6ce2a2014-02-24 20:16:10 -060056class CFFIBuild(build):
Alex Gaynor49697512014-01-03 15:08:45 -080057 """
58 This class exists, instead of just providing ``ext_modules=[...]`` directly
59 in ``setup()`` because importing cryptography requires we have several
60 packages installed first.
61
62 By doing the imports here we ensure that packages listed in
63 ``setup_requires`` are already installed.
64 """
65
Alex Gaynor9a00f052014-01-02 13:09:34 -080066 def finalize_options(self):
Alex Gaynordefc7f02014-01-19 23:44:31 -060067 from cryptography.hazmat.bindings.commoncrypto.binding import (
68 Binding as CommonCryptoBinding
69 )
70 from cryptography.hazmat.bindings.openssl.binding import (
71 Binding as OpenSSLBinding
72 )
Alex Gaynor9a00f052014-01-02 13:09:34 -080073 from cryptography.hazmat.primitives import constant_time, padding
74
75 self.distribution.ext_modules = [
Alex Gaynordefc7f02014-01-19 23:44:31 -060076 OpenSSLBinding().ffi.verifier.get_extension(),
Alex Gaynor9a00f052014-01-02 13:09:34 -080077 constant_time._ffi.verifier.get_extension(),
78 padding._ffi.verifier.get_extension()
79 ]
Alex Gaynordefc7f02014-01-19 23:44:31 -060080 if CommonCryptoBinding.is_available():
81 self.distribution.ext_modules.append(
82 CommonCryptoBinding().ffi.verifier.get_extension()
83 )
Alex Gaynor50f233e2014-01-06 11:10:40 -080084
Alex Gaynor9a00f052014-01-02 13:09:34 -080085 build.finalize_options(self)
86
koobs92a4cdb2014-02-24 22:13:17 +110087
Alex Gaynoracac6a62014-03-04 15:24:03 -080088class PyTest(test):
koobsff0dd1e2014-02-24 21:55:04 +110089 def finalize_options(self):
Alex Gaynor6858cd42014-03-04 15:33:13 -080090 test.finalize_options(self)
koobsff0dd1e2014-02-24 21:55:04 +110091 self.test_args = []
92 self.test_suite = True
koobs06671802014-02-24 22:33:07 +110093
Alex Stapletona39a3192014-03-14 20:03:12 +000094 # This means there's a vectors/ folder with the package in here.
95 # cd into it, install the vectors package and then refresh sys.path
96 if VECTORS_DEPENDENCY not in test_requirements:
97 subprocess.Popen([sys.executable, "setup.py", "install"],
98 cwd="vectors").communicate()
99 pkg_resources.get_distribution("cryptography_vectors").activate()
100
koobsff0dd1e2014-02-24 21:55:04 +1100101 def run_tests(self):
koobs92a4cdb2014-02-24 22:13:17 +1100102 # Import here because in module scope the eggs are not loaded.
koobsff0dd1e2014-02-24 21:55:04 +1100103 import pytest
104 errno = pytest.main(self.test_args)
105 sys.exit(errno)
106
Alex Gaynor9a00f052014-01-02 13:09:34 -0800107
Alex Gaynor7630d6c2014-01-03 07:34:43 -0800108with open(os.path.join(base_dir, "README.rst")) as f:
Alex Gaynorf51f2c12014-01-03 07:33:01 -0800109 long_description = f.read()
110
111
Alex Gaynorc62e91f2013-08-06 19:25:52 -0700112setup(
Donald Stufft5f12a1b2013-08-11 16:37:43 -0400113 name=about["__title__"],
114 version=about["__version__"],
115
116 description=about["__summary__"],
Alex Gaynorf51f2c12014-01-03 07:33:01 -0800117 long_description=long_description,
Donald Stufft5f12a1b2013-08-11 16:37:43 -0400118 license=about["__license__"],
119 url=about["__uri__"],
120
121 author=about["__author__"],
122 author_email=about["__email__"],
123
Christian Heimesf83ed1d2013-08-10 23:28:29 +0200124 classifiers=[
Christian Heimesf83ed1d2013-08-10 23:28:29 +0200125 "Intended Audience :: Developers",
126 "License :: OSI Approved :: Apache Software License",
127 "Natural Language :: English",
128 "Operating System :: MacOS :: MacOS X",
129 "Operating System :: POSIX",
130 "Operating System :: POSIX :: BSD",
131 "Operating System :: POSIX :: Linux",
132 "Operating System :: Microsoft :: Windows",
Christian Heimesf83ed1d2013-08-10 23:28:29 +0200133 "Programming Language :: Python",
134 "Programming Language :: Python :: 2",
135 "Programming Language :: Python :: 2.6",
136 "Programming Language :: Python :: 2.7",
137 "Programming Language :: Python :: 3",
138 "Programming Language :: Python :: 3.2",
139 "Programming Language :: Python :: 3.3",
Alex Gaynor7f8b2772014-03-17 10:22:41 -0700140 "Programming Language :: Python :: 3.4",
Christian Heimesf83ed1d2013-08-10 23:28:29 +0200141 "Programming Language :: Python :: Implementation :: CPython",
142 "Programming Language :: Python :: Implementation :: PyPy",
143 "Topic :: Security :: Cryptography",
144 ],
Donald Stufft5f12a1b2013-08-11 16:37:43 -0400145
Donald Stufft9ebb8ff2013-08-11 17:05:03 -0400146 packages=find_packages(exclude=["tests", "tests.*"]),
147
Alex Gaynor91f119e2014-01-02 13:12:59 -0800148 install_requires=requirements,
149 setup_requires=requirements,
koobsff0dd1e2014-02-24 21:55:04 +1100150 tests_require=test_requirements,
Donald Stufft5f12a1b2013-08-11 16:37:43 -0400151
152 # for cffi
153 zip_safe=False,
Alex Gaynor9a00f052014-01-02 13:09:34 -0800154 ext_package="cryptography",
155 cmdclass={
Paul Kehrer5b6ce2a2014-02-24 20:16:10 -0600156 "build": CFFIBuild,
koobsff0dd1e2014-02-24 21:55:04 +1100157 "test": PyTest,
Alex Gaynor9a00f052014-01-02 13:09:34 -0800158 }
Alex Gaynorc62e91f2013-08-06 19:25:52 -0700159)