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