We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Readlinelike display of options crashes ipython terminal.


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

{"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -196,7 +196,7 @@\n     'pickleshare',\n     'simplegeneric>0.8',\n     'traitlets>=4.2',\n-    'prompt_toolkit>=1.0.1,<2.0.0',\n+    'prompt_toolkit>=1.0.3,<2.0.0',\n     'pygments',\n ]\n", "issue": "Readlinelike display of options crashes ipython terminal.\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\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.3'],\n    test = ['nose>=0.10.1', 'requests', 'testpath', 'pygments', 'nbformat', 'ipykernel', 'numpy'],\n    terminal = [],\n    kernel = ['ipykernel'],\n    nbformat = ['nbformat'],\n    notebook = ['notebook', 'ipywidgets'],\n    nbconvert = ['nbconvert'],\n)\n\ninstall_requires = [\n    'setuptools>=18.5',\n    'decorator',\n    'pickleshare',\n    'simplegeneric>0.8',\n    'traitlets>=4.2',\n    'prompt_toolkit>=1.0.1,<2.0.0',\n    'pygments',\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    ':python_version == \"2.7\"': ['backports.shutil_get_terminal_size'],\n    ':python_version == \"2.7\" or python_version == \"3.3\"': ['pathlib2'],\n    ':sys_platform != \"win32\"': ['pexpect'],\n    ':sys_platform == \"darwin\"': ['appnope'],\n    ':sys_platform == \"win32\"': ['colorama', 'win_unicode_console'],\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\n\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\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.3'],\n    test = ['nose>=0.10.1', 'requests', 'testpath', 'pygments', 'nbformat', 'ipykernel', 'numpy'],\n    terminal = [],\n    kernel = ['ipykernel'],\n    nbformat = ['nbformat'],\n    notebook = ['notebook', 'ipywidgets'],\n    nbconvert = ['nbconvert'],\n)\n\ninstall_requires = [\n    'setuptools>=18.5',\n    'decorator',\n    'pickleshare',\n    'simplegeneric>0.8',\n    'traitlets>=4.2',\n    'prompt_toolkit>=1.0.3,<2.0.0',\n    'pygments',\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    ':python_version == \"2.7\"': ['backports.shutil_get_terminal_size'],\n    ':python_version == \"2.7\" or python_version == \"3.3\"': ['pathlib2'],\n    ':sys_platform != \"win32\"': ['pexpect'],\n    ':sys_platform == \"darwin\"': ['appnope'],\n    ':sys_platform == \"win32\"': ['colorama', 'win_unicode_console'],\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\n\n\ndef main():\n    setup(**setup_args)\n\nif __name__ == '__main__':\n    main()\n", "path": "setup.py"}]}