blob: ecf0f5ea4d88bbf88b158bb71e147a8035da0f7f [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 Gaynorf51f2c12014-01-03 07:33:01 -080013import os
Alex Gaynor9a00f052014-01-02 13:09:34 -080014from distutils.command.build import build
15
Donald Stufft9ebb8ff2013-08-11 17:05:03 -040016from setuptools import setup, find_packages
koobsff0dd1e2014-02-24 21:55:04 +110017from setuptools.command.test import test as TestCommand
Donald Stufft446a4572013-08-11 17:38:13 -040018
Alex Gaynor7630d6c2014-01-03 07:34:43 -080019base_dir = os.path.dirname(__file__)
20
Donald Stufft5f12a1b2013-08-11 16:37:43 -040021about = {}
Alex Gaynor7630d6c2014-01-03 07:34:43 -080022with open(os.path.join(base_dir, "cryptography", "__about__.py")) as f:
23 exec(f.read(), about)
Donald Stufft5f12a1b2013-08-11 16:37:43 -040024
25
Paul Kehrer7fcaa372014-01-10 23:39:58 -060026CFFI_DEPENDENCY = "cffi>=0.8"
Paul Kehrerc0242552013-09-10 18:54:13 -050027SIX_DEPENDENCY = "six>=1.4.1"
Donald Stufft5f12a1b2013-08-11 16:37:43 -040028
Alex Gaynor91f119e2014-01-02 13:12:59 -080029requirements = [
Donald Stufft5f12a1b2013-08-11 16:37:43 -040030 CFFI_DEPENDENCY,
Paul Kehrerc0242552013-09-10 18:54:13 -050031 SIX_DEPENDENCY
Donald Stufft5f12a1b2013-08-11 16:37:43 -040032]
33
koobsff0dd1e2014-02-24 21:55:04 +110034test_requirements = [
35 "pytest",
36 "pretend",
37 "iso8601"
38]
39
Alex Gaynor9a00f052014-01-02 13:09:34 -080040
Paul Kehrer5b6ce2a2014-02-24 20:16:10 -060041class CFFIBuild(build):
Alex Gaynor49697512014-01-03 15:08:45 -080042 """
43 This class exists, instead of just providing ``ext_modules=[...]`` directly
44 in ``setup()`` because importing cryptography requires we have several
45 packages installed first.
46
47 By doing the imports here we ensure that packages listed in
48 ``setup_requires`` are already installed.
49 """
50
Alex Gaynor9a00f052014-01-02 13:09:34 -080051 def finalize_options(self):
Alex Gaynordefc7f02014-01-19 23:44:31 -060052 from cryptography.hazmat.bindings.commoncrypto.binding import (
53 Binding as CommonCryptoBinding
54 )
55 from cryptography.hazmat.bindings.openssl.binding import (
56 Binding as OpenSSLBinding
57 )
Alex Gaynor9a00f052014-01-02 13:09:34 -080058 from cryptography.hazmat.primitives import constant_time, padding
59
60 self.distribution.ext_modules = [
Alex Gaynordefc7f02014-01-19 23:44:31 -060061 OpenSSLBinding().ffi.verifier.get_extension(),
Alex Gaynor9a00f052014-01-02 13:09:34 -080062 constant_time._ffi.verifier.get_extension(),
63 padding._ffi.verifier.get_extension()
64 ]
Alex Gaynordefc7f02014-01-19 23:44:31 -060065 if CommonCryptoBinding.is_available():
66 self.distribution.ext_modules.append(
67 CommonCryptoBinding().ffi.verifier.get_extension()
68 )
Alex Gaynor50f233e2014-01-06 11:10:40 -080069
Alex Gaynor9a00f052014-01-02 13:09:34 -080070 build.finalize_options(self)
71
koobsff0dd1e2014-02-24 21:55:04 +110072class PyTest(TestCommand):
73 def finalize_options(self):
74 TestCommand.finalize_options(self)
75 self.test_args = []
76 self.test_suite = True
77 def run_tests(self):
78 #import here, cause outside the eggs aren't loaded
79 import pytest
80 errno = pytest.main(self.test_args)
81 sys.exit(errno)
82
Alex Gaynor9a00f052014-01-02 13:09:34 -080083
Alex Gaynor7630d6c2014-01-03 07:34:43 -080084with open(os.path.join(base_dir, "README.rst")) as f:
Alex Gaynorf51f2c12014-01-03 07:33:01 -080085 long_description = f.read()
86
87
Alex Gaynorc62e91f2013-08-06 19:25:52 -070088setup(
Donald Stufft5f12a1b2013-08-11 16:37:43 -040089 name=about["__title__"],
90 version=about["__version__"],
91
92 description=about["__summary__"],
Alex Gaynorf51f2c12014-01-03 07:33:01 -080093 long_description=long_description,
Donald Stufft5f12a1b2013-08-11 16:37:43 -040094 license=about["__license__"],
95 url=about["__uri__"],
96
97 author=about["__author__"],
98 author_email=about["__email__"],
99
Christian Heimesf83ed1d2013-08-10 23:28:29 +0200100 classifiers=[
Christian Heimesf83ed1d2013-08-10 23:28:29 +0200101 "Intended Audience :: Developers",
102 "License :: OSI Approved :: Apache Software License",
103 "Natural Language :: English",
104 "Operating System :: MacOS :: MacOS X",
105 "Operating System :: POSIX",
106 "Operating System :: POSIX :: BSD",
107 "Operating System :: POSIX :: Linux",
108 "Operating System :: Microsoft :: Windows",
Christian Heimesf83ed1d2013-08-10 23:28:29 +0200109 "Programming Language :: Python",
110 "Programming Language :: Python :: 2",
111 "Programming Language :: Python :: 2.6",
112 "Programming Language :: Python :: 2.7",
113 "Programming Language :: Python :: 3",
114 "Programming Language :: Python :: 3.2",
115 "Programming Language :: Python :: 3.3",
116 "Programming Language :: Python :: Implementation :: CPython",
117 "Programming Language :: Python :: Implementation :: PyPy",
118 "Topic :: Security :: Cryptography",
119 ],
Donald Stufft5f12a1b2013-08-11 16:37:43 -0400120
Donald Stufft9ebb8ff2013-08-11 17:05:03 -0400121 packages=find_packages(exclude=["tests", "tests.*"]),
122
Alex Gaynor91f119e2014-01-02 13:12:59 -0800123 install_requires=requirements,
124 setup_requires=requirements,
koobsff0dd1e2014-02-24 21:55:04 +1100125 tests_require=test_requirements,
Donald Stufft5f12a1b2013-08-11 16:37:43 -0400126
127 # for cffi
128 zip_safe=False,
Alex Gaynor9a00f052014-01-02 13:09:34 -0800129 ext_package="cryptography",
130 cmdclass={
Paul Kehrer5b6ce2a2014-02-24 20:16:10 -0600131 "build": CFFIBuild,
koobsff0dd1e2014-02-24 21:55:04 +1100132 "test": PyTest,
Alex Gaynor9a00f052014-01-02 13:09:34 -0800133 }
Alex Gaynorc62e91f2013-08-06 19:25:52 -0700134)