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 | f51f2c1 | 2014-01-03 07:33:01 -0800 | [diff] [blame] | 13 | import os |
koobs | 23690dd | 2014-02-24 22:26:23 +1100 | [diff] [blame] | 14 | import sys |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 15 | from distutils.command.build import build |
| 16 | |
Donald Stufft | 9ebb8ff | 2013-08-11 17:05:03 -0400 | [diff] [blame] | 17 | from setuptools import setup, find_packages |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 18 | from setuptools.command.test import test as TestCommand |
Donald Stufft | 446a457 | 2013-08-11 17:38:13 -0400 | [diff] [blame] | 19 | |
Alex Gaynor | 7630d6c | 2014-01-03 07:34:43 -0800 | [diff] [blame] | 20 | base_dir = os.path.dirname(__file__) |
| 21 | |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 22 | about = {} |
Alex Gaynor | 7630d6c | 2014-01-03 07:34:43 -0800 | [diff] [blame] | 23 | with open(os.path.join(base_dir, "cryptography", "__about__.py")) as f: |
| 24 | exec(f.read(), about) |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 25 | |
| 26 | |
Paul Kehrer | 7fcaa37 | 2014-01-10 23:39:58 -0600 | [diff] [blame] | 27 | CFFI_DEPENDENCY = "cffi>=0.8" |
Paul Kehrer | c024255 | 2013-09-10 18:54:13 -0500 | [diff] [blame] | 28 | SIX_DEPENDENCY = "six>=1.4.1" |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 29 | |
Alex Gaynor | 91f119e | 2014-01-02 13:12:59 -0800 | [diff] [blame] | 30 | requirements = [ |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 31 | CFFI_DEPENDENCY, |
Paul Kehrer | c024255 | 2013-09-10 18:54:13 -0500 | [diff] [blame] | 32 | SIX_DEPENDENCY |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 33 | ] |
| 34 | |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 35 | test_requirements = [ |
| 36 | "pytest", |
| 37 | "pretend", |
| 38 | "iso8601" |
| 39 | ] |
| 40 | |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 41 | |
Paul Kehrer | 5b6ce2a | 2014-02-24 20:16:10 -0600 | [diff] [blame] | 42 | class CFFIBuild(build): |
Alex Gaynor | 4969751 | 2014-01-03 15:08:45 -0800 | [diff] [blame] | 43 | """ |
| 44 | This class exists, instead of just providing ``ext_modules=[...]`` directly |
| 45 | in ``setup()`` because importing cryptography requires we have several |
| 46 | packages installed first. |
| 47 | |
| 48 | By doing the imports here we ensure that packages listed in |
| 49 | ``setup_requires`` are already installed. |
| 50 | """ |
| 51 | |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 52 | def finalize_options(self): |
Alex Gaynor | defc7f0 | 2014-01-19 23:44:31 -0600 | [diff] [blame] | 53 | from cryptography.hazmat.bindings.commoncrypto.binding import ( |
| 54 | Binding as CommonCryptoBinding |
| 55 | ) |
| 56 | from cryptography.hazmat.bindings.openssl.binding import ( |
| 57 | Binding as OpenSSLBinding |
| 58 | ) |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 59 | from cryptography.hazmat.primitives import constant_time, padding |
| 60 | |
| 61 | self.distribution.ext_modules = [ |
Alex Gaynor | defc7f0 | 2014-01-19 23:44:31 -0600 | [diff] [blame] | 62 | OpenSSLBinding().ffi.verifier.get_extension(), |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 63 | constant_time._ffi.verifier.get_extension(), |
| 64 | padding._ffi.verifier.get_extension() |
| 65 | ] |
Alex Gaynor | defc7f0 | 2014-01-19 23:44:31 -0600 | [diff] [blame] | 66 | if CommonCryptoBinding.is_available(): |
| 67 | self.distribution.ext_modules.append( |
| 68 | CommonCryptoBinding().ffi.verifier.get_extension() |
| 69 | ) |
Alex Gaynor | 50f233e | 2014-01-06 11:10:40 -0800 | [diff] [blame] | 70 | |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 71 | build.finalize_options(self) |
| 72 | |
koobs | 92a4cdb | 2014-02-24 22:13:17 +1100 | [diff] [blame] | 73 | |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 74 | class PyTest(TestCommand): |
| 75 | def finalize_options(self): |
| 76 | TestCommand.finalize_options(self) |
| 77 | self.test_args = [] |
| 78 | self.test_suite = True |
koobs | 0667180 | 2014-02-24 22:33:07 +1100 | [diff] [blame] | 79 | |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 80 | def run_tests(self): |
koobs | 92a4cdb | 2014-02-24 22:13:17 +1100 | [diff] [blame] | 81 | # Import here because in module scope the eggs are not loaded. |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 82 | import pytest |
| 83 | errno = pytest.main(self.test_args) |
| 84 | sys.exit(errno) |
| 85 | |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 86 | |
Alex Gaynor | 7630d6c | 2014-01-03 07:34:43 -0800 | [diff] [blame] | 87 | with open(os.path.join(base_dir, "README.rst")) as f: |
Alex Gaynor | f51f2c1 | 2014-01-03 07:33:01 -0800 | [diff] [blame] | 88 | long_description = f.read() |
| 89 | |
| 90 | |
Alex Gaynor | c62e91f | 2013-08-06 19:25:52 -0700 | [diff] [blame] | 91 | setup( |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 92 | name=about["__title__"], |
| 93 | version=about["__version__"], |
| 94 | |
| 95 | description=about["__summary__"], |
Alex Gaynor | f51f2c1 | 2014-01-03 07:33:01 -0800 | [diff] [blame] | 96 | long_description=long_description, |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 97 | license=about["__license__"], |
| 98 | url=about["__uri__"], |
| 99 | |
| 100 | author=about["__author__"], |
| 101 | author_email=about["__email__"], |
| 102 | |
Christian Heimes | f83ed1d | 2013-08-10 23:28:29 +0200 | [diff] [blame] | 103 | classifiers=[ |
Christian Heimes | f83ed1d | 2013-08-10 23:28:29 +0200 | [diff] [blame] | 104 | "Intended Audience :: Developers", |
| 105 | "License :: OSI Approved :: Apache Software License", |
| 106 | "Natural Language :: English", |
| 107 | "Operating System :: MacOS :: MacOS X", |
| 108 | "Operating System :: POSIX", |
| 109 | "Operating System :: POSIX :: BSD", |
| 110 | "Operating System :: POSIX :: Linux", |
| 111 | "Operating System :: Microsoft :: Windows", |
Christian Heimes | f83ed1d | 2013-08-10 23:28:29 +0200 | [diff] [blame] | 112 | "Programming Language :: Python", |
| 113 | "Programming Language :: Python :: 2", |
| 114 | "Programming Language :: Python :: 2.6", |
| 115 | "Programming Language :: Python :: 2.7", |
| 116 | "Programming Language :: Python :: 3", |
| 117 | "Programming Language :: Python :: 3.2", |
| 118 | "Programming Language :: Python :: 3.3", |
| 119 | "Programming Language :: Python :: Implementation :: CPython", |
| 120 | "Programming Language :: Python :: Implementation :: PyPy", |
| 121 | "Topic :: Security :: Cryptography", |
| 122 | ], |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 123 | |
Donald Stufft | 9ebb8ff | 2013-08-11 17:05:03 -0400 | [diff] [blame] | 124 | packages=find_packages(exclude=["tests", "tests.*"]), |
| 125 | |
Alex Gaynor | 91f119e | 2014-01-02 13:12:59 -0800 | [diff] [blame] | 126 | install_requires=requirements, |
| 127 | setup_requires=requirements, |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 128 | tests_require=test_requirements, |
Donald Stufft | 5f12a1b | 2013-08-11 16:37:43 -0400 | [diff] [blame] | 129 | |
| 130 | # for cffi |
| 131 | zip_safe=False, |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 132 | ext_package="cryptography", |
| 133 | cmdclass={ |
Paul Kehrer | 5b6ce2a | 2014-02-24 20:16:10 -0600 | [diff] [blame] | 134 | "build": CFFIBuild, |
koobs | ff0dd1e | 2014-02-24 21:55:04 +1100 | [diff] [blame] | 135 | "test": PyTest, |
Alex Gaynor | 9a00f05 | 2014-01-02 13:09:34 -0800 | [diff] [blame] | 136 | } |
Alex Gaynor | c62e91f | 2013-08-06 19:25:52 -0700 | [diff] [blame] | 137 | ) |