We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Installing cryptography with old pypy builds (and caches) bad wheels
If I install cryptography with pypy 2.5.1, the new cffi build mechanism isn't invoked and I get an installed package without any of the compiled modules. However, pip builds and caches `cryptography-1.0-py2-none-any.whl` which is platform-independent (because it has no compiled modules). This bad wheel then gets used for any further installs with any Python 2 interpreter, and happily installs a cryptography without any of the interesting bits.

To illustrate with an example:

``` console
root@e1ffcbbe8f9d:/foo$ # Before cryptograpy is installed:
root@e1ffcbbe8f9d:/foo$ find ~/.cache/pip/wheels -name 'cryptography*'
root@e1ffcbbe8f9d:/foo$ /env-pypy-2.6.0/bin/pypy -c 'import cryptography.hazmat.bindings._openssl' 2>&1 | grep ImportError
ImportError: No module named cryptography

root@e1ffcbbe8f9d:/foo$ # Install cryptography using old pypy:
root@e1ffcbbe8f9d:/foo$ /env-pypy-2.5.1/bin/pip install cryptography -q
root@e1ffcbbe8f9d:/foo$ find ~/.cache/pip/wheels -name 'cryptography*'
/root/.cache/pip/wheels/6d/db/24/a5bbe660e3b632abb007ba6d8c91b5fa51a83bb53544c16709/cryptography-1.0-py2-none-any.whl

root@e1ffcbbe8f9d:/foo$ # After that, install cryptography using new pypy:
root@e1ffcbbe8f9d:/foo$ /env-pypy-2.6.0/bin/pip install cryptography -q
root@e1ffcbbe8f9d:/foo$ find ~/.cache/pip/wheels -name 'cryptography*'
/root/.cache/pip/wheels/6d/db/24/a5bbe660e3b632abb007ba6d8c91b5fa51a83bb53544c16709/cryptography-1.0-py2-none-any.whl

root@e1ffcbbe8f9d:/foo$ # The installed cryptography is now broken:
root@e1ffcbbe8f9d:/foo$ /env-pypy-2.6.0/bin/pypy -c 'import cryptography.hazmat.bindings._openssl' 2>&1 | grep ImportError
ImportError: No module named cryptography.hazmat.bindings._openssl
```

I think a reasonable solution is to explicitly fail to build or install on older versions of pypy. This would prevent the broken wheel from being being built, and would also give a useful error at install time instead of silently installing a nonfunctional cryptography.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `setup.py`
Content:
```
1 # This file is dual licensed under the terms of the Apache License, Version
2 # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3 # for complete details.
4 
5 from __future__ import absolute_import, division, print_function
6 
7 import os
8 import platform
9 import subprocess
10 import sys
11 from distutils.command.build import build
12 
13 import pkg_resources
14 
15 from setuptools import find_packages, setup
16 from setuptools.command.install import install
17 from setuptools.command.test import test
18 
19 
20 base_dir = os.path.dirname(__file__)
21 src_dir = os.path.join(base_dir, "src")
22 
23 # When executing the setup.py, we need to be able to import ourselves, this
24 # means that we need to add the src/ directory to the sys.path.
25 sys.path.insert(0, src_dir)
26 
27 about = {}
28 with open(os.path.join(src_dir, "cryptography", "__about__.py")) as f:
29     exec(f.read(), about)
30 
31 
32 VECTORS_DEPENDENCY = "cryptography_vectors=={0}".format(about['__version__'])
33 
34 requirements = [
35     "idna>=2.0",
36     "pyasn1>=0.1.8",
37     "six>=1.4.1",
38     "setuptools",
39 ]
40 setup_requirements = []
41 
42 if sys.version_info < (3, 4):
43     requirements.append("enum34")
44 
45 if sys.version_info < (3, 3):
46     requirements.append("ipaddress")
47 
48 if platform.python_implementation() != "PyPy":
49     requirements.append("cffi>=1.1.0")
50     setup_requirements.append("cffi>=1.1.0")
51 
52 # If you add a new dep here you probably need to add it in the tox.ini as well
53 test_requirements = [
54     "pytest",
55     "pretend",
56     "iso8601",
57 ]
58 
59 # If there's no vectors locally that probably means we are in a tarball and
60 # need to go and get the matching vectors package from PyPi
61 if not os.path.exists(os.path.join(base_dir, "vectors/setup.py")):
62     test_requirements.append(VECTORS_DEPENDENCY)
63 
64 
65 def cc_is_available():
66     return sys.platform == "darwin" and list(map(
67         int, platform.mac_ver()[0].split("."))) >= [10, 8, 0]
68 
69 
70 backends = [
71     "openssl = cryptography.hazmat.backends.openssl:backend"
72 ]
73 
74 if cc_is_available():
75     backends.append(
76         "commoncrypto = cryptography.hazmat.backends.commoncrypto:backend",
77     )
78 
79 
80 class PyTest(test):
81     def finalize_options(self):
82         test.finalize_options(self)
83         self.test_args = []
84         self.test_suite = True
85 
86         # This means there's a vectors/ folder with the package in here.
87         # cd into it, install the vectors package and then refresh sys.path
88         if VECTORS_DEPENDENCY not in test_requirements:
89             subprocess.check_call(
90                 [sys.executable, "setup.py", "install"], cwd="vectors"
91             )
92             pkg_resources.get_distribution("cryptography_vectors").activate()
93 
94     def run_tests(self):
95         # Import here because in module scope the eggs are not loaded.
96         import pytest
97         test_args = [os.path.join(base_dir, "tests")]
98         errno = pytest.main(test_args)
99         sys.exit(errno)
100 
101 
102 def keywords_with_side_effects(argv):
103     """
104     Get a dictionary with setup keywords that (can) have side effects.
105 
106     :param argv: A list of strings with command line arguments.
107     :returns: A dictionary with keyword arguments for the ``setup()`` function.
108 
109     This setup.py script uses the setuptools 'setup_requires' feature because
110     this is required by the cffi package to compile extension modules. The
111     purpose of ``keywords_with_side_effects()`` is to avoid triggering the cffi
112     build process as a result of setup.py invocations that don't need the cffi
113     module to be built (setup.py serves the dual purpose of exposing package
114     metadata).
115 
116     All of the options listed by ``python setup.py --help`` that print
117     information should be recognized here. The commands ``clean``,
118     ``egg_info``, ``register``, ``sdist`` and ``upload`` are also recognized.
119     Any combination of these options and commands is also supported.
120 
121     This function was originally based on the `setup.py script`_ of SciPy (see
122     also the discussion in `pip issue #25`_).
123 
124     .. _pip issue #25: https://github.com/pypa/pip/issues/25
125     .. _setup.py script: https://github.com/scipy/scipy/blob/master/setup.py
126     """
127     no_setup_requires_arguments = (
128         '-h', '--help',
129         '-n', '--dry-run',
130         '-q', '--quiet',
131         '-v', '--verbose',
132         '-V', '--version',
133         '--author',
134         '--author-email',
135         '--classifiers',
136         '--contact',
137         '--contact-email',
138         '--description',
139         '--egg-base',
140         '--fullname',
141         '--help-commands',
142         '--keywords',
143         '--licence',
144         '--license',
145         '--long-description',
146         '--maintainer',
147         '--maintainer-email',
148         '--name',
149         '--no-user-cfg',
150         '--obsoletes',
151         '--platforms',
152         '--provides',
153         '--requires',
154         '--url',
155         'clean',
156         'egg_info',
157         'register',
158         'sdist',
159         'upload',
160     )
161 
162     def is_short_option(argument):
163         """Check whether a command line argument is a short option."""
164         return len(argument) >= 2 and argument[0] == '-' and argument[1] != '-'
165 
166     def expand_short_options(argument):
167         """Expand combined short options into canonical short options."""
168         return ('-' + char for char in argument[1:])
169 
170     def argument_without_setup_requirements(argv, i):
171         """Check whether a command line argument needs setup requirements."""
172         if argv[i] in no_setup_requires_arguments:
173             # Simple case: An argument which is either an option or a command
174             # which doesn't need setup requirements.
175             return True
176         elif (is_short_option(argv[i]) and
177               all(option in no_setup_requires_arguments
178                   for option in expand_short_options(argv[i]))):
179             # Not so simple case: Combined short options none of which need
180             # setup requirements.
181             return True
182         elif argv[i - 1:i] == ['--egg-base']:
183             # Tricky case: --egg-info takes an argument which should not make
184             # us use setup_requires (defeating the purpose of this code).
185             return True
186         else:
187             return False
188 
189     if all(argument_without_setup_requirements(argv, i)
190            for i in range(1, len(argv))):
191         return {
192             "cmdclass": {
193                 "build": DummyBuild,
194                 "install": DummyInstall,
195                 "test": DummyPyTest,
196             }
197         }
198     else:
199         cffi_modules = [
200             "src/_cffi_src/build_openssl.py:ffi",
201             "src/_cffi_src/build_constant_time.py:ffi",
202             "src/_cffi_src/build_padding.py:ffi",
203         ]
204         if cc_is_available():
205             cffi_modules.append("src/_cffi_src/build_commoncrypto.py:ffi")
206 
207         return {
208             "setup_requires": setup_requirements,
209             "cmdclass": {
210                 "test": PyTest,
211             },
212             "cffi_modules": cffi_modules
213         }
214 
215 
216 setup_requires_error = ("Requested setup command that needs 'setup_requires' "
217                         "while command line arguments implied a side effect "
218                         "free command or option.")
219 
220 
221 class DummyBuild(build):
222     """
223     This class makes it very obvious when ``keywords_with_side_effects()`` has
224     incorrectly interpreted the command line arguments to ``setup.py build`` as
225     one of the 'side effect free' commands or options.
226     """
227 
228     def run(self):
229         raise RuntimeError(setup_requires_error)
230 
231 
232 class DummyInstall(install):
233     """
234     This class makes it very obvious when ``keywords_with_side_effects()`` has
235     incorrectly interpreted the command line arguments to ``setup.py install``
236     as one of the 'side effect free' commands or options.
237     """
238 
239     def run(self):
240         raise RuntimeError(setup_requires_error)
241 
242 
243 class DummyPyTest(test):
244     """
245     This class makes it very obvious when ``keywords_with_side_effects()`` has
246     incorrectly interpreted the command line arguments to ``setup.py test`` as
247     one of the 'side effect free' commands or options.
248     """
249 
250     def run_tests(self):
251         raise RuntimeError(setup_requires_error)
252 
253 
254 with open(os.path.join(base_dir, "README.rst")) as f:
255     long_description = f.read()
256 
257 
258 setup(
259     name=about["__title__"],
260     version=about["__version__"],
261 
262     description=about["__summary__"],
263     long_description=long_description,
264     license=about["__license__"],
265     url=about["__uri__"],
266 
267     author=about["__author__"],
268     author_email=about["__email__"],
269 
270     classifiers=[
271         "Intended Audience :: Developers",
272         "License :: OSI Approved :: Apache Software License",
273         "License :: OSI Approved :: BSD License",
274         "Natural Language :: English",
275         "Operating System :: MacOS :: MacOS X",
276         "Operating System :: POSIX",
277         "Operating System :: POSIX :: BSD",
278         "Operating System :: POSIX :: Linux",
279         "Operating System :: Microsoft :: Windows",
280         "Programming Language :: Python",
281         "Programming Language :: Python :: 2",
282         "Programming Language :: Python :: 2.6",
283         "Programming Language :: Python :: 2.7",
284         "Programming Language :: Python :: 3",
285         "Programming Language :: Python :: 3.3",
286         "Programming Language :: Python :: 3.4",
287         "Programming Language :: Python :: Implementation :: CPython",
288         "Programming Language :: Python :: Implementation :: PyPy",
289         "Topic :: Security :: Cryptography",
290     ],
291 
292     package_dir={"": "src"},
293     packages=find_packages(
294         where="src", exclude=["_cffi_src", "_cffi_src.*", "tests", "tests.*"]
295     ),
296     include_package_data=True,
297 
298     install_requires=requirements,
299     tests_require=test_requirements,
300 
301     # for cffi
302     zip_safe=False,
303     ext_package="cryptography.hazmat.bindings",
304     entry_points={
305         "cryptography.backends": backends,
306     },
307     **keywords_with_side_effects(sys.argv)
308 )
309
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -45,7 +45,13 @@
 if sys.version_info < (3, 3):
     requirements.append("ipaddress")
 
-if platform.python_implementation() != "PyPy":
+if platform.python_implementation() == "PyPy":
+    if sys.pypy_version_info < (2, 6):
+        raise RuntimeError(
+            "cryptography 1.0 is not compatible with PyPy < 2.6. Please "
+            "upgrade PyPy to use this library."
+        )
+else:
     requirements.append("cffi>=1.1.0")
     setup_requirements.append("cffi>=1.1.0")

{"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -45,7 +45,13 @@\n if sys.version_info < (3, 3):\n     requirements.append(\"ipaddress\")\n \n-if platform.python_implementation() != \"PyPy\":\n+if platform.python_implementation() == \"PyPy\":\n+    if sys.pypy_version_info < (2, 6):\n+        raise RuntimeError(\n+            \"cryptography 1.0 is not compatible with PyPy < 2.6. Please \"\n+            \"upgrade PyPy to use this library.\"\n+        )\n+else:\n     requirements.append(\"cffi>=1.1.0\")\n     setup_requirements.append(\"cffi>=1.1.0\")\n", "issue": "Installing cryptography with old pypy builds (and caches) bad wheels\nIf I install cryptography with pypy 2.5.1, the new cffi build mechanism isn't invoked and I get an installed package without any of the compiled modules. However, pip builds and caches `cryptography-1.0-py2-none-any.whl` which is platform-independent (because it has no compiled modules). This bad wheel then gets used for any further installs with any Python 2 interpreter, and happily installs a cryptography without any of the interesting bits.\n\nTo illustrate with an example:\n\n``` console\nroot@e1ffcbbe8f9d:/foo$ # Before cryptograpy is installed:\nroot@e1ffcbbe8f9d:/foo$ find ~/.cache/pip/wheels -name 'cryptography*'\nroot@e1ffcbbe8f9d:/foo$ /env-pypy-2.6.0/bin/pypy -c 'import cryptography.hazmat.bindings._openssl' 2>&1 | grep ImportError\nImportError: No module named cryptography\n\nroot@e1ffcbbe8f9d:/foo$ # Install cryptography using old pypy:\nroot@e1ffcbbe8f9d:/foo$ /env-pypy-2.5.1/bin/pip install cryptography -q\nroot@e1ffcbbe8f9d:/foo$ find ~/.cache/pip/wheels -name 'cryptography*'\n/root/.cache/pip/wheels/6d/db/24/a5bbe660e3b632abb007ba6d8c91b5fa51a83bb53544c16709/cryptography-1.0-py2-none-any.whl\n\nroot@e1ffcbbe8f9d:/foo$ # After that, install cryptography using new pypy:\nroot@e1ffcbbe8f9d:/foo$ /env-pypy-2.6.0/bin/pip install cryptography -q\nroot@e1ffcbbe8f9d:/foo$ find ~/.cache/pip/wheels -name 'cryptography*'\n/root/.cache/pip/wheels/6d/db/24/a5bbe660e3b632abb007ba6d8c91b5fa51a83bb53544c16709/cryptography-1.0-py2-none-any.whl\n\nroot@e1ffcbbe8f9d:/foo$ # The installed cryptography is now broken:\nroot@e1ffcbbe8f9d:/foo$ /env-pypy-2.6.0/bin/pypy -c 'import cryptography.hazmat.bindings._openssl' 2>&1 | grep ImportError\nImportError: No module named cryptography.hazmat.bindings._openssl\n```\n\nI think a reasonable solution is to explicitly fail to build or install on older versions of pypy. This would prevent the broken wheel from being being built, and would also give a useful error at install time instead of silently installing a nonfunctional cryptography.\n\n", "before_files": [{"content": "# This file is dual licensed under the terms of the Apache License, Version\n# 2.0, and the BSD License. See the LICENSE file in the root of this repository\n# for complete details.\n\nfrom __future__ import absolute_import, division, print_function\n\nimport os\nimport platform\nimport subprocess\nimport sys\nfrom distutils.command.build import build\n\nimport pkg_resources\n\nfrom setuptools import find_packages, setup\nfrom setuptools.command.install import install\nfrom setuptools.command.test import test\n\n\nbase_dir = os.path.dirname(__file__)\nsrc_dir = os.path.join(base_dir, \"src\")\n\n# When executing the setup.py, we need to be able to import ourselves, this\n# means that we need to add the src/ directory to the sys.path.\nsys.path.insert(0, src_dir)\n\nabout = {}\nwith open(os.path.join(src_dir, \"cryptography\", \"__about__.py\")) as f:\n    exec(f.read(), about)\n\n\nVECTORS_DEPENDENCY = \"cryptography_vectors=={0}\".format(about['__version__'])\n\nrequirements = [\n    \"idna>=2.0\",\n    \"pyasn1>=0.1.8\",\n    \"six>=1.4.1\",\n    \"setuptools\",\n]\nsetup_requirements = []\n\nif sys.version_info < (3, 4):\n    requirements.append(\"enum34\")\n\nif sys.version_info < (3, 3):\n    requirements.append(\"ipaddress\")\n\nif platform.python_implementation() != \"PyPy\":\n    requirements.append(\"cffi>=1.1.0\")\n    setup_requirements.append(\"cffi>=1.1.0\")\n\n# If you add a new dep here you probably need to add it in the tox.ini as well\ntest_requirements = [\n    \"pytest\",\n    \"pretend\",\n    \"iso8601\",\n]\n\n# If there's no vectors locally that probably means we are in a tarball and\n# need to go and get the matching vectors package from PyPi\nif not os.path.exists(os.path.join(base_dir, \"vectors/setup.py\")):\n    test_requirements.append(VECTORS_DEPENDENCY)\n\n\ndef cc_is_available():\n    return sys.platform == \"darwin\" and list(map(\n        int, platform.mac_ver()[0].split(\".\"))) >= [10, 8, 0]\n\n\nbackends = [\n    \"openssl = cryptography.hazmat.backends.openssl:backend\"\n]\n\nif cc_is_available():\n    backends.append(\n        \"commoncrypto = cryptography.hazmat.backends.commoncrypto:backend\",\n    )\n\n\nclass PyTest(test):\n    def finalize_options(self):\n        test.finalize_options(self)\n        self.test_args = []\n        self.test_suite = True\n\n        # This means there's a vectors/ folder with the package in here.\n        # cd into it, install the vectors package and then refresh sys.path\n        if VECTORS_DEPENDENCY not in test_requirements:\n            subprocess.check_call(\n                [sys.executable, \"setup.py\", \"install\"], cwd=\"vectors\"\n            )\n            pkg_resources.get_distribution(\"cryptography_vectors\").activate()\n\n    def run_tests(self):\n        # Import here because in module scope the eggs are not loaded.\n        import pytest\n        test_args = [os.path.join(base_dir, \"tests\")]\n        errno = pytest.main(test_args)\n        sys.exit(errno)\n\n\ndef keywords_with_side_effects(argv):\n    \"\"\"\n    Get a dictionary with setup keywords that (can) have side effects.\n\n    :param argv: A list of strings with command line arguments.\n    :returns: A dictionary with keyword arguments for the ``setup()`` function.\n\n    This setup.py script uses the setuptools 'setup_requires' feature because\n    this is required by the cffi package to compile extension modules. The\n    purpose of ``keywords_with_side_effects()`` is to avoid triggering the cffi\n    build process as a result of setup.py invocations that don't need the cffi\n    module to be built (setup.py serves the dual purpose of exposing package\n    metadata).\n\n    All of the options listed by ``python setup.py --help`` that print\n    information should be recognized here. The commands ``clean``,\n    ``egg_info``, ``register``, ``sdist`` and ``upload`` are also recognized.\n    Any combination of these options and commands is also supported.\n\n    This function was originally based on the `setup.py script`_ of SciPy (see\n    also the discussion in `pip issue #25`_).\n\n    .. _pip issue #25: https://github.com/pypa/pip/issues/25\n    .. _setup.py script: https://github.com/scipy/scipy/blob/master/setup.py\n    \"\"\"\n    no_setup_requires_arguments = (\n        '-h', '--help',\n        '-n', '--dry-run',\n        '-q', '--quiet',\n        '-v', '--verbose',\n        '-V', '--version',\n        '--author',\n        '--author-email',\n        '--classifiers',\n        '--contact',\n        '--contact-email',\n        '--description',\n        '--egg-base',\n        '--fullname',\n        '--help-commands',\n        '--keywords',\n        '--licence',\n        '--license',\n        '--long-description',\n        '--maintainer',\n        '--maintainer-email',\n        '--name',\n        '--no-user-cfg',\n        '--obsoletes',\n        '--platforms',\n        '--provides',\n        '--requires',\n        '--url',\n        'clean',\n        'egg_info',\n        'register',\n        'sdist',\n        'upload',\n    )\n\n    def is_short_option(argument):\n        \"\"\"Check whether a command line argument is a short option.\"\"\"\n        return len(argument) >= 2 and argument[0] == '-' and argument[1] != '-'\n\n    def expand_short_options(argument):\n        \"\"\"Expand combined short options into canonical short options.\"\"\"\n        return ('-' + char for char in argument[1:])\n\n    def argument_without_setup_requirements(argv, i):\n        \"\"\"Check whether a command line argument needs setup requirements.\"\"\"\n        if argv[i] in no_setup_requires_arguments:\n            # Simple case: An argument which is either an option or a command\n            # which doesn't need setup requirements.\n            return True\n        elif (is_short_option(argv[i]) and\n              all(option in no_setup_requires_arguments\n                  for option in expand_short_options(argv[i]))):\n            # Not so simple case: Combined short options none of which need\n            # setup requirements.\n            return True\n        elif argv[i - 1:i] == ['--egg-base']:\n            # Tricky case: --egg-info takes an argument which should not make\n            # us use setup_requires (defeating the purpose of this code).\n            return True\n        else:\n            return False\n\n    if all(argument_without_setup_requirements(argv, i)\n           for i in range(1, len(argv))):\n        return {\n            \"cmdclass\": {\n                \"build\": DummyBuild,\n                \"install\": DummyInstall,\n                \"test\": DummyPyTest,\n            }\n        }\n    else:\n        cffi_modules = [\n            \"src/_cffi_src/build_openssl.py:ffi\",\n            \"src/_cffi_src/build_constant_time.py:ffi\",\n            \"src/_cffi_src/build_padding.py:ffi\",\n        ]\n        if cc_is_available():\n            cffi_modules.append(\"src/_cffi_src/build_commoncrypto.py:ffi\")\n\n        return {\n            \"setup_requires\": setup_requirements,\n            \"cmdclass\": {\n                \"test\": PyTest,\n            },\n            \"cffi_modules\": cffi_modules\n        }\n\n\nsetup_requires_error = (\"Requested setup command that needs 'setup_requires' \"\n                        \"while command line arguments implied a side effect \"\n                        \"free command or option.\")\n\n\nclass DummyBuild(build):\n    \"\"\"\n    This class makes it very obvious when ``keywords_with_side_effects()`` has\n    incorrectly interpreted the command line arguments to ``setup.py build`` as\n    one of the 'side effect free' commands or options.\n    \"\"\"\n\n    def run(self):\n        raise RuntimeError(setup_requires_error)\n\n\nclass DummyInstall(install):\n    \"\"\"\n    This class makes it very obvious when ``keywords_with_side_effects()`` has\n    incorrectly interpreted the command line arguments to ``setup.py install``\n    as one of the 'side effect free' commands or options.\n    \"\"\"\n\n    def run(self):\n        raise RuntimeError(setup_requires_error)\n\n\nclass DummyPyTest(test):\n    \"\"\"\n    This class makes it very obvious when ``keywords_with_side_effects()`` has\n    incorrectly interpreted the command line arguments to ``setup.py test`` as\n    one of the 'side effect free' commands or options.\n    \"\"\"\n\n    def run_tests(self):\n        raise RuntimeError(setup_requires_error)\n\n\nwith open(os.path.join(base_dir, \"README.rst\")) as f:\n    long_description = f.read()\n\n\nsetup(\n    name=about[\"__title__\"],\n    version=about[\"__version__\"],\n\n    description=about[\"__summary__\"],\n    long_description=long_description,\n    license=about[\"__license__\"],\n    url=about[\"__uri__\"],\n\n    author=about[\"__author__\"],\n    author_email=about[\"__email__\"],\n\n    classifiers=[\n        \"Intended Audience :: Developers\",\n        \"License :: OSI Approved :: Apache Software License\",\n        \"License :: OSI Approved :: BSD License\",\n        \"Natural Language :: English\",\n        \"Operating System :: MacOS :: MacOS X\",\n        \"Operating System :: POSIX\",\n        \"Operating System :: POSIX :: BSD\",\n        \"Operating System :: POSIX :: Linux\",\n        \"Operating System :: Microsoft :: Windows\",\n        \"Programming Language :: Python\",\n        \"Programming Language :: Python :: 2\",\n        \"Programming Language :: Python :: 2.6\",\n        \"Programming Language :: Python :: 2.7\",\n        \"Programming Language :: Python :: 3\",\n        \"Programming Language :: Python :: 3.3\",\n        \"Programming Language :: Python :: 3.4\",\n        \"Programming Language :: Python :: Implementation :: CPython\",\n        \"Programming Language :: Python :: Implementation :: PyPy\",\n        \"Topic :: Security :: Cryptography\",\n    ],\n\n    package_dir={\"\": \"src\"},\n    packages=find_packages(\n        where=\"src\", exclude=[\"_cffi_src\", \"_cffi_src.*\", \"tests\", \"tests.*\"]\n    ),\n    include_package_data=True,\n\n    install_requires=requirements,\n    tests_require=test_requirements,\n\n    # for cffi\n    zip_safe=False,\n    ext_package=\"cryptography.hazmat.bindings\",\n    entry_points={\n        \"cryptography.backends\": backends,\n    },\n    **keywords_with_side_effects(sys.argv)\n)\n", "path": "setup.py"}], "after_files": [{"content": "# This file is dual licensed under the terms of the Apache License, Version\n# 2.0, and the BSD License. See the LICENSE file in the root of this repository\n# for complete details.\n\nfrom __future__ import absolute_import, division, print_function\n\nimport os\nimport platform\nimport subprocess\nimport sys\nfrom distutils.command.build import build\n\nimport pkg_resources\n\nfrom setuptools import find_packages, setup\nfrom setuptools.command.install import install\nfrom setuptools.command.test import test\n\n\nbase_dir = os.path.dirname(__file__)\nsrc_dir = os.path.join(base_dir, \"src\")\n\n# When executing the setup.py, we need to be able to import ourselves, this\n# means that we need to add the src/ directory to the sys.path.\nsys.path.insert(0, src_dir)\n\nabout = {}\nwith open(os.path.join(src_dir, \"cryptography\", \"__about__.py\")) as f:\n    exec(f.read(), about)\n\n\nVECTORS_DEPENDENCY = \"cryptography_vectors=={0}\".format(about['__version__'])\n\nrequirements = [\n    \"idna>=2.0\",\n    \"pyasn1>=0.1.8\",\n    \"six>=1.4.1\",\n    \"setuptools\",\n]\nsetup_requirements = []\n\nif sys.version_info < (3, 4):\n    requirements.append(\"enum34\")\n\nif sys.version_info < (3, 3):\n    requirements.append(\"ipaddress\")\n\nif platform.python_implementation() == \"PyPy\":\n    if sys.pypy_version_info < (2, 6):\n        raise RuntimeError(\n            \"cryptography 1.0 is not compatible with PyPy < 2.6. Please \"\n            \"upgrade PyPy to use this library.\"\n        )\nelse:\n    requirements.append(\"cffi>=1.1.0\")\n    setup_requirements.append(\"cffi>=1.1.0\")\n\n# If you add a new dep here you probably need to add it in the tox.ini as well\ntest_requirements = [\n    \"pytest\",\n    \"pretend\",\n    \"iso8601\",\n]\n\n# If there's no vectors locally that probably means we are in a tarball and\n# need to go and get the matching vectors package from PyPi\nif not os.path.exists(os.path.join(base_dir, \"vectors/setup.py\")):\n    test_requirements.append(VECTORS_DEPENDENCY)\n\n\ndef cc_is_available():\n    return sys.platform == \"darwin\" and list(map(\n        int, platform.mac_ver()[0].split(\".\"))) >= [10, 8, 0]\n\n\nbackends = [\n    \"openssl = cryptography.hazmat.backends.openssl:backend\"\n]\n\nif cc_is_available():\n    backends.append(\n        \"commoncrypto = cryptography.hazmat.backends.commoncrypto:backend\",\n    )\n\n\nclass PyTest(test):\n    def finalize_options(self):\n        test.finalize_options(self)\n        self.test_args = []\n        self.test_suite = True\n\n        # This means there's a vectors/ folder with the package in here.\n        # cd into it, install the vectors package and then refresh sys.path\n        if VECTORS_DEPENDENCY not in test_requirements:\n            subprocess.check_call(\n                [sys.executable, \"setup.py\", \"install\"], cwd=\"vectors\"\n            )\n            pkg_resources.get_distribution(\"cryptography_vectors\").activate()\n\n    def run_tests(self):\n        # Import here because in module scope the eggs are not loaded.\n        import pytest\n        test_args = [os.path.join(base_dir, \"tests\")]\n        errno = pytest.main(test_args)\n        sys.exit(errno)\n\n\ndef keywords_with_side_effects(argv):\n    \"\"\"\n    Get a dictionary with setup keywords that (can) have side effects.\n\n    :param argv: A list of strings with command line arguments.\n    :returns: A dictionary with keyword arguments for the ``setup()`` function.\n\n    This setup.py script uses the setuptools 'setup_requires' feature because\n    this is required by the cffi package to compile extension modules. The\n    purpose of ``keywords_with_side_effects()`` is to avoid triggering the cffi\n    build process as a result of setup.py invocations that don't need the cffi\n    module to be built (setup.py serves the dual purpose of exposing package\n    metadata).\n\n    All of the options listed by ``python setup.py --help`` that print\n    information should be recognized here. The commands ``clean``,\n    ``egg_info``, ``register``, ``sdist`` and ``upload`` are also recognized.\n    Any combination of these options and commands is also supported.\n\n    This function was originally based on the `setup.py script`_ of SciPy (see\n    also the discussion in `pip issue #25`_).\n\n    .. _pip issue #25: https://github.com/pypa/pip/issues/25\n    .. _setup.py script: https://github.com/scipy/scipy/blob/master/setup.py\n    \"\"\"\n    no_setup_requires_arguments = (\n        '-h', '--help',\n        '-n', '--dry-run',\n        '-q', '--quiet',\n        '-v', '--verbose',\n        '-V', '--version',\n        '--author',\n        '--author-email',\n        '--classifiers',\n        '--contact',\n        '--contact-email',\n        '--description',\n        '--egg-base',\n        '--fullname',\n        '--help-commands',\n        '--keywords',\n        '--licence',\n        '--license',\n        '--long-description',\n        '--maintainer',\n        '--maintainer-email',\n        '--name',\n        '--no-user-cfg',\n        '--obsoletes',\n        '--platforms',\n        '--provides',\n        '--requires',\n        '--url',\n        'clean',\n        'egg_info',\n        'register',\n        'sdist',\n        'upload',\n    )\n\n    def is_short_option(argument):\n        \"\"\"Check whether a command line argument is a short option.\"\"\"\n        return len(argument) >= 2 and argument[0] == '-' and argument[1] != '-'\n\n    def expand_short_options(argument):\n        \"\"\"Expand combined short options into canonical short options.\"\"\"\n        return ('-' + char for char in argument[1:])\n\n    def argument_without_setup_requirements(argv, i):\n        \"\"\"Check whether a command line argument needs setup requirements.\"\"\"\n        if argv[i] in no_setup_requires_arguments:\n            # Simple case: An argument which is either an option or a command\n            # which doesn't need setup requirements.\n            return True\n        elif (is_short_option(argv[i]) and\n              all(option in no_setup_requires_arguments\n                  for option in expand_short_options(argv[i]))):\n            # Not so simple case: Combined short options none of which need\n            # setup requirements.\n            return True\n        elif argv[i - 1:i] == ['--egg-base']:\n            # Tricky case: --egg-info takes an argument which should not make\n            # us use setup_requires (defeating the purpose of this code).\n            return True\n        else:\n            return False\n\n    if all(argument_without_setup_requirements(argv, i)\n           for i in range(1, len(argv))):\n        return {\n            \"cmdclass\": {\n                \"build\": DummyBuild,\n                \"install\": DummyInstall,\n                \"test\": DummyPyTest,\n            }\n        }\n    else:\n        cffi_modules = [\n            \"src/_cffi_src/build_openssl.py:ffi\",\n            \"src/_cffi_src/build_constant_time.py:ffi\",\n            \"src/_cffi_src/build_padding.py:ffi\",\n        ]\n        if cc_is_available():\n            cffi_modules.append(\"src/_cffi_src/build_commoncrypto.py:ffi\")\n\n        return {\n            \"setup_requires\": setup_requirements,\n            \"cmdclass\": {\n                \"test\": PyTest,\n            },\n            \"cffi_modules\": cffi_modules\n        }\n\n\nsetup_requires_error = (\"Requested setup command that needs 'setup_requires' \"\n                        \"while command line arguments implied a side effect \"\n                        \"free command or option.\")\n\n\nclass DummyBuild(build):\n    \"\"\"\n    This class makes it very obvious when ``keywords_with_side_effects()`` has\n    incorrectly interpreted the command line arguments to ``setup.py build`` as\n    one of the 'side effect free' commands or options.\n    \"\"\"\n\n    def run(self):\n        raise RuntimeError(setup_requires_error)\n\n\nclass DummyInstall(install):\n    \"\"\"\n    This class makes it very obvious when ``keywords_with_side_effects()`` has\n    incorrectly interpreted the command line arguments to ``setup.py install``\n    as one of the 'side effect free' commands or options.\n    \"\"\"\n\n    def run(self):\n        raise RuntimeError(setup_requires_error)\n\n\nclass DummyPyTest(test):\n    \"\"\"\n    This class makes it very obvious when ``keywords_with_side_effects()`` has\n    incorrectly interpreted the command line arguments to ``setup.py test`` as\n    one of the 'side effect free' commands or options.\n    \"\"\"\n\n    def run_tests(self):\n        raise RuntimeError(setup_requires_error)\n\n\nwith open(os.path.join(base_dir, \"README.rst\")) as f:\n    long_description = f.read()\n\n\nsetup(\n    name=about[\"__title__\"],\n    version=about[\"__version__\"],\n\n    description=about[\"__summary__\"],\n    long_description=long_description,\n    license=about[\"__license__\"],\n    url=about[\"__uri__\"],\n\n    author=about[\"__author__\"],\n    author_email=about[\"__email__\"],\n\n    classifiers=[\n        \"Intended Audience :: Developers\",\n        \"License :: OSI Approved :: Apache Software License\",\n        \"License :: OSI Approved :: BSD License\",\n        \"Natural Language :: English\",\n        \"Operating System :: MacOS :: MacOS X\",\n        \"Operating System :: POSIX\",\n        \"Operating System :: POSIX :: BSD\",\n        \"Operating System :: POSIX :: Linux\",\n        \"Operating System :: Microsoft :: Windows\",\n        \"Programming Language :: Python\",\n        \"Programming Language :: Python :: 2\",\n        \"Programming Language :: Python :: 2.6\",\n        \"Programming Language :: Python :: 2.7\",\n        \"Programming Language :: Python :: 3\",\n        \"Programming Language :: Python :: 3.3\",\n        \"Programming Language :: Python :: 3.4\",\n        \"Programming Language :: Python :: Implementation :: CPython\",\n        \"Programming Language :: Python :: Implementation :: PyPy\",\n        \"Topic :: Security :: Cryptography\",\n    ],\n\n    package_dir={\"\": \"src\"},\n    packages=find_packages(\n        where=\"src\", exclude=[\"_cffi_src\", \"_cffi_src.*\", \"tests\", \"tests.*\"]\n    ),\n    include_package_data=True,\n\n    install_requires=requirements,\n    tests_require=test_requirements,\n\n    # for cffi\n    zip_safe=False,\n    ext_package=\"cryptography.hazmat.bindings\",\n    entry_points={\n        \"cryptography.backends\": backends,\n    },\n    **keywords_with_side_effects(sys.argv)\n)\n", "path": "setup.py"}]}