We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Redundant exclude in setup.py's find_packages
I think the call can be reduced from 

``` python
find_packages(
    where="src", exclude=["_cffi_src", "_cffi_src.*", "tests", "tests.*"]
)
```

to

``` python
find_packages(where="src", exclude=["_cffi_src", "_cffi_src.*"])
```

because of the `where="src"`. I verified by printing the output from setup.py


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

{"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -302,9 +302,7 @@\n     ],\n \n     package_dir={\"\": \"src\"},\n-    packages=find_packages(\n-        where=\"src\", exclude=[\"_cffi_src\", \"_cffi_src.*\", \"tests\", \"tests.*\"]\n-    ),\n+    packages=find_packages(where=\"src\", exclude=[\"_cffi_src\", \"_cffi_src.*\"]),\n     include_package_data=True,\n \n     install_requires=requirements,\n", "issue": "Redundant exclude in setup.py's find_packages\nI think the call can be reduced from \n\n``` python\nfind_packages(\n    where=\"src\", exclude=[\"_cffi_src\", \"_cffi_src.*\", \"tests\", \"tests.*\"]\n)\n```\n\nto\n\n``` python\nfind_packages(where=\"src\", exclude=[\"_cffi_src\", \"_cffi_src.*\"])\n```\n\nbecause of the `where=\"src\"`. I verified by printing the output from setup.py\n\n", "before_files": [{"content": "#!/usr/bin/env python\n\n# 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>=11.3\",\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.4.1\")\n    setup_requirements.append(\"cffi>=1.4.1\")\n\ntest_requirements = [\n    \"pytest\",\n    \"pretend\",\n    \"iso8601\",\n    \"pyasn1_modules\",\n]\nif sys.version_info[:2] > (2, 6):\n    test_requirements.append(\"hypothesis>=1.11.4\")\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 :: 3.5\",\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    extras_require={\n        \"test\": test_requirements,\n        \"docs-test\": [\n            \"doc8\",\n            \"pyenchant\",\n            \"readme_renderer\",\n            \"sphinx\",\n            \"sphinx_rtd_theme\",\n            \"sphinxcontrib-spelling\",\n        ],\n        \"pep8-test\": [\n            \"flake8\",\n            \"flake8-import-order\",\n            \"pep8-naming\",\n        ],\n    },\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": "#!/usr/bin/env python\n\n# 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>=11.3\",\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.4.1\")\n    setup_requirements.append(\"cffi>=1.4.1\")\n\ntest_requirements = [\n    \"pytest\",\n    \"pretend\",\n    \"iso8601\",\n    \"pyasn1_modules\",\n]\nif sys.version_info[:2] > (2, 6):\n    test_requirements.append(\"hypothesis>=1.11.4\")\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 :: 3.5\",\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(where=\"src\", exclude=[\"_cffi_src\", \"_cffi_src.*\"]),\n    include_package_data=True,\n\n    install_requires=requirements,\n    tests_require=test_requirements,\n    extras_require={\n        \"test\": test_requirements,\n        \"docs-test\": [\n            \"doc8\",\n            \"pyenchant\",\n            \"readme_renderer\",\n            \"sphinx\",\n            \"sphinx_rtd_theme\",\n            \"sphinxcontrib-spelling\",\n        ],\n        \"pep8-test\": [\n            \"flake8\",\n            \"flake8-import-order\",\n            \"pep8-naming\",\n        ],\n    },\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"}]}