Alex Gaynor | bfc06bc | 2013-08-06 19:36:19 -0700 | [diff] [blame] | 1 | # 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 Gaynor | c37feed | 2014-03-08 08:32:56 -0800 | [diff] [blame] | 13 | |
| 14 | from __future__ import absolute_import, division, print_function |
| 15 | |
Alex Gaynor | f51f2c1 | 2014-01-03 07:33:01 -0800 | [diff] [blame] | 16 | import os |
koobs | 23690dd | 2014-02-24 22:26:23 +1100 | [diff] [blame] | 17 | import sys |
Paul Kehrer | 8443a92 | 2014-03-19 13:09:31 -0400 | [diff] [blame] | 18 | from distutils.command.build import build |
Alex Stapleton | a39a319 | 2014-03-14 20:03:12 +0000 | [diff] [blame] | 19 | import subprocess |
| 20 | |
| 21 | import pkg_resources |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 22 | |
Paul Kehrer | afc1ccd | 2014-03-19 11:49:32 -0400 | [diff] [blame] | 23 | from setuptools import find_packages, setup |
Alex Gaynor | acac6a6 | 2014-03-04 15:24:03 -0800 | [diff] [blame] | 24 | from setuptools.command.test import test |
Donald Stufft | 446a457 | 2013-08-11 17:38:13 -0400 | [diff] [blame] | 25 | |
Paul Kehrer | afc1ccd | 2014-03-19 11:49:32 -0400 | [diff] [blame] | 26 | |
Alex Gaynor | 7630d6c | 2014-01-03 07:34:43 -0800 | [diff] [blame] | 27 | base_dir = os.path.dirname(__file__) |
| 28 | |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 29 | about = {} |
Alex Gaynor | 7630d6c | 2014-01-03 07:34:43 -0800 | [diff] [blame] | 30 | with open(os.path.join(base_dir, "cryptography", "__about__.py")) as f: |
| 31 | exec(f.read(), about) |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 32 | |
| 33 | |
Paul Kehrer | 7fcaa37 | 2014-01-10 23:39:58 -0600 | [diff] [blame] | 34 | CFFI_DEPENDENCY = "cffi>=0.8" |
Paul Kehrer | c024255 | 2013-09-10 18:54:13 -0500 | [diff] [blame] | 35 | SIX_DEPENDENCY = "six>=1.4.1" |
Alex Stapleton | a39a319 | 2014-03-14 20:03:12 +0000 | [diff] [blame] | 36 | VECTORS_DEPENDENCY = "cryptography_vectors=={0}".format(about['__version__']) |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 37 | |
Alex Gaynor | 91f119e | 2014-01-02 13:12:59 -0800 | [diff] [blame] | 38 | requirements = [ |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 39 | CFFI_DEPENDENCY, |
Paul Kehrer | c024255 | 2013-09-10 18:54:13 -0500 | [diff] [blame] | 40 | SIX_DEPENDENCY |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 41 | ] |
| 42 | |
Paul Kehrer | 7ad18bc | 2014-03-26 13:13:38 -0600 | [diff] [blame^] | 43 | # If you add a new dep here you probably need to add it in the tox.ini as well |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 44 | test_requirements = [ |
| 45 | "pytest", |
| 46 | "pretend", |
Alex Stapleton | 0bd20e2 | 2014-03-14 19:58:07 +0000 | [diff] [blame] | 47 | "iso8601", |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 48 | ] |
| 49 | |
Alex Stapleton | a39a319 | 2014-03-14 20:03:12 +0000 | [diff] [blame] | 50 | # 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 |
| 52 | if not os.path.exists(os.path.join(base_dir, "vectors/setup.py")): |
| 53 | test_requirements.append(VECTORS_DEPENDENCY) |
| 54 | |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 55 | |
Paul Kehrer | 5b6ce2a | 2014-02-24 20:16:10 -0600 | [diff] [blame] | 56 | class CFFIBuild(build): |
Alex Gaynor | 4969751 | 2014-01-03 15:08:45 -0800 | [diff] [blame] | 57 | """ |
| 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 Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 66 | def finalize_options(self): |
Alex Gaynor | defc7f0 | 2014-01-19 23:44:31 -0600 | [diff] [blame] | 67 | 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 Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 73 | from cryptography.hazmat.primitives import constant_time, padding |
| 74 | |
| 75 | self.distribution.ext_modules = [ |
Alex Gaynor | defc7f0 | 2014-01-19 23:44:31 -0600 | [diff] [blame] | 76 | OpenSSLBinding().ffi.verifier.get_extension(), |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 77 | constant_time._ffi.verifier.get_extension(), |
| 78 | padding._ffi.verifier.get_extension() |
| 79 | ] |
Alex Gaynor | defc7f0 | 2014-01-19 23:44:31 -0600 | [diff] [blame] | 80 | if CommonCryptoBinding.is_available(): |
| 81 | self.distribution.ext_modules.append( |
| 82 | CommonCryptoBinding().ffi.verifier.get_extension() |
| 83 | ) |
Alex Gaynor | 50f233e | 2014-01-06 11:10:40 -0800 | [diff] [blame] | 84 | |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 85 | build.finalize_options(self) |
| 86 | |
koobs | 92a4cdb | 2014-02-24 22:13:17 +1100 | [diff] [blame] | 87 | |
Alex Gaynor | acac6a6 | 2014-03-04 15:24:03 -0800 | [diff] [blame] | 88 | class PyTest(test): |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 89 | def finalize_options(self): |
Alex Gaynor | 6858cd4 | 2014-03-04 15:33:13 -0800 | [diff] [blame] | 90 | test.finalize_options(self) |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 91 | self.test_args = [] |
| 92 | self.test_suite = True |
koobs | 0667180 | 2014-02-24 22:33:07 +1100 | [diff] [blame] | 93 | |
Alex Stapleton | a39a319 | 2014-03-14 20:03:12 +0000 | [diff] [blame] | 94 | # 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 | |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 101 | def run_tests(self): |
koobs | 92a4cdb | 2014-02-24 22:13:17 +1100 | [diff] [blame] | 102 | # Import here because in module scope the eggs are not loaded. |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 103 | import pytest |
| 104 | errno = pytest.main(self.test_args) |
| 105 | sys.exit(errno) |
| 106 | |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 107 | |
Alex Gaynor | 7630d6c | 2014-01-03 07:34:43 -0800 | [diff] [blame] | 108 | with open(os.path.join(base_dir, "README.rst")) as f: |
Alex Gaynor | f51f2c1 | 2014-01-03 07:33:01 -0800 | [diff] [blame] | 109 | long_description = f.read() |
| 110 | |
| 111 | |
Alex Gaynor | c62e91f | 2013-08-06 19:25:52 -0700 | [diff] [blame] | 112 | setup( |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 113 | name=about["__title__"], |
| 114 | version=about["__version__"], |
| 115 | |
| 116 | description=about["__summary__"], |
Alex Gaynor | f51f2c1 | 2014-01-03 07:33:01 -0800 | [diff] [blame] | 117 | long_description=long_description, |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 118 | license=about["__license__"], |
| 119 | url=about["__uri__"], |
| 120 | |
| 121 | author=about["__author__"], |
| 122 | author_email=about["__email__"], |
| 123 | |
Christian Heimes | f83ed1d | 2013-08-10 23:28:29 +0200 | [diff] [blame] | 124 | classifiers=[ |
Christian Heimes | f83ed1d | 2013-08-10 23:28:29 +0200 | [diff] [blame] | 125 | "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 Heimes | f83ed1d | 2013-08-10 23:28:29 +0200 | [diff] [blame] | 133 | "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 Gaynor | 7f8b277 | 2014-03-17 10:22:41 -0700 | [diff] [blame] | 140 | "Programming Language :: Python :: 3.4", |
Christian Heimes | f83ed1d | 2013-08-10 23:28:29 +0200 | [diff] [blame] | 141 | "Programming Language :: Python :: Implementation :: CPython", |
| 142 | "Programming Language :: Python :: Implementation :: PyPy", |
| 143 | "Topic :: Security :: Cryptography", |
| 144 | ], |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 145 | |
Donald Stufft | 9ebb8ff | 2013-08-11 17:05:03 -0400 | [diff] [blame] | 146 | packages=find_packages(exclude=["tests", "tests.*"]), |
| 147 | |
Alex Gaynor | 91f119e | 2014-01-02 13:12:59 -0800 | [diff] [blame] | 148 | install_requires=requirements, |
| 149 | setup_requires=requirements, |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 150 | tests_require=test_requirements, |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 151 | |
| 152 | # for cffi |
| 153 | zip_safe=False, |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 154 | ext_package="cryptography", |
| 155 | cmdclass={ |
Paul Kehrer | 5b6ce2a | 2014-02-24 20:16:10 -0600 | [diff] [blame] | 156 | "build": CFFIBuild, |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 157 | "test": PyTest, |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 158 | } |
Alex Gaynor | c62e91f | 2013-08-06 19:25:52 -0700 | [diff] [blame] | 159 | ) |