We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Unable to 'pip install ipython' with PyPy 2.6.1 on OS X
Attempting to `pip install ipython` with PyPy 2.6.1 on OS X fails due to being unable to install gnureadline:

```
Failed to build gnureadline
Installing collected packages: decorator, path.py, pickleshare, simplegeneric, ipython-genutils, traitlets, pexpect, appnope, gnureadline, ipython
  Running setup.py install for gnureadline
    Complete output from command /Users/rouge8/.virtualenvs/tmp-62491ef39875e400/bin/python -c "import setuptools, tokenize;__file__='/private/var/folders/tv/tqsxmfzd7l5_5ys1jq3496hr0000gp/T/pip-build-MSyBT_/gnureadline/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/tv/tqsxmfzd7l5_5ys1jq3496hr0000gp/T/pip-Yzq13m-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/rouge8/.virtualenvs/tmp-62491ef39875e400/include/site/python2.7/gnureadline:
    running install
    running build
    running build_py
    running egg_info
    writing gnureadline.egg-info/PKG-INFO
    writing dependency_links to gnureadline.egg-info/dependency_links.txt
    writing top-level names to gnureadline.egg-info/top_level.txt
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'gnureadline.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'gnureadline.egg-info/SOURCES.txt'
    warning: build_py: byte-compiling is disabled, skipping.

    running build_ext
    building 'gnureadline' extension
    cc -arch x86_64 -O2 -fPIC -Wimplicit -DHAVE_RL_CALLBACK -DHAVE_RL_CATCH_SIGNAL -DHAVE_RL_COMPLETION_APPEND_CHARACTER -DHAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK -DHAVE_RL_COMPLETION_MATCHES -DHAVE_RL_COMPLETION_SUPPRESS_APPEND -DHAVE_RL_PRE_INPUT_HOOK -I. -I/Users/rouge8/.virtualenvs/tmp-62491ef39875e400/include -c Modules/2.x/readline.c -o build/temp.macosx-10.10-x86_64-2.7/Modules/2.x/readline.o
    Modules/2.x/readline.c:1057:21: error: use of undeclared identifier 'PyOS_InputHook'
        rl_event_hook = PyOS_InputHook;
                        ^
    Modules/2.x/readline.c:1170:5: error: use of undeclared identifier 'PyOS_ReadlineFunctionPointer'
        PyOS_ReadlineFunctionPointer = call_readline;
        ^
    2 errors generated.
    error: command 'cc' failed with exit status 1
```

Python version:

``` sh
$ python --version
Python 2.7.10 (f3ad1e1e1d6215e20d34bb65ab85ff9188c9f559, Sep 01 2015, 06:26:30)
[PyPy 2.6.1 with GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]
```

I was able to work around this by installing all of the IPython dependencies except for gnureadline and then running `pip install --no-deps ipython`, but obviously that's not ideal. :/


--- 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 # -*- coding: utf-8 -*-
3 """Setup script for IPython.
4 
5 Under Posix environments it works like a typical setup.py script.
6 Under Windows, the command sdist is not supported, since IPython
7 requires utilities which are not available under Windows."""
8 
9 #-----------------------------------------------------------------------------
10 #  Copyright (c) 2008-2011, IPython Development Team.
11 #  Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu>
12 #  Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>
13 #  Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>
14 #
15 #  Distributed under the terms of the Modified BSD License.
16 #
17 #  The full license is in the file COPYING.rst, distributed with this software.
18 #-----------------------------------------------------------------------------
19 
20 #-----------------------------------------------------------------------------
21 # Minimal Python version sanity check
22 #-----------------------------------------------------------------------------
23 from __future__ import print_function
24 
25 import sys
26 
27 # This check is also made in IPython/__init__, don't forget to update both when
28 # changing Python version requirements.
29 v = sys.version_info
30 if v[:2] < (2,7) or (v[0] >= 3 and v[:2] < (3,3)):
31     error = "ERROR: IPython requires Python version 2.7 or 3.3 or above."
32     print(error, file=sys.stderr)
33     sys.exit(1)
34 
35 PY3 = (sys.version_info[0] >= 3)
36 
37 # At least we're on the python version we need, move on.
38 
39 #-------------------------------------------------------------------------------
40 # Imports
41 #-------------------------------------------------------------------------------
42 
43 # Stdlib imports
44 import os
45 import shutil
46 
47 from glob import glob
48 
49 # BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
50 # update it when the contents of directories change.
51 if os.path.exists('MANIFEST'): os.remove('MANIFEST')
52 
53 from distutils.core import setup
54 
55 # Our own imports
56 from setupbase import target_update
57 
58 from setupbase import (
59     setup_args,
60     find_packages,
61     find_package_data,
62     check_package_data_first,
63     find_entry_points,
64     build_scripts_entrypt,
65     find_data_files,
66     git_prebuild,
67     install_symlinked,
68     install_lib_symlink,
69     install_scripts_for_symlink,
70     unsymlink,
71 )
72 
73 isfile = os.path.isfile
74 pjoin = os.path.join
75 
76 #-------------------------------------------------------------------------------
77 # Handle OS specific things
78 #-------------------------------------------------------------------------------
79 
80 if os.name in ('nt','dos'):
81     os_name = 'windows'
82 else:
83     os_name = os.name
84 
85 # Under Windows, 'sdist' has not been supported.  Now that the docs build with
86 # Sphinx it might work, but let's not turn it on until someone confirms that it
87 # actually works.
88 if os_name == 'windows' and 'sdist' in sys.argv:
89     print('The sdist command is not available under Windows.  Exiting.')
90     sys.exit(1)
91 
92 
93 #-------------------------------------------------------------------------------
94 # Things related to the IPython documentation
95 #-------------------------------------------------------------------------------
96 
97 # update the manuals when building a source dist
98 if len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'):
99 
100     # List of things to be updated. Each entry is a triplet of args for
101     # target_update()
102     to_update = [
103                  ('docs/man/ipython.1.gz',
104                   ['docs/man/ipython.1'],
105                   'cd docs/man && gzip -9c ipython.1 > ipython.1.gz'),
106                  ]
107 
108 
109     [ target_update(*t) for t in to_update ]
110 
111 #---------------------------------------------------------------------------
112 # Find all the packages, package data, and data_files
113 #---------------------------------------------------------------------------
114 
115 packages = find_packages()
116 package_data = find_package_data()
117 
118 data_files = find_data_files()
119 
120 setup_args['packages'] = packages
121 setup_args['package_data'] = package_data
122 setup_args['data_files'] = data_files
123 
124 #---------------------------------------------------------------------------
125 # custom distutils commands
126 #---------------------------------------------------------------------------
127 # imports here, so they are after setuptools import if there was one
128 from distutils.command.sdist import sdist
129 from distutils.command.upload import upload
130 
131 class UploadWindowsInstallers(upload):
132 
133     description = "Upload Windows installers to PyPI (only used from tools/release_windows.py)"
134     user_options = upload.user_options + [
135         ('files=', 'f', 'exe file (or glob) to upload')
136     ]
137     def initialize_options(self):
138         upload.initialize_options(self)
139         meta = self.distribution.metadata
140         base = '{name}-{version}'.format(
141             name=meta.get_name(),
142             version=meta.get_version()
143         )
144         self.files = os.path.join('dist', '%s.*.exe' % base)
145 
146     def run(self):
147         for dist_file in glob(self.files):
148             self.upload_file('bdist_wininst', 'any', dist_file)
149 
150 setup_args['cmdclass'] = {
151     'build_py': \
152             check_package_data_first(git_prebuild('IPython')),
153     'sdist' : git_prebuild('IPython', sdist),
154     'upload_wininst' : UploadWindowsInstallers,
155     'symlink': install_symlinked,
156     'install_lib_symlink': install_lib_symlink,
157     'install_scripts_sym': install_scripts_for_symlink,
158     'unsymlink': unsymlink,
159 }
160 
161 
162 #---------------------------------------------------------------------------
163 # Handle scripts, dependencies, and setuptools specific things
164 #---------------------------------------------------------------------------
165 
166 # For some commands, use setuptools.  Note that we do NOT list install here!
167 # If you want a setuptools-enhanced install, just run 'setupegg.py install'
168 needs_setuptools = set(('develop', 'release', 'bdist_egg', 'bdist_rpm',
169            'bdist', 'bdist_dumb', 'bdist_wininst', 'bdist_wheel',
170            'egg_info', 'easy_install', 'upload', 'install_egg_info',
171             ))
172 
173 if len(needs_setuptools.intersection(sys.argv)) > 0:
174     import setuptools
175 
176 # This dict is used for passing extra arguments that are setuptools
177 # specific to setup
178 setuptools_extra_args = {}
179 
180 # setuptools requirements
181 
182 extras_require = dict(
183     parallel = ['ipyparallel'],
184     qtconsole = ['qtconsole'],
185     doc = ['Sphinx>=1.1', 'numpydoc'],
186     test = ['nose>=0.10.1', 'requests', 'testpath'],
187     terminal = [],
188     kernel = ['ipykernel'],
189     nbformat = ['nbformat'],
190     notebook = ['notebook'],
191     nbconvert = ['nbconvert'],
192 )
193 install_requires = [
194     'decorator',
195     'pickleshare',
196     'simplegeneric>0.8',
197     'traitlets',
198 ]
199 
200 # Platform-specific dependencies:
201 # This is the correct way to specify these,
202 # but requires pip >= 6. pip < 6 ignores these.
203 extras_require.update({
204     ':sys_platform != "win32"': ['pexpect'],
205     ':sys_platform == "darwin"': ['appnope', 'gnureadline'],
206     'terminal:sys_platform == "win32"': ['pyreadline>=2'],
207     'test:python_version == "2.7"': ['mock'],
208 })
209 # FIXME: re-specify above platform dependencies for pip < 6
210 # These would result in non-portable bdists.
211 if not any(arg.startswith('bdist') for arg in sys.argv):
212     if sys.version_info < (3, 3):
213         extras_require['test'].append('mock')
214 
215     if sys.platform == 'darwin':
216         install_requires.extend(['appnope', 'gnureadline'])
217 
218     if sys.platform.startswith('win'):
219         extras_require['terminal'].append('pyreadline>=2.0')
220     else:
221         install_requires.append('pexpect')
222 
223 everything = set()
224 for key, deps in extras_require.items():
225     if ':' not in key:
226         everything.update(deps)
227 extras_require['all'] = everything
228 
229 if 'setuptools' in sys.modules:
230     setuptools_extra_args['zip_safe'] = False
231     setuptools_extra_args['entry_points'] = {
232         'console_scripts': find_entry_points(),
233         'pygments.lexers': [
234             'ipythonconsole = IPython.lib.lexers:IPythonConsoleLexer',
235             'ipython = IPython.lib.lexers:IPythonLexer',
236             'ipython3 = IPython.lib.lexers:IPython3Lexer',
237         ],
238     }
239     setup_args['extras_require'] = extras_require
240     requires = setup_args['install_requires'] = install_requires
241 
242     # Script to be run by the windows binary installer after the default setup
243     # routine, to add shortcuts and similar windows-only things.  Windows
244     # post-install scripts MUST reside in the scripts/ dir, otherwise distutils
245     # doesn't find them.
246     if 'bdist_wininst' in sys.argv:
247         if len(sys.argv) > 2 and \
248                ('sdist' in sys.argv or 'bdist_rpm' in sys.argv):
249             print("ERROR: bdist_wininst must be run alone. Exiting.", file=sys.stderr)
250             sys.exit(1)
251         setup_args['data_files'].append(
252             ['Scripts', ('scripts/ipython.ico', 'scripts/ipython_nb.ico')])
253         setup_args['scripts'] = [pjoin('scripts','ipython_win_post_install.py')]
254         setup_args['options'] = {"bdist_wininst":
255                                  {"install_script":
256                                   "ipython_win_post_install.py"}}
257 
258 else:
259     # scripts has to be a non-empty list, or install_scripts isn't called
260     setup_args['scripts'] = [e.split('=')[0].strip() for e in find_entry_points()]
261 
262     setup_args['cmdclass']['build_scripts'] = build_scripts_entrypt
263 
264 #---------------------------------------------------------------------------
265 # Do the actual setup now
266 #---------------------------------------------------------------------------
267 
268 setup_args.update(setuptools_extra_args)
269 
270 def main():
271     setup(**setup_args)
272 
273 if __name__ == '__main__':
274     main()
275
```
--- 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
@@ -200,9 +200,11 @@
 # Platform-specific dependencies:
 # This is the correct way to specify these,
 # but requires pip >= 6. pip < 6 ignores these.
+
 extras_require.update({
     ':sys_platform != "win32"': ['pexpect'],
-    ':sys_platform == "darwin"': ['appnope', 'gnureadline'],
+    ':sys_platform == "darwin"': ['appnope'],
+    ':sys_platform == "darwin" and platform_python_implementation == "CPython"': ['gnureadline'],
     'terminal:sys_platform == "win32"': ['pyreadline>=2'],
     'test:python_version == "2.7"': ['mock'],
 })
@@ -213,12 +215,30 @@
         extras_require['test'].append('mock')
 
     if sys.platform == 'darwin':
-        install_requires.extend(['appnope', 'gnureadline'])
+        install_requires.extend(['appnope'])
+        have_readline = False
+        try:
+            import readline
+        except ImportError:
+            pass
+        else:
+            if 'libedit' not in readline.__doc__:
+                have_readline = True
+        if not have_readline:
+            install_requires.extend(['gnureadline'])
 
     if sys.platform.startswith('win'):
         extras_require['terminal'].append('pyreadline>=2.0')
     else:
         install_requires.append('pexpect')
+    
+    # workaround pypa/setuptools#147, where setuptools misspells
+    # platform_python_implementation as python_implementation
+    if 'setuptools' in sys.modules:
+        for key in list(extras_require):
+            if 'platform_python_implementation' in key:
+                new_key = key.replace('platform_python_implementation', 'python_implementation')
+                extras_require[new_key] = extras_require.pop(key)
 
 everything = set()
 for key, deps in extras_require.items():

{"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -200,9 +200,11 @@\n # Platform-specific dependencies:\n # This is the correct way to specify these,\n # but requires pip >= 6. pip < 6 ignores these.\n+\n extras_require.update({\n     ':sys_platform != \"win32\"': ['pexpect'],\n-    ':sys_platform == \"darwin\"': ['appnope', 'gnureadline'],\n+    ':sys_platform == \"darwin\"': ['appnope'],\n+    ':sys_platform == \"darwin\" and platform_python_implementation == \"CPython\"': ['gnureadline'],\n     'terminal:sys_platform == \"win32\"': ['pyreadline>=2'],\n     'test:python_version == \"2.7\"': ['mock'],\n })\n@@ -213,12 +215,30 @@\n         extras_require['test'].append('mock')\n \n     if sys.platform == 'darwin':\n-        install_requires.extend(['appnope', 'gnureadline'])\n+        install_requires.extend(['appnope'])\n+        have_readline = False\n+        try:\n+            import readline\n+        except ImportError:\n+            pass\n+        else:\n+            if 'libedit' not in readline.__doc__:\n+                have_readline = True\n+        if not have_readline:\n+            install_requires.extend(['gnureadline'])\n \n     if sys.platform.startswith('win'):\n         extras_require['terminal'].append('pyreadline>=2.0')\n     else:\n         install_requires.append('pexpect')\n+    \n+    # workaround pypa/setuptools#147, where setuptools misspells\n+    # platform_python_implementation as python_implementation\n+    if 'setuptools' in sys.modules:\n+        for key in list(extras_require):\n+            if 'platform_python_implementation' in key:\n+                new_key = key.replace('platform_python_implementation', 'python_implementation')\n+                extras_require[new_key] = extras_require.pop(key)\n \n everything = set()\n for key, deps in extras_require.items():\n", "issue": "Unable to 'pip install ipython' with PyPy 2.6.1 on OS X\nAttempting to `pip install ipython` with PyPy 2.6.1 on OS X fails due to being unable to install gnureadline:\n\n```\nFailed to build gnureadline\nInstalling collected packages: decorator, path.py, pickleshare, simplegeneric, ipython-genutils, traitlets, pexpect, appnope, gnureadline, ipython\n  Running setup.py install for gnureadline\n    Complete output from command /Users/rouge8/.virtualenvs/tmp-62491ef39875e400/bin/python -c \"import setuptools, tokenize;__file__='/private/var/folders/tv/tqsxmfzd7l5_5ys1jq3496hr0000gp/T/pip-build-MSyBT_/gnureadline/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))\" install --record /var/folders/tv/tqsxmfzd7l5_5ys1jq3496hr0000gp/T/pip-Yzq13m-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/rouge8/.virtualenvs/tmp-62491ef39875e400/include/site/python2.7/gnureadline:\n    running install\n    running build\n    running build_py\n    running egg_info\n    writing gnureadline.egg-info/PKG-INFO\n    writing dependency_links to gnureadline.egg-info/dependency_links.txt\n    writing top-level names to gnureadline.egg-info/top_level.txt\n    warning: manifest_maker: standard file '-c' not found\n\n    reading manifest file 'gnureadline.egg-info/SOURCES.txt'\n    reading manifest template 'MANIFEST.in'\n    writing manifest file 'gnureadline.egg-info/SOURCES.txt'\n    warning: build_py: byte-compiling is disabled, skipping.\n\n    running build_ext\n    building 'gnureadline' extension\n    cc -arch x86_64 -O2 -fPIC -Wimplicit -DHAVE_RL_CALLBACK -DHAVE_RL_CATCH_SIGNAL -DHAVE_RL_COMPLETION_APPEND_CHARACTER -DHAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK -DHAVE_RL_COMPLETION_MATCHES -DHAVE_RL_COMPLETION_SUPPRESS_APPEND -DHAVE_RL_PRE_INPUT_HOOK -I. -I/Users/rouge8/.virtualenvs/tmp-62491ef39875e400/include -c Modules/2.x/readline.c -o build/temp.macosx-10.10-x86_64-2.7/Modules/2.x/readline.o\n    Modules/2.x/readline.c:1057:21: error: use of undeclared identifier 'PyOS_InputHook'\n        rl_event_hook = PyOS_InputHook;\n                        ^\n    Modules/2.x/readline.c:1170:5: error: use of undeclared identifier 'PyOS_ReadlineFunctionPointer'\n        PyOS_ReadlineFunctionPointer = call_readline;\n        ^\n    2 errors generated.\n    error: command 'cc' failed with exit status 1\n```\n\nPython version:\n\n``` sh\n$ python --version\nPython 2.7.10 (f3ad1e1e1d6215e20d34bb65ab85ff9188c9f559, Sep 01 2015, 06:26:30)\n[PyPy 2.6.1 with GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]\n```\n\nI was able to work around this by installing all of the IPython dependencies except for gnureadline and then running `pip install --no-deps ipython`, but obviously that's not ideal. :/\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"Setup script for IPython.\n\nUnder Posix environments it works like a typical setup.py script.\nUnder Windows, the command sdist is not supported, since IPython\nrequires utilities which are not available under Windows.\"\"\"\n\n#-----------------------------------------------------------------------------\n#  Copyright (c) 2008-2011, IPython Development Team.\n#  Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu>\n#  Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>\n#  Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>\n#\n#  Distributed under the terms of the Modified BSD License.\n#\n#  The full license is in the file COPYING.rst, distributed with this software.\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n# Minimal Python version sanity check\n#-----------------------------------------------------------------------------\nfrom __future__ import print_function\n\nimport sys\n\n# This check is also made in IPython/__init__, don't forget to update both when\n# changing Python version requirements.\nv = sys.version_info\nif v[:2] < (2,7) or (v[0] >= 3 and v[:2] < (3,3)):\n    error = \"ERROR: IPython requires Python version 2.7 or 3.3 or above.\"\n    print(error, file=sys.stderr)\n    sys.exit(1)\n\nPY3 = (sys.version_info[0] >= 3)\n\n# At least we're on the python version we need, move on.\n\n#-------------------------------------------------------------------------------\n# Imports\n#-------------------------------------------------------------------------------\n\n# Stdlib imports\nimport os\nimport shutil\n\nfrom glob import glob\n\n# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly\n# update it when the contents of directories change.\nif os.path.exists('MANIFEST'): os.remove('MANIFEST')\n\nfrom distutils.core import setup\n\n# Our own imports\nfrom setupbase import target_update\n\nfrom setupbase import (\n    setup_args,\n    find_packages,\n    find_package_data,\n    check_package_data_first,\n    find_entry_points,\n    build_scripts_entrypt,\n    find_data_files,\n    git_prebuild,\n    install_symlinked,\n    install_lib_symlink,\n    install_scripts_for_symlink,\n    unsymlink,\n)\n\nisfile = os.path.isfile\npjoin = os.path.join\n\n#-------------------------------------------------------------------------------\n# Handle OS specific things\n#-------------------------------------------------------------------------------\n\nif os.name in ('nt','dos'):\n    os_name = 'windows'\nelse:\n    os_name = os.name\n\n# Under Windows, 'sdist' has not been supported.  Now that the docs build with\n# Sphinx it might work, but let's not turn it on until someone confirms that it\n# actually works.\nif os_name == 'windows' and 'sdist' in sys.argv:\n    print('The sdist command is not available under Windows.  Exiting.')\n    sys.exit(1)\n\n\n#-------------------------------------------------------------------------------\n# Things related to the IPython documentation\n#-------------------------------------------------------------------------------\n\n# update the manuals when building a source dist\nif len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'):\n\n    # List of things to be updated. Each entry is a triplet of args for\n    # target_update()\n    to_update = [\n                 ('docs/man/ipython.1.gz',\n                  ['docs/man/ipython.1'],\n                  'cd docs/man && gzip -9c ipython.1 > ipython.1.gz'),\n                 ]\n\n\n    [ target_update(*t) for t in to_update ]\n\n#---------------------------------------------------------------------------\n# Find all the packages, package data, and data_files\n#---------------------------------------------------------------------------\n\npackages = find_packages()\npackage_data = find_package_data()\n\ndata_files = find_data_files()\n\nsetup_args['packages'] = packages\nsetup_args['package_data'] = package_data\nsetup_args['data_files'] = data_files\n\n#---------------------------------------------------------------------------\n# custom distutils commands\n#---------------------------------------------------------------------------\n# imports here, so they are after setuptools import if there was one\nfrom distutils.command.sdist import sdist\nfrom distutils.command.upload import upload\n\nclass UploadWindowsInstallers(upload):\n\n    description = \"Upload Windows installers to PyPI (only used from tools/release_windows.py)\"\n    user_options = upload.user_options + [\n        ('files=', 'f', 'exe file (or glob) to upload')\n    ]\n    def initialize_options(self):\n        upload.initialize_options(self)\n        meta = self.distribution.metadata\n        base = '{name}-{version}'.format(\n            name=meta.get_name(),\n            version=meta.get_version()\n        )\n        self.files = os.path.join('dist', '%s.*.exe' % base)\n\n    def run(self):\n        for dist_file in glob(self.files):\n            self.upload_file('bdist_wininst', 'any', dist_file)\n\nsetup_args['cmdclass'] = {\n    'build_py': \\\n            check_package_data_first(git_prebuild('IPython')),\n    'sdist' : git_prebuild('IPython', sdist),\n    'upload_wininst' : UploadWindowsInstallers,\n    'symlink': install_symlinked,\n    'install_lib_symlink': install_lib_symlink,\n    'install_scripts_sym': install_scripts_for_symlink,\n    'unsymlink': unsymlink,\n}\n\n\n#---------------------------------------------------------------------------\n# Handle scripts, dependencies, and setuptools specific things\n#---------------------------------------------------------------------------\n\n# For some commands, use setuptools.  Note that we do NOT list install here!\n# If you want a setuptools-enhanced install, just run 'setupegg.py install'\nneeds_setuptools = set(('develop', 'release', 'bdist_egg', 'bdist_rpm',\n           'bdist', 'bdist_dumb', 'bdist_wininst', 'bdist_wheel',\n           'egg_info', 'easy_install', 'upload', 'install_egg_info',\n            ))\n\nif len(needs_setuptools.intersection(sys.argv)) > 0:\n    import setuptools\n\n# This dict is used for passing extra arguments that are setuptools\n# specific to setup\nsetuptools_extra_args = {}\n\n# setuptools requirements\n\nextras_require = dict(\n    parallel = ['ipyparallel'],\n    qtconsole = ['qtconsole'],\n    doc = ['Sphinx>=1.1', 'numpydoc'],\n    test = ['nose>=0.10.1', 'requests', 'testpath'],\n    terminal = [],\n    kernel = ['ipykernel'],\n    nbformat = ['nbformat'],\n    notebook = ['notebook'],\n    nbconvert = ['nbconvert'],\n)\ninstall_requires = [\n    'decorator',\n    'pickleshare',\n    'simplegeneric>0.8',\n    'traitlets',\n]\n\n# Platform-specific dependencies:\n# This is the correct way to specify these,\n# but requires pip >= 6. pip < 6 ignores these.\nextras_require.update({\n    ':sys_platform != \"win32\"': ['pexpect'],\n    ':sys_platform == \"darwin\"': ['appnope', 'gnureadline'],\n    'terminal:sys_platform == \"win32\"': ['pyreadline>=2'],\n    'test:python_version == \"2.7\"': ['mock'],\n})\n# FIXME: re-specify above platform dependencies for pip < 6\n# These would result in non-portable bdists.\nif not any(arg.startswith('bdist') for arg in sys.argv):\n    if sys.version_info < (3, 3):\n        extras_require['test'].append('mock')\n\n    if sys.platform == 'darwin':\n        install_requires.extend(['appnope', 'gnureadline'])\n\n    if sys.platform.startswith('win'):\n        extras_require['terminal'].append('pyreadline>=2.0')\n    else:\n        install_requires.append('pexpect')\n\neverything = set()\nfor key, deps in extras_require.items():\n    if ':' not in key:\n        everything.update(deps)\nextras_require['all'] = everything\n\nif 'setuptools' in sys.modules:\n    setuptools_extra_args['zip_safe'] = False\n    setuptools_extra_args['entry_points'] = {\n        'console_scripts': find_entry_points(),\n        'pygments.lexers': [\n            'ipythonconsole = IPython.lib.lexers:IPythonConsoleLexer',\n            'ipython = IPython.lib.lexers:IPythonLexer',\n            'ipython3 = IPython.lib.lexers:IPython3Lexer',\n        ],\n    }\n    setup_args['extras_require'] = extras_require\n    requires = setup_args['install_requires'] = install_requires\n\n    # Script to be run by the windows binary installer after the default setup\n    # routine, to add shortcuts and similar windows-only things.  Windows\n    # post-install scripts MUST reside in the scripts/ dir, otherwise distutils\n    # doesn't find them.\n    if 'bdist_wininst' in sys.argv:\n        if len(sys.argv) > 2 and \\\n               ('sdist' in sys.argv or 'bdist_rpm' in sys.argv):\n            print(\"ERROR: bdist_wininst must be run alone. Exiting.\", file=sys.stderr)\n            sys.exit(1)\n        setup_args['data_files'].append(\n            ['Scripts', ('scripts/ipython.ico', 'scripts/ipython_nb.ico')])\n        setup_args['scripts'] = [pjoin('scripts','ipython_win_post_install.py')]\n        setup_args['options'] = {\"bdist_wininst\":\n                                 {\"install_script\":\n                                  \"ipython_win_post_install.py\"}}\n\nelse:\n    # scripts has to be a non-empty list, or install_scripts isn't called\n    setup_args['scripts'] = [e.split('=')[0].strip() for e in find_entry_points()]\n\n    setup_args['cmdclass']['build_scripts'] = build_scripts_entrypt\n\n#---------------------------------------------------------------------------\n# Do the actual setup now\n#---------------------------------------------------------------------------\n\nsetup_args.update(setuptools_extra_args)\n\ndef main():\n    setup(**setup_args)\n\nif __name__ == '__main__':\n    main()\n", "path": "setup.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"Setup script for IPython.\n\nUnder Posix environments it works like a typical setup.py script.\nUnder Windows, the command sdist is not supported, since IPython\nrequires utilities which are not available under Windows.\"\"\"\n\n#-----------------------------------------------------------------------------\n#  Copyright (c) 2008-2011, IPython Development Team.\n#  Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu>\n#  Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>\n#  Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>\n#\n#  Distributed under the terms of the Modified BSD License.\n#\n#  The full license is in the file COPYING.rst, distributed with this software.\n#-----------------------------------------------------------------------------\n\n#-----------------------------------------------------------------------------\n# Minimal Python version sanity check\n#-----------------------------------------------------------------------------\nfrom __future__ import print_function\n\nimport sys\n\n# This check is also made in IPython/__init__, don't forget to update both when\n# changing Python version requirements.\nv = sys.version_info\nif v[:2] < (2,7) or (v[0] >= 3 and v[:2] < (3,3)):\n    error = \"ERROR: IPython requires Python version 2.7 or 3.3 or above.\"\n    print(error, file=sys.stderr)\n    sys.exit(1)\n\nPY3 = (sys.version_info[0] >= 3)\n\n# At least we're on the python version we need, move on.\n\n#-------------------------------------------------------------------------------\n# Imports\n#-------------------------------------------------------------------------------\n\n# Stdlib imports\nimport os\nimport shutil\n\nfrom glob import glob\n\n# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly\n# update it when the contents of directories change.\nif os.path.exists('MANIFEST'): os.remove('MANIFEST')\n\nfrom distutils.core import setup\n\n# Our own imports\nfrom setupbase import target_update\n\nfrom setupbase import (\n    setup_args,\n    find_packages,\n    find_package_data,\n    check_package_data_first,\n    find_entry_points,\n    build_scripts_entrypt,\n    find_data_files,\n    git_prebuild,\n    install_symlinked,\n    install_lib_symlink,\n    install_scripts_for_symlink,\n    unsymlink,\n)\n\nisfile = os.path.isfile\npjoin = os.path.join\n\n#-------------------------------------------------------------------------------\n# Handle OS specific things\n#-------------------------------------------------------------------------------\n\nif os.name in ('nt','dos'):\n    os_name = 'windows'\nelse:\n    os_name = os.name\n\n# Under Windows, 'sdist' has not been supported.  Now that the docs build with\n# Sphinx it might work, but let's not turn it on until someone confirms that it\n# actually works.\nif os_name == 'windows' and 'sdist' in sys.argv:\n    print('The sdist command is not available under Windows.  Exiting.')\n    sys.exit(1)\n\n\n#-------------------------------------------------------------------------------\n# Things related to the IPython documentation\n#-------------------------------------------------------------------------------\n\n# update the manuals when building a source dist\nif len(sys.argv) >= 2 and sys.argv[1] in ('sdist','bdist_rpm'):\n\n    # List of things to be updated. Each entry is a triplet of args for\n    # target_update()\n    to_update = [\n                 ('docs/man/ipython.1.gz',\n                  ['docs/man/ipython.1'],\n                  'cd docs/man && gzip -9c ipython.1 > ipython.1.gz'),\n                 ]\n\n\n    [ target_update(*t) for t in to_update ]\n\n#---------------------------------------------------------------------------\n# Find all the packages, package data, and data_files\n#---------------------------------------------------------------------------\n\npackages = find_packages()\npackage_data = find_package_data()\n\ndata_files = find_data_files()\n\nsetup_args['packages'] = packages\nsetup_args['package_data'] = package_data\nsetup_args['data_files'] = data_files\n\n#---------------------------------------------------------------------------\n# custom distutils commands\n#---------------------------------------------------------------------------\n# imports here, so they are after setuptools import if there was one\nfrom distutils.command.sdist import sdist\nfrom distutils.command.upload import upload\n\nclass UploadWindowsInstallers(upload):\n\n    description = \"Upload Windows installers to PyPI (only used from tools/release_windows.py)\"\n    user_options = upload.user_options + [\n        ('files=', 'f', 'exe file (or glob) to upload')\n    ]\n    def initialize_options(self):\n        upload.initialize_options(self)\n        meta = self.distribution.metadata\n        base = '{name}-{version}'.format(\n            name=meta.get_name(),\n            version=meta.get_version()\n        )\n        self.files = os.path.join('dist', '%s.*.exe' % base)\n\n    def run(self):\n        for dist_file in glob(self.files):\n            self.upload_file('bdist_wininst', 'any', dist_file)\n\nsetup_args['cmdclass'] = {\n    'build_py': \\\n            check_package_data_first(git_prebuild('IPython')),\n    'sdist' : git_prebuild('IPython', sdist),\n    'upload_wininst' : UploadWindowsInstallers,\n    'symlink': install_symlinked,\n    'install_lib_symlink': install_lib_symlink,\n    'install_scripts_sym': install_scripts_for_symlink,\n    'unsymlink': unsymlink,\n}\n\n\n#---------------------------------------------------------------------------\n# Handle scripts, dependencies, and setuptools specific things\n#---------------------------------------------------------------------------\n\n# For some commands, use setuptools.  Note that we do NOT list install here!\n# If you want a setuptools-enhanced install, just run 'setupegg.py install'\nneeds_setuptools = set(('develop', 'release', 'bdist_egg', 'bdist_rpm',\n           'bdist', 'bdist_dumb', 'bdist_wininst', 'bdist_wheel',\n           'egg_info', 'easy_install', 'upload', 'install_egg_info',\n            ))\n\nif len(needs_setuptools.intersection(sys.argv)) > 0:\n    import setuptools\n\n# This dict is used for passing extra arguments that are setuptools\n# specific to setup\nsetuptools_extra_args = {}\n\n# setuptools requirements\n\nextras_require = dict(\n    parallel = ['ipyparallel'],\n    qtconsole = ['qtconsole'],\n    doc = ['Sphinx>=1.1', 'numpydoc'],\n    test = ['nose>=0.10.1', 'requests', 'testpath'],\n    terminal = [],\n    kernel = ['ipykernel'],\n    nbformat = ['nbformat'],\n    notebook = ['notebook'],\n    nbconvert = ['nbconvert'],\n)\ninstall_requires = [\n    'decorator',\n    'pickleshare',\n    'simplegeneric>0.8',\n    'traitlets',\n]\n\n# Platform-specific dependencies:\n# This is the correct way to specify these,\n# but requires pip >= 6. pip < 6 ignores these.\n\nextras_require.update({\n    ':sys_platform != \"win32\"': ['pexpect'],\n    ':sys_platform == \"darwin\"': ['appnope'],\n    ':sys_platform == \"darwin\" and platform_python_implementation == \"CPython\"': ['gnureadline'],\n    'terminal:sys_platform == \"win32\"': ['pyreadline>=2'],\n    'test:python_version == \"2.7\"': ['mock'],\n})\n# FIXME: re-specify above platform dependencies for pip < 6\n# These would result in non-portable bdists.\nif not any(arg.startswith('bdist') for arg in sys.argv):\n    if sys.version_info < (3, 3):\n        extras_require['test'].append('mock')\n\n    if sys.platform == 'darwin':\n        install_requires.extend(['appnope'])\n        have_readline = False\n        try:\n            import readline\n        except ImportError:\n            pass\n        else:\n            if 'libedit' not in readline.__doc__:\n                have_readline = True\n        if not have_readline:\n            install_requires.extend(['gnureadline'])\n\n    if sys.platform.startswith('win'):\n        extras_require['terminal'].append('pyreadline>=2.0')\n    else:\n        install_requires.append('pexpect')\n    \n    # workaround pypa/setuptools#147, where setuptools misspells\n    # platform_python_implementation as python_implementation\n    if 'setuptools' in sys.modules:\n        for key in list(extras_require):\n            if 'platform_python_implementation' in key:\n                new_key = key.replace('platform_python_implementation', 'python_implementation')\n                extras_require[new_key] = extras_require.pop(key)\n\neverything = set()\nfor key, deps in extras_require.items():\n    if ':' not in key:\n        everything.update(deps)\nextras_require['all'] = everything\n\nif 'setuptools' in sys.modules:\n    setuptools_extra_args['zip_safe'] = False\n    setuptools_extra_args['entry_points'] = {\n        'console_scripts': find_entry_points(),\n        'pygments.lexers': [\n            'ipythonconsole = IPython.lib.lexers:IPythonConsoleLexer',\n            'ipython = IPython.lib.lexers:IPythonLexer',\n            'ipython3 = IPython.lib.lexers:IPython3Lexer',\n        ],\n    }\n    setup_args['extras_require'] = extras_require\n    requires = setup_args['install_requires'] = install_requires\n\n    # Script to be run by the windows binary installer after the default setup\n    # routine, to add shortcuts and similar windows-only things.  Windows\n    # post-install scripts MUST reside in the scripts/ dir, otherwise distutils\n    # doesn't find them.\n    if 'bdist_wininst' in sys.argv:\n        if len(sys.argv) > 2 and \\\n               ('sdist' in sys.argv or 'bdist_rpm' in sys.argv):\n            print(\"ERROR: bdist_wininst must be run alone. Exiting.\", file=sys.stderr)\n            sys.exit(1)\n        setup_args['data_files'].append(\n            ['Scripts', ('scripts/ipython.ico', 'scripts/ipython_nb.ico')])\n        setup_args['scripts'] = [pjoin('scripts','ipython_win_post_install.py')]\n        setup_args['options'] = {\"bdist_wininst\":\n                                 {\"install_script\":\n                                  \"ipython_win_post_install.py\"}}\n\nelse:\n    # scripts has to be a non-empty list, or install_scripts isn't called\n    setup_args['scripts'] = [e.split('=')[0].strip() for e in find_entry_points()]\n\n    setup_args['cmdclass']['build_scripts'] = build_scripts_entrypt\n\n#---------------------------------------------------------------------------\n# Do the actual setup now\n#---------------------------------------------------------------------------\n\nsetup_args.update(setuptools_extra_args)\n\ndef main():\n    setup(**setup_args)\n\nif __name__ == '__main__':\n    main()\n", "path": "setup.py"}]}