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