##// END OF EJS Templates
Update some docstrings
Thomas Kluyver -
Show More
@@ -1,747 +1,754 b''
1 # encoding: utf-8
1 # encoding: utf-8
2 """
2 """
3 This module defines the things that are used in setup.py for building IPython
3 This module defines the things that are used in setup.py for building IPython
4
4
5 This includes:
5 This includes:
6
6
7 * The basic arguments to setup
7 * The basic arguments to setup
8 * Functions for finding things like packages, package data, etc.
8 * Functions for finding things like packages, package data, etc.
9 * A function for checking dependencies.
9 * A function for checking dependencies.
10 """
10 """
11
11
12 # Copyright (c) IPython Development Team.
12 # Copyright (c) IPython Development Team.
13 # Distributed under the terms of the Modified BSD License.
13 # Distributed under the terms of the Modified BSD License.
14
14
15 from __future__ import print_function
15 from __future__ import print_function
16
16
17 import errno
17 import errno
18 import os
18 import os
19 import sys
19 import sys
20
20
21 from distutils import log
21 from distutils import log
22 from distutils.command.build_py import build_py
22 from distutils.command.build_py import build_py
23 from distutils.command.build_scripts import build_scripts
23 from distutils.command.build_scripts import build_scripts
24 from distutils.command.install import install
24 from distutils.command.install import install
25 from distutils.command.install_scripts import install_scripts
25 from distutils.command.install_scripts import install_scripts
26 from distutils.cmd import Command
26 from distutils.cmd import Command
27 from fnmatch import fnmatch
27 from fnmatch import fnmatch
28 from glob import glob
28 from glob import glob
29 from subprocess import check_call
29 from subprocess import check_call
30
30
31 from setupext import install_data_ext
31 from setupext import install_data_ext
32
32
33 #-------------------------------------------------------------------------------
33 #-------------------------------------------------------------------------------
34 # Useful globals and utility functions
34 # Useful globals and utility functions
35 #-------------------------------------------------------------------------------
35 #-------------------------------------------------------------------------------
36
36
37 # A few handy globals
37 # A few handy globals
38 isfile = os.path.isfile
38 isfile = os.path.isfile
39 pjoin = os.path.join
39 pjoin = os.path.join
40 repo_root = os.path.dirname(os.path.abspath(__file__))
40 repo_root = os.path.dirname(os.path.abspath(__file__))
41
41
42 def oscmd(s):
42 def oscmd(s):
43 print(">", s)
43 print(">", s)
44 os.system(s)
44 os.system(s)
45
45
46 # Py3 compatibility hacks, without assuming IPython itself is installed with
46 # Py3 compatibility hacks, without assuming IPython itself is installed with
47 # the full py3compat machinery.
47 # the full py3compat machinery.
48
48
49 try:
49 try:
50 execfile
50 execfile
51 except NameError:
51 except NameError:
52 def execfile(fname, globs, locs=None):
52 def execfile(fname, globs, locs=None):
53 locs = locs or globs
53 locs = locs or globs
54 exec(compile(open(fname).read(), fname, "exec"), globs, locs)
54 exec(compile(open(fname).read(), fname, "exec"), globs, locs)
55
55
56 # A little utility we'll need below, since glob() does NOT allow you to do
56 # A little utility we'll need below, since glob() does NOT allow you to do
57 # exclusion on multiple endings!
57 # exclusion on multiple endings!
58 def file_doesnt_endwith(test,endings):
58 def file_doesnt_endwith(test,endings):
59 """Return true if test is a file and its name does NOT end with any
59 """Return true if test is a file and its name does NOT end with any
60 of the strings listed in endings."""
60 of the strings listed in endings."""
61 if not isfile(test):
61 if not isfile(test):
62 return False
62 return False
63 for e in endings:
63 for e in endings:
64 if test.endswith(e):
64 if test.endswith(e):
65 return False
65 return False
66 return True
66 return True
67
67
68 #---------------------------------------------------------------------------
68 #---------------------------------------------------------------------------
69 # Basic project information
69 # Basic project information
70 #---------------------------------------------------------------------------
70 #---------------------------------------------------------------------------
71
71
72 # release.py contains version, authors, license, url, keywords, etc.
72 # release.py contains version, authors, license, url, keywords, etc.
73 execfile(pjoin(repo_root, 'IPython','core','release.py'), globals())
73 execfile(pjoin(repo_root, 'IPython','core','release.py'), globals())
74
74
75 # Create a dict with the basic information
75 # Create a dict with the basic information
76 # This dict is eventually passed to setup after additional keys are added.
76 # This dict is eventually passed to setup after additional keys are added.
77 setup_args = dict(
77 setup_args = dict(
78 name = name,
78 name = name,
79 version = version,
79 version = version,
80 description = description,
80 description = description,
81 long_description = long_description,
81 long_description = long_description,
82 author = author,
82 author = author,
83 author_email = author_email,
83 author_email = author_email,
84 url = url,
84 url = url,
85 download_url = download_url,
85 download_url = download_url,
86 license = license,
86 license = license,
87 platforms = platforms,
87 platforms = platforms,
88 keywords = keywords,
88 keywords = keywords,
89 classifiers = classifiers,
89 classifiers = classifiers,
90 cmdclass = {'install_data': install_data_ext},
90 cmdclass = {'install_data': install_data_ext},
91 )
91 )
92
92
93
93
94 #---------------------------------------------------------------------------
94 #---------------------------------------------------------------------------
95 # Find packages
95 # Find packages
96 #---------------------------------------------------------------------------
96 #---------------------------------------------------------------------------
97
97
98 def find_packages():
98 def find_packages():
99 """
99 """
100 Find all of IPython's packages.
100 Find all of IPython's packages.
101 """
101 """
102 excludes = ['deathrow', 'quarantine']
102 excludes = ['deathrow', 'quarantine']
103 packages = []
103 packages = []
104 for dir,subdirs,files in os.walk('IPython'):
104 for dir,subdirs,files in os.walk('IPython'):
105 package = dir.replace(os.path.sep, '.')
105 package = dir.replace(os.path.sep, '.')
106 if any(package.startswith('IPython.'+exc) for exc in excludes):
106 if any(package.startswith('IPython.'+exc) for exc in excludes):
107 # package is to be excluded (e.g. deathrow)
107 # package is to be excluded (e.g. deathrow)
108 continue
108 continue
109 if '__init__.py' not in files:
109 if '__init__.py' not in files:
110 # not a package
110 # not a package
111 continue
111 continue
112 packages.append(package)
112 packages.append(package)
113 return packages
113 return packages
114
114
115 #---------------------------------------------------------------------------
115 #---------------------------------------------------------------------------
116 # Find package data
116 # Find package data
117 #---------------------------------------------------------------------------
117 #---------------------------------------------------------------------------
118
118
119 def find_package_data():
119 def find_package_data():
120 """
120 """
121 Find IPython's package_data.
121 Find IPython's package_data.
122 """
122 """
123 # This is not enough for these things to appear in an sdist.
123 # This is not enough for these things to appear in an sdist.
124 # We need to muck with the MANIFEST to get this to work
124 # We need to muck with the MANIFEST to get this to work
125
125
126 # exclude components and less from the walk;
126 # exclude components and less from the walk;
127 # we will build the components separately
127 # we will build the components separately
128 excludes = [
128 excludes = [
129 pjoin('static', 'components'),
129 pjoin('static', 'components'),
130 pjoin('static', '*', 'less'),
130 pjoin('static', '*', 'less'),
131 ]
131 ]
132
132
133 # walk notebook resources:
133 # walk notebook resources:
134 cwd = os.getcwd()
134 cwd = os.getcwd()
135 os.chdir(os.path.join('IPython', 'html'))
135 os.chdir(os.path.join('IPython', 'html'))
136 static_data = []
136 static_data = []
137 for parent, dirs, files in os.walk('static'):
137 for parent, dirs, files in os.walk('static'):
138 if any(fnmatch(parent, pat) for pat in excludes):
138 if any(fnmatch(parent, pat) for pat in excludes):
139 # prevent descending into subdirs
139 # prevent descending into subdirs
140 dirs[:] = []
140 dirs[:] = []
141 continue
141 continue
142 for f in files:
142 for f in files:
143 static_data.append(pjoin(parent, f))
143 static_data.append(pjoin(parent, f))
144
144
145 components = pjoin("static", "components")
145 components = pjoin("static", "components")
146 # select the components we actually need to install
146 # select the components we actually need to install
147 # (there are lots of resources we bundle for sdist-reasons that we don't actually use)
147 # (there are lots of resources we bundle for sdist-reasons that we don't actually use)
148 static_data.extend([
148 static_data.extend([
149 pjoin(components, "backbone", "backbone-min.js"),
149 pjoin(components, "backbone", "backbone-min.js"),
150 pjoin(components, "bootstrap", "js", "bootstrap.min.js"),
150 pjoin(components, "bootstrap", "js", "bootstrap.min.js"),
151 pjoin(components, "bootstrap-tour", "build", "css", "bootstrap-tour.min.css"),
151 pjoin(components, "bootstrap-tour", "build", "css", "bootstrap-tour.min.css"),
152 pjoin(components, "bootstrap-tour", "build", "js", "bootstrap-tour.min.js"),
152 pjoin(components, "bootstrap-tour", "build", "js", "bootstrap-tour.min.js"),
153 pjoin(components, "font-awesome", "fonts", "*.*"),
153 pjoin(components, "font-awesome", "fonts", "*.*"),
154 pjoin(components, "google-caja", "html-css-sanitizer-minified.js"),
154 pjoin(components, "google-caja", "html-css-sanitizer-minified.js"),
155 pjoin(components, "highlight.js", "build", "highlight.pack.js"),
155 pjoin(components, "highlight.js", "build", "highlight.pack.js"),
156 pjoin(components, "jquery", "jquery.min.js"),
156 pjoin(components, "jquery", "jquery.min.js"),
157 pjoin(components, "jquery-ui", "ui", "minified", "jquery-ui.min.js"),
157 pjoin(components, "jquery-ui", "ui", "minified", "jquery-ui.min.js"),
158 pjoin(components, "jquery-ui", "themes", "smoothness", "jquery-ui.min.css"),
158 pjoin(components, "jquery-ui", "themes", "smoothness", "jquery-ui.min.css"),
159 pjoin(components, "jquery-ui", "themes", "smoothness", "images", "*"),
159 pjoin(components, "jquery-ui", "themes", "smoothness", "images", "*"),
160 pjoin(components, "marked", "lib", "marked.js"),
160 pjoin(components, "marked", "lib", "marked.js"),
161 pjoin(components, "requirejs", "require.js"),
161 pjoin(components, "requirejs", "require.js"),
162 pjoin(components, "underscore", "underscore-min.js"),
162 pjoin(components, "underscore", "underscore-min.js"),
163 pjoin(components, "moment", "moment.js"),
163 pjoin(components, "moment", "moment.js"),
164 pjoin(components, "moment", "min", "moment.min.js"),
164 pjoin(components, "moment", "min", "moment.min.js"),
165 pjoin(components, "term.js", "src", "term.js"),
165 pjoin(components, "term.js", "src", "term.js"),
166 pjoin(components, "text-encoding", "lib", "encoding.js"),
166 pjoin(components, "text-encoding", "lib", "encoding.js"),
167 ])
167 ])
168
168
169 # Ship all of Codemirror's CSS and JS
169 # Ship all of Codemirror's CSS and JS
170 for parent, dirs, files in os.walk(pjoin(components, 'codemirror')):
170 for parent, dirs, files in os.walk(pjoin(components, 'codemirror')):
171 for f in files:
171 for f in files:
172 if f.endswith(('.js', '.css')):
172 if f.endswith(('.js', '.css')):
173 static_data.append(pjoin(parent, f))
173 static_data.append(pjoin(parent, f))
174
174
175 os.chdir(os.path.join('tests',))
175 os.chdir(os.path.join('tests',))
176 js_tests = glob('*.js') + glob('*/*.js')
176 js_tests = glob('*.js') + glob('*/*.js')
177
177
178 os.chdir(os.path.join(cwd, 'IPython', 'nbconvert'))
178 os.chdir(os.path.join(cwd, 'IPython', 'nbconvert'))
179 nbconvert_templates = [os.path.join(dirpath, '*.*')
179 nbconvert_templates = [os.path.join(dirpath, '*.*')
180 for dirpath, _, _ in os.walk('templates')]
180 for dirpath, _, _ in os.walk('templates')]
181
181
182 os.chdir(cwd)
182 os.chdir(cwd)
183
183
184 package_data = {
184 package_data = {
185 'IPython.config.profile' : ['README*', '*/*.py'],
185 'IPython.config.profile' : ['README*', '*/*.py'],
186 'IPython.core.tests' : ['*.png', '*.jpg'],
186 'IPython.core.tests' : ['*.png', '*.jpg'],
187 'IPython.lib.tests' : ['*.wav'],
187 'IPython.lib.tests' : ['*.wav'],
188 'IPython.testing.plugin' : ['*.txt'],
188 'IPython.testing.plugin' : ['*.txt'],
189 'IPython.html' : ['templates/*'] + static_data,
189 'IPython.html' : ['templates/*'] + static_data,
190 'IPython.html.tests' : js_tests,
190 'IPython.html.tests' : js_tests,
191 'IPython.qt.console' : ['resources/icon/*.svg'],
191 'IPython.qt.console' : ['resources/icon/*.svg'],
192 'IPython.nbconvert' : nbconvert_templates +
192 'IPython.nbconvert' : nbconvert_templates +
193 [
193 [
194 'tests/files/*.*',
194 'tests/files/*.*',
195 'exporters/tests/files/*.*',
195 'exporters/tests/files/*.*',
196 'preprocessors/tests/files/*.*',
196 'preprocessors/tests/files/*.*',
197 ],
197 ],
198 'IPython.nbconvert.filters' : ['marked.js'],
198 'IPython.nbconvert.filters' : ['marked.js'],
199 'IPython.nbformat' : [
199 'IPython.nbformat' : [
200 'tests/*.ipynb',
200 'tests/*.ipynb',
201 'v3/nbformat.v3.schema.json',
201 'v3/nbformat.v3.schema.json',
202 'v4/nbformat.v4.schema.json',
202 'v4/nbformat.v4.schema.json',
203 ]
203 ]
204 }
204 }
205
205
206 return package_data
206 return package_data
207
207
208
208
209 def check_package_data(package_data):
209 def check_package_data(package_data):
210 """verify that package_data globs make sense"""
210 """verify that package_data globs make sense"""
211 print("checking package data")
211 print("checking package data")
212 for pkg, data in package_data.items():
212 for pkg, data in package_data.items():
213 pkg_root = pjoin(*pkg.split('.'))
213 pkg_root = pjoin(*pkg.split('.'))
214 for d in data:
214 for d in data:
215 path = pjoin(pkg_root, d)
215 path = pjoin(pkg_root, d)
216 if '*' in path:
216 if '*' in path:
217 assert len(glob(path)) > 0, "No files match pattern %s" % path
217 assert len(glob(path)) > 0, "No files match pattern %s" % path
218 else:
218 else:
219 assert os.path.exists(path), "Missing package data: %s" % path
219 assert os.path.exists(path), "Missing package data: %s" % path
220
220
221
221
222 def check_package_data_first(command):
222 def check_package_data_first(command):
223 """decorator for checking package_data before running a given command
223 """decorator for checking package_data before running a given command
224
224
225 Probably only needs to wrap build_py
225 Probably only needs to wrap build_py
226 """
226 """
227 class DecoratedCommand(command):
227 class DecoratedCommand(command):
228 def run(self):
228 def run(self):
229 check_package_data(self.package_data)
229 check_package_data(self.package_data)
230 command.run(self)
230 command.run(self)
231 return DecoratedCommand
231 return DecoratedCommand
232
232
233
233
234 #---------------------------------------------------------------------------
234 #---------------------------------------------------------------------------
235 # Find data files
235 # Find data files
236 #---------------------------------------------------------------------------
236 #---------------------------------------------------------------------------
237
237
238 def make_dir_struct(tag,base,out_base):
238 def make_dir_struct(tag,base,out_base):
239 """Make the directory structure of all files below a starting dir.
239 """Make the directory structure of all files below a starting dir.
240
240
241 This is just a convenience routine to help build a nested directory
241 This is just a convenience routine to help build a nested directory
242 hierarchy because distutils is too stupid to do this by itself.
242 hierarchy because distutils is too stupid to do this by itself.
243
243
244 XXX - this needs a proper docstring!
244 XXX - this needs a proper docstring!
245 """
245 """
246
246
247 # we'll use these a lot below
247 # we'll use these a lot below
248 lbase = len(base)
248 lbase = len(base)
249 pathsep = os.path.sep
249 pathsep = os.path.sep
250 lpathsep = len(pathsep)
250 lpathsep = len(pathsep)
251
251
252 out = []
252 out = []
253 for (dirpath,dirnames,filenames) in os.walk(base):
253 for (dirpath,dirnames,filenames) in os.walk(base):
254 # we need to strip out the dirpath from the base to map it to the
254 # we need to strip out the dirpath from the base to map it to the
255 # output (installation) path. This requires possibly stripping the
255 # output (installation) path. This requires possibly stripping the
256 # path separator, because otherwise pjoin will not work correctly
256 # path separator, because otherwise pjoin will not work correctly
257 # (pjoin('foo/','/bar') returns '/bar').
257 # (pjoin('foo/','/bar') returns '/bar').
258
258
259 dp_eff = dirpath[lbase:]
259 dp_eff = dirpath[lbase:]
260 if dp_eff.startswith(pathsep):
260 if dp_eff.startswith(pathsep):
261 dp_eff = dp_eff[lpathsep:]
261 dp_eff = dp_eff[lpathsep:]
262 # The output path must be anchored at the out_base marker
262 # The output path must be anchored at the out_base marker
263 out_path = pjoin(out_base,dp_eff)
263 out_path = pjoin(out_base,dp_eff)
264 # Now we can generate the final filenames. Since os.walk only produces
264 # Now we can generate the final filenames. Since os.walk only produces
265 # filenames, we must join back with the dirpath to get full valid file
265 # filenames, we must join back with the dirpath to get full valid file
266 # paths:
266 # paths:
267 pfiles = [pjoin(dirpath,f) for f in filenames]
267 pfiles = [pjoin(dirpath,f) for f in filenames]
268 # Finally, generate the entry we need, which is a pari of (output
268 # Finally, generate the entry we need, which is a pari of (output
269 # path, files) for use as a data_files parameter in install_data.
269 # path, files) for use as a data_files parameter in install_data.
270 out.append((out_path, pfiles))
270 out.append((out_path, pfiles))
271
271
272 return out
272 return out
273
273
274
274
275 def find_data_files():
275 def find_data_files():
276 """
276 """
277 Find IPython's data_files.
277 Find IPython's data_files.
278
278
279 Just man pages at this point.
279 Just man pages at this point.
280 """
280 """
281
281
282 manpagebase = pjoin('share', 'man', 'man1')
282 manpagebase = pjoin('share', 'man', 'man1')
283
283
284 # Simple file lists can be made by hand
284 # Simple file lists can be made by hand
285 manpages = [f for f in glob(pjoin('docs','man','*.1.gz')) if isfile(f)]
285 manpages = [f for f in glob(pjoin('docs','man','*.1.gz')) if isfile(f)]
286 if not manpages:
286 if not manpages:
287 # When running from a source tree, the manpages aren't gzipped
287 # When running from a source tree, the manpages aren't gzipped
288 manpages = [f for f in glob(pjoin('docs','man','*.1')) if isfile(f)]
288 manpages = [f for f in glob(pjoin('docs','man','*.1')) if isfile(f)]
289
289
290 # And assemble the entire output list
290 # And assemble the entire output list
291 data_files = [ (manpagebase, manpages) ]
291 data_files = [ (manpagebase, manpages) ]
292
292
293 return data_files
293 return data_files
294
294
295
295
296 def make_man_update_target(manpage):
296 def make_man_update_target(manpage):
297 """Return a target_update-compliant tuple for the given manpage.
297 """Return a target_update-compliant tuple for the given manpage.
298
298
299 Parameters
299 Parameters
300 ----------
300 ----------
301 manpage : string
301 manpage : string
302 Name of the manpage, must include the section number (trailing number).
302 Name of the manpage, must include the section number (trailing number).
303
303
304 Example
304 Example
305 -------
305 -------
306
306
307 >>> make_man_update_target('ipython.1') #doctest: +NORMALIZE_WHITESPACE
307 >>> make_man_update_target('ipython.1') #doctest: +NORMALIZE_WHITESPACE
308 ('docs/man/ipython.1.gz',
308 ('docs/man/ipython.1.gz',
309 ['docs/man/ipython.1'],
309 ['docs/man/ipython.1'],
310 'cd docs/man && gzip -9c ipython.1 > ipython.1.gz')
310 'cd docs/man && gzip -9c ipython.1 > ipython.1.gz')
311 """
311 """
312 man_dir = pjoin('docs', 'man')
312 man_dir = pjoin('docs', 'man')
313 manpage_gz = manpage + '.gz'
313 manpage_gz = manpage + '.gz'
314 manpath = pjoin(man_dir, manpage)
314 manpath = pjoin(man_dir, manpage)
315 manpath_gz = pjoin(man_dir, manpage_gz)
315 manpath_gz = pjoin(man_dir, manpage_gz)
316 gz_cmd = ( "cd %(man_dir)s && gzip -9c %(manpage)s > %(manpage_gz)s" %
316 gz_cmd = ( "cd %(man_dir)s && gzip -9c %(manpage)s > %(manpage_gz)s" %
317 locals() )
317 locals() )
318 return (manpath_gz, [manpath], gz_cmd)
318 return (manpath_gz, [manpath], gz_cmd)
319
319
320 # The two functions below are copied from IPython.utils.path, so we don't need
320 # The two functions below are copied from IPython.utils.path, so we don't need
321 # to import IPython during setup, which fails on Python 3.
321 # to import IPython during setup, which fails on Python 3.
322
322
323 def target_outdated(target,deps):
323 def target_outdated(target,deps):
324 """Determine whether a target is out of date.
324 """Determine whether a target is out of date.
325
325
326 target_outdated(target,deps) -> 1/0
326 target_outdated(target,deps) -> 1/0
327
327
328 deps: list of filenames which MUST exist.
328 deps: list of filenames which MUST exist.
329 target: single filename which may or may not exist.
329 target: single filename which may or may not exist.
330
330
331 If target doesn't exist or is older than any file listed in deps, return
331 If target doesn't exist or is older than any file listed in deps, return
332 true, otherwise return false.
332 true, otherwise return false.
333 """
333 """
334 try:
334 try:
335 target_time = os.path.getmtime(target)
335 target_time = os.path.getmtime(target)
336 except os.error:
336 except os.error:
337 return 1
337 return 1
338 for dep in deps:
338 for dep in deps:
339 dep_time = os.path.getmtime(dep)
339 dep_time = os.path.getmtime(dep)
340 if dep_time > target_time:
340 if dep_time > target_time:
341 #print "For target",target,"Dep failed:",dep # dbg
341 #print "For target",target,"Dep failed:",dep # dbg
342 #print "times (dep,tar):",dep_time,target_time # dbg
342 #print "times (dep,tar):",dep_time,target_time # dbg
343 return 1
343 return 1
344 return 0
344 return 0
345
345
346
346
347 def target_update(target,deps,cmd):
347 def target_update(target,deps,cmd):
348 """Update a target with a given command given a list of dependencies.
348 """Update a target with a given command given a list of dependencies.
349
349
350 target_update(target,deps,cmd) -> runs cmd if target is outdated.
350 target_update(target,deps,cmd) -> runs cmd if target is outdated.
351
351
352 This is just a wrapper around target_outdated() which calls the given
352 This is just a wrapper around target_outdated() which calls the given
353 command if target is outdated."""
353 command if target is outdated."""
354
354
355 if target_outdated(target,deps):
355 if target_outdated(target,deps):
356 os.system(cmd)
356 os.system(cmd)
357
357
358 #---------------------------------------------------------------------------
358 #---------------------------------------------------------------------------
359 # Find scripts
359 # Find scripts
360 #---------------------------------------------------------------------------
360 #---------------------------------------------------------------------------
361
361
362 def find_entry_points():
362 def find_entry_points():
363 """Find IPython's scripts.
363 """Defines the command line entry points for IPython
364
364
365 if entry_points is True:
365 This always uses setuptools-style entry points. When setuptools is not in
366 return setuptools entry_point-style definitions
366 use, our own build_scripts_entrypt class below parses these and builds
367 else:
367 command line scripts.
368 return file paths of plain scripts [default]
369
368
370 suffix is appended to script names if entry_points is True, so that the
369 Each of our entry points gets both a plain name, e.g. ipython, and one
371 Python 3 scripts get named "ipython3" etc.
370 suffixed with the Python major version number, e.g. ipython3.
372 """
371 """
373 ep = [
372 ep = [
374 'ipython%s = IPython:start_ipython',
373 'ipython%s = IPython:start_ipython',
375 'ipcontroller%s = IPython.parallel.apps.ipcontrollerapp:launch_new_instance',
374 'ipcontroller%s = IPython.parallel.apps.ipcontrollerapp:launch_new_instance',
376 'ipengine%s = IPython.parallel.apps.ipengineapp:launch_new_instance',
375 'ipengine%s = IPython.parallel.apps.ipengineapp:launch_new_instance',
377 'ipcluster%s = IPython.parallel.apps.ipclusterapp:launch_new_instance',
376 'ipcluster%s = IPython.parallel.apps.ipclusterapp:launch_new_instance',
378 'iptest%s = IPython.testing.iptestcontroller:main',
377 'iptest%s = IPython.testing.iptestcontroller:main',
379 ]
378 ]
380 suffix = str(sys.version_info[0])
379 suffix = str(sys.version_info[0])
381 return [e % '' for e in ep] + [e % suffix for e in ep]
380 return [e % '' for e in ep] + [e % suffix for e in ep]
382
381
383 script_src = """#!{executable}
382 script_src = """#!{executable}
384 # This script was automatically generated by setup.py
383 # This script was automatically generated by setup.py
385 if __name__ == '__main__':
384 if __name__ == '__main__':
386 from {mod} import {func}
385 from {mod} import {func}
387 {func}()
386 {func}()
388 """
387 """
389
388
390 class build_scripts_entrypt(build_scripts):
389 class build_scripts_entrypt(build_scripts):
390 """Build the command line scripts
391
392 Parse setuptools style entry points and write simple scripts to run the
393 target functions.
394
395 On Windows, this also creates .cmd wrappers for the scripts so that you can
396 easily launch them from a command line.
397 """
391 def run(self):
398 def run(self):
392 self.mkpath(self.build_dir)
399 self.mkpath(self.build_dir)
393 outfiles = []
400 outfiles = []
394 for script in find_entry_points():
401 for script in find_entry_points():
395 name, entrypt = script.split('=')
402 name, entrypt = script.split('=')
396 name = name.strip()
403 name = name.strip()
397 entrypt = entrypt.strip()
404 entrypt = entrypt.strip()
398 outfile = os.path.join(self.build_dir, name)
405 outfile = os.path.join(self.build_dir, name)
399 outfiles.append(outfile)
406 outfiles.append(outfile)
400 print('Writing script to', outfile)
407 print('Writing script to', outfile)
401
408
402 mod, func = entrypt.split(':')
409 mod, func = entrypt.split(':')
403 with open(outfile, 'w') as f:
410 with open(outfile, 'w') as f:
404 f.write(script_src.format(executable=sys.executable,
411 f.write(script_src.format(executable=sys.executable,
405 mod=mod, func=func))
412 mod=mod, func=func))
406
413
407 if sys.platform == 'win32':
414 if sys.platform == 'win32':
408 # Write .cmd wrappers for Windows so 'ipython' etc. work at the
415 # Write .cmd wrappers for Windows so 'ipython' etc. work at the
409 # command line
416 # command line
410 cmd_file = os.path.join(self.build_dir, name + '.cmd')
417 cmd_file = os.path.join(self.build_dir, name + '.cmd')
411 cmd = '@"{python}" "%~dp0\{script}" %*\r\n'.format(
418 cmd = '@"{python}" "%~dp0\{script}" %*\r\n'.format(
412 python=sys.executable, script=name)
419 python=sys.executable, script=name)
413 log.info("Writing %s wrapper script" % cmd_file)
420 log.info("Writing %s wrapper script" % cmd_file)
414 with open(cmd_file, 'w') as f:
421 with open(cmd_file, 'w') as f:
415 f.write(cmd)
422 f.write(cmd)
416
423
417 return outfiles, outfiles
424 return outfiles, outfiles
418
425
419 class install_lib_symlink(Command):
426 class install_lib_symlink(Command):
420 user_options = [
427 user_options = [
421 ('install-dir=', 'd', "directory to install to"),
428 ('install-dir=', 'd', "directory to install to"),
422 ]
429 ]
423
430
424 def initialize_options(self):
431 def initialize_options(self):
425 self.install_dir = None
432 self.install_dir = None
426
433
427 def finalize_options(self):
434 def finalize_options(self):
428 self.set_undefined_options('symlink',
435 self.set_undefined_options('symlink',
429 ('install_lib', 'install_dir'),
436 ('install_lib', 'install_dir'),
430 )
437 )
431
438
432 def run(self):
439 def run(self):
433 if sys.platform == 'win32':
440 if sys.platform == 'win32':
434 raise Exception("This doesn't work on Windows.")
441 raise Exception("This doesn't work on Windows.")
435 pkg = os.path.join(os.getcwd(), 'IPython')
442 pkg = os.path.join(os.getcwd(), 'IPython')
436 dest = os.path.join(self.install_dir, 'IPython')
443 dest = os.path.join(self.install_dir, 'IPython')
437 if os.path.islink(dest):
444 if os.path.islink(dest):
438 print('removing existing symlink at %s' % dest)
445 print('removing existing symlink at %s' % dest)
439 os.unlink(dest)
446 os.unlink(dest)
440 print('symlinking %s -> %s' % (pkg, dest))
447 print('symlinking %s -> %s' % (pkg, dest))
441 os.symlink(pkg, dest)
448 os.symlink(pkg, dest)
442
449
443 class unsymlink(install):
450 class unsymlink(install):
444 def run(self):
451 def run(self):
445 dest = os.path.join(self.install_lib, 'IPython')
452 dest = os.path.join(self.install_lib, 'IPython')
446 if os.path.islink(dest):
453 if os.path.islink(dest):
447 print('removing symlink at %s' % dest)
454 print('removing symlink at %s' % dest)
448 os.unlink(dest)
455 os.unlink(dest)
449 else:
456 else:
450 print('No symlink exists at %s' % dest)
457 print('No symlink exists at %s' % dest)
451
458
452 class install_symlinked(install):
459 class install_symlinked(install):
453 def run(self):
460 def run(self):
454 if sys.platform == 'win32':
461 if sys.platform == 'win32':
455 raise Exception("This doesn't work on Windows.")
462 raise Exception("This doesn't work on Windows.")
456
463
457 # Run all sub-commands (at least those that need to be run)
464 # Run all sub-commands (at least those that need to be run)
458 for cmd_name in self.get_sub_commands():
465 for cmd_name in self.get_sub_commands():
459 self.run_command(cmd_name)
466 self.run_command(cmd_name)
460
467
461 # 'sub_commands': a list of commands this command might have to run to
468 # 'sub_commands': a list of commands this command might have to run to
462 # get its work done. See cmd.py for more info.
469 # get its work done. See cmd.py for more info.
463 sub_commands = [('install_lib_symlink', lambda self:True),
470 sub_commands = [('install_lib_symlink', lambda self:True),
464 ('install_scripts_sym', lambda self:True),
471 ('install_scripts_sym', lambda self:True),
465 ]
472 ]
466
473
467 class install_scripts_for_symlink(install_scripts):
474 class install_scripts_for_symlink(install_scripts):
468 """Redefined to get options from 'symlink' instead of 'install'.
475 """Redefined to get options from 'symlink' instead of 'install'.
469
476
470 I love distutils almost as much as I love setuptools.
477 I love distutils almost as much as I love setuptools.
471 """
478 """
472 def finalize_options(self):
479 def finalize_options(self):
473 self.set_undefined_options('build', ('build_scripts', 'build_dir'))
480 self.set_undefined_options('build', ('build_scripts', 'build_dir'))
474 self.set_undefined_options('symlink',
481 self.set_undefined_options('symlink',
475 ('install_scripts', 'install_dir'),
482 ('install_scripts', 'install_dir'),
476 ('force', 'force'),
483 ('force', 'force'),
477 ('skip_build', 'skip_build'),
484 ('skip_build', 'skip_build'),
478 )
485 )
479
486
480 #---------------------------------------------------------------------------
487 #---------------------------------------------------------------------------
481 # Verify all dependencies
488 # Verify all dependencies
482 #---------------------------------------------------------------------------
489 #---------------------------------------------------------------------------
483
490
484 def check_for_dependencies():
491 def check_for_dependencies():
485 """Check for IPython's dependencies.
492 """Check for IPython's dependencies.
486
493
487 This function should NOT be called if running under setuptools!
494 This function should NOT be called if running under setuptools!
488 """
495 """
489 from setupext.setupext import (
496 from setupext.setupext import (
490 print_line, print_raw, print_status,
497 print_line, print_raw, print_status,
491 check_for_sphinx, check_for_pygments,
498 check_for_sphinx, check_for_pygments,
492 check_for_nose, check_for_pexpect,
499 check_for_nose, check_for_pexpect,
493 check_for_pyzmq, check_for_readline,
500 check_for_pyzmq, check_for_readline,
494 check_for_jinja2, check_for_tornado
501 check_for_jinja2, check_for_tornado
495 )
502 )
496 print_line()
503 print_line()
497 print_raw("BUILDING IPYTHON")
504 print_raw("BUILDING IPYTHON")
498 print_status('python', sys.version)
505 print_status('python', sys.version)
499 print_status('platform', sys.platform)
506 print_status('platform', sys.platform)
500 if sys.platform == 'win32':
507 if sys.platform == 'win32':
501 print_status('Windows version', sys.getwindowsversion())
508 print_status('Windows version', sys.getwindowsversion())
502
509
503 print_raw("")
510 print_raw("")
504 print_raw("OPTIONAL DEPENDENCIES")
511 print_raw("OPTIONAL DEPENDENCIES")
505
512
506 check_for_sphinx()
513 check_for_sphinx()
507 check_for_pygments()
514 check_for_pygments()
508 check_for_nose()
515 check_for_nose()
509 if os.name == 'posix':
516 if os.name == 'posix':
510 check_for_pexpect()
517 check_for_pexpect()
511 check_for_pyzmq()
518 check_for_pyzmq()
512 check_for_tornado()
519 check_for_tornado()
513 check_for_readline()
520 check_for_readline()
514 check_for_jinja2()
521 check_for_jinja2()
515
522
516 #---------------------------------------------------------------------------
523 #---------------------------------------------------------------------------
517 # VCS related
524 # VCS related
518 #---------------------------------------------------------------------------
525 #---------------------------------------------------------------------------
519
526
520 # utils.submodule has checks for submodule status
527 # utils.submodule has checks for submodule status
521 execfile(pjoin('IPython','utils','submodule.py'), globals())
528 execfile(pjoin('IPython','utils','submodule.py'), globals())
522
529
523 class UpdateSubmodules(Command):
530 class UpdateSubmodules(Command):
524 """Update git submodules
531 """Update git submodules
525
532
526 IPython's external javascript dependencies live in a separate repo.
533 IPython's external javascript dependencies live in a separate repo.
527 """
534 """
528 description = "Update git submodules"
535 description = "Update git submodules"
529 user_options = []
536 user_options = []
530
537
531 def initialize_options(self):
538 def initialize_options(self):
532 pass
539 pass
533
540
534 def finalize_options(self):
541 def finalize_options(self):
535 pass
542 pass
536
543
537 def run(self):
544 def run(self):
538 failure = False
545 failure = False
539 try:
546 try:
540 self.spawn('git submodule init'.split())
547 self.spawn('git submodule init'.split())
541 self.spawn('git submodule update --recursive'.split())
548 self.spawn('git submodule update --recursive'.split())
542 except Exception as e:
549 except Exception as e:
543 failure = e
550 failure = e
544 print(e)
551 print(e)
545
552
546 if not check_submodule_status(repo_root) == 'clean':
553 if not check_submodule_status(repo_root) == 'clean':
547 print("submodules could not be checked out")
554 print("submodules could not be checked out")
548 sys.exit(1)
555 sys.exit(1)
549
556
550
557
551 def git_prebuild(pkg_dir, build_cmd=build_py):
558 def git_prebuild(pkg_dir, build_cmd=build_py):
552 """Return extended build or sdist command class for recording commit
559 """Return extended build or sdist command class for recording commit
553
560
554 records git commit in IPython.utils._sysinfo.commit
561 records git commit in IPython.utils._sysinfo.commit
555
562
556 for use in IPython.utils.sysinfo.sys_info() calls after installation.
563 for use in IPython.utils.sysinfo.sys_info() calls after installation.
557
564
558 Also ensures that submodules exist prior to running
565 Also ensures that submodules exist prior to running
559 """
566 """
560
567
561 class MyBuildPy(build_cmd):
568 class MyBuildPy(build_cmd):
562 ''' Subclass to write commit data into installation tree '''
569 ''' Subclass to write commit data into installation tree '''
563 def run(self):
570 def run(self):
564 build_cmd.run(self)
571 build_cmd.run(self)
565 # this one will only fire for build commands
572 # this one will only fire for build commands
566 if hasattr(self, 'build_lib'):
573 if hasattr(self, 'build_lib'):
567 self._record_commit(self.build_lib)
574 self._record_commit(self.build_lib)
568
575
569 def make_release_tree(self, base_dir, files):
576 def make_release_tree(self, base_dir, files):
570 # this one will fire for sdist
577 # this one will fire for sdist
571 build_cmd.make_release_tree(self, base_dir, files)
578 build_cmd.make_release_tree(self, base_dir, files)
572 self._record_commit(base_dir)
579 self._record_commit(base_dir)
573
580
574 def _record_commit(self, base_dir):
581 def _record_commit(self, base_dir):
575 import subprocess
582 import subprocess
576 proc = subprocess.Popen('git rev-parse --short HEAD',
583 proc = subprocess.Popen('git rev-parse --short HEAD',
577 stdout=subprocess.PIPE,
584 stdout=subprocess.PIPE,
578 stderr=subprocess.PIPE,
585 stderr=subprocess.PIPE,
579 shell=True)
586 shell=True)
580 repo_commit, _ = proc.communicate()
587 repo_commit, _ = proc.communicate()
581 repo_commit = repo_commit.strip().decode("ascii")
588 repo_commit = repo_commit.strip().decode("ascii")
582
589
583 out_pth = pjoin(base_dir, pkg_dir, 'utils', '_sysinfo.py')
590 out_pth = pjoin(base_dir, pkg_dir, 'utils', '_sysinfo.py')
584 if os.path.isfile(out_pth) and not repo_commit:
591 if os.path.isfile(out_pth) and not repo_commit:
585 # nothing to write, don't clobber
592 # nothing to write, don't clobber
586 return
593 return
587
594
588 print("writing git commit '%s' to %s" % (repo_commit, out_pth))
595 print("writing git commit '%s' to %s" % (repo_commit, out_pth))
589
596
590 # remove to avoid overwriting original via hard link
597 # remove to avoid overwriting original via hard link
591 try:
598 try:
592 os.remove(out_pth)
599 os.remove(out_pth)
593 except (IOError, OSError):
600 except (IOError, OSError):
594 pass
601 pass
595 with open(out_pth, 'w') as out_file:
602 with open(out_pth, 'w') as out_file:
596 out_file.writelines([
603 out_file.writelines([
597 '# GENERATED BY setup.py\n',
604 '# GENERATED BY setup.py\n',
598 'commit = u"%s"\n' % repo_commit,
605 'commit = u"%s"\n' % repo_commit,
599 ])
606 ])
600 return require_submodules(MyBuildPy)
607 return require_submodules(MyBuildPy)
601
608
602
609
603 def require_submodules(command):
610 def require_submodules(command):
604 """decorator for instructing a command to check for submodules before running"""
611 """decorator for instructing a command to check for submodules before running"""
605 class DecoratedCommand(command):
612 class DecoratedCommand(command):
606 def run(self):
613 def run(self):
607 if not check_submodule_status(repo_root) == 'clean':
614 if not check_submodule_status(repo_root) == 'clean':
608 print("submodules missing! Run `setup.py submodule` and try again")
615 print("submodules missing! Run `setup.py submodule` and try again")
609 sys.exit(1)
616 sys.exit(1)
610 command.run(self)
617 command.run(self)
611 return DecoratedCommand
618 return DecoratedCommand
612
619
613 #---------------------------------------------------------------------------
620 #---------------------------------------------------------------------------
614 # bdist related
621 # bdist related
615 #---------------------------------------------------------------------------
622 #---------------------------------------------------------------------------
616
623
617 def get_bdist_wheel():
624 def get_bdist_wheel():
618 """Construct bdist_wheel command for building wheels
625 """Construct bdist_wheel command for building wheels
619
626
620 Constructs py2-none-any tag, instead of py2.7-none-any
627 Constructs py2-none-any tag, instead of py2.7-none-any
621 """
628 """
622 class RequiresWheel(Command):
629 class RequiresWheel(Command):
623 description = "Dummy command for missing bdist_wheel"
630 description = "Dummy command for missing bdist_wheel"
624 user_options = []
631 user_options = []
625
632
626 def initialize_options(self):
633 def initialize_options(self):
627 pass
634 pass
628
635
629 def finalize_options(self):
636 def finalize_options(self):
630 pass
637 pass
631
638
632 def run(self):
639 def run(self):
633 print("bdist_wheel requires the wheel package")
640 print("bdist_wheel requires the wheel package")
634 sys.exit(1)
641 sys.exit(1)
635
642
636 if 'setuptools' not in sys.modules:
643 if 'setuptools' not in sys.modules:
637 return RequiresWheel
644 return RequiresWheel
638 else:
645 else:
639 try:
646 try:
640 from wheel.bdist_wheel import bdist_wheel, read_pkg_info, write_pkg_info
647 from wheel.bdist_wheel import bdist_wheel, read_pkg_info, write_pkg_info
641 except ImportError:
648 except ImportError:
642 return RequiresWheel
649 return RequiresWheel
643
650
644 class bdist_wheel_tag(bdist_wheel):
651 class bdist_wheel_tag(bdist_wheel):
645
652
646 def add_requirements(self, metadata_path):
653 def add_requirements(self, metadata_path):
647 """transform platform-dependent requirements"""
654 """transform platform-dependent requirements"""
648 pkg_info = read_pkg_info(metadata_path)
655 pkg_info = read_pkg_info(metadata_path)
649 # pkg_info is an email.Message object (?!)
656 # pkg_info is an email.Message object (?!)
650 # we have to remove the unconditional 'readline' and/or 'pyreadline' entries
657 # we have to remove the unconditional 'readline' and/or 'pyreadline' entries
651 # and transform them to conditionals
658 # and transform them to conditionals
652 requires = pkg_info.get_all('Requires-Dist')
659 requires = pkg_info.get_all('Requires-Dist')
653 del pkg_info['Requires-Dist']
660 del pkg_info['Requires-Dist']
654 def _remove_startswith(lis, prefix):
661 def _remove_startswith(lis, prefix):
655 """like list.remove, but with startswith instead of =="""
662 """like list.remove, but with startswith instead of =="""
656 found = False
663 found = False
657 for idx, item in enumerate(lis):
664 for idx, item in enumerate(lis):
658 if item.startswith(prefix):
665 if item.startswith(prefix):
659 found = True
666 found = True
660 break
667 break
661 if found:
668 if found:
662 lis.pop(idx)
669 lis.pop(idx)
663
670
664 for pkg in ("gnureadline", "pyreadline", "mock"):
671 for pkg in ("gnureadline", "pyreadline", "mock"):
665 _remove_startswith(requires, pkg)
672 _remove_startswith(requires, pkg)
666 requires.append("gnureadline; sys.platform == 'darwin' and platform.python_implementation == 'CPython'")
673 requires.append("gnureadline; sys.platform == 'darwin' and platform.python_implementation == 'CPython'")
667 requires.append("pyreadline (>=2.0); extra == 'terminal' and sys.platform == 'win32' and platform.python_implementation == 'CPython'")
674 requires.append("pyreadline (>=2.0); extra == 'terminal' and sys.platform == 'win32' and platform.python_implementation == 'CPython'")
668 requires.append("pyreadline (>=2.0); extra == 'all' and sys.platform == 'win32' and platform.python_implementation == 'CPython'")
675 requires.append("pyreadline (>=2.0); extra == 'all' and sys.platform == 'win32' and platform.python_implementation == 'CPython'")
669 requires.append("mock; extra == 'test' and python_version < '3.3'")
676 requires.append("mock; extra == 'test' and python_version < '3.3'")
670 for r in requires:
677 for r in requires:
671 pkg_info['Requires-Dist'] = r
678 pkg_info['Requires-Dist'] = r
672 write_pkg_info(metadata_path, pkg_info)
679 write_pkg_info(metadata_path, pkg_info)
673
680
674 return bdist_wheel_tag
681 return bdist_wheel_tag
675
682
676 #---------------------------------------------------------------------------
683 #---------------------------------------------------------------------------
677 # Notebook related
684 # Notebook related
678 #---------------------------------------------------------------------------
685 #---------------------------------------------------------------------------
679
686
680 class CompileCSS(Command):
687 class CompileCSS(Command):
681 """Recompile Notebook CSS
688 """Recompile Notebook CSS
682
689
683 Regenerate the compiled CSS from LESS sources.
690 Regenerate the compiled CSS from LESS sources.
684
691
685 Requires various dev dependencies, such as invoke and lessc.
692 Requires various dev dependencies, such as invoke and lessc.
686 """
693 """
687 description = "Recompile Notebook CSS"
694 description = "Recompile Notebook CSS"
688 user_options = [
695 user_options = [
689 ('minify', 'x', "minify CSS"),
696 ('minify', 'x', "minify CSS"),
690 ('force', 'f', "force recompilation of CSS"),
697 ('force', 'f', "force recompilation of CSS"),
691 ]
698 ]
692
699
693 def initialize_options(self):
700 def initialize_options(self):
694 self.minify = False
701 self.minify = False
695 self.force = False
702 self.force = False
696
703
697 def finalize_options(self):
704 def finalize_options(self):
698 self.minify = bool(self.minify)
705 self.minify = bool(self.minify)
699 self.force = bool(self.force)
706 self.force = bool(self.force)
700
707
701 def run(self):
708 def run(self):
702 cmd = ['invoke', 'css']
709 cmd = ['invoke', 'css']
703 if self.minify:
710 if self.minify:
704 cmd.append('--minify')
711 cmd.append('--minify')
705 if self.force:
712 if self.force:
706 cmd.append('--force')
713 cmd.append('--force')
707 check_call(cmd, cwd=pjoin(repo_root, "IPython", "html"))
714 check_call(cmd, cwd=pjoin(repo_root, "IPython", "html"))
708
715
709
716
710 class JavascriptVersion(Command):
717 class JavascriptVersion(Command):
711 """write the javascript version to notebook javascript"""
718 """write the javascript version to notebook javascript"""
712 description = "Write IPython version to javascript"
719 description = "Write IPython version to javascript"
713 user_options = []
720 user_options = []
714
721
715 def initialize_options(self):
722 def initialize_options(self):
716 pass
723 pass
717
724
718 def finalize_options(self):
725 def finalize_options(self):
719 pass
726 pass
720
727
721 def run(self):
728 def run(self):
722 nsfile = pjoin(repo_root, "IPython", "html", "static", "base", "js", "namespace.js")
729 nsfile = pjoin(repo_root, "IPython", "html", "static", "base", "js", "namespace.js")
723 with open(nsfile) as f:
730 with open(nsfile) as f:
724 lines = f.readlines()
731 lines = f.readlines()
725 with open(nsfile, 'w') as f:
732 with open(nsfile, 'w') as f:
726 for line in lines:
733 for line in lines:
727 if line.startswith("IPython.version"):
734 if line.startswith("IPython.version"):
728 line = 'IPython.version = "{0}";\n'.format(version)
735 line = 'IPython.version = "{0}";\n'.format(version)
729 f.write(line)
736 f.write(line)
730
737
731
738
732 def css_js_prerelease(command, strict=True):
739 def css_js_prerelease(command, strict=True):
733 """decorator for building js/minified css prior to a release"""
740 """decorator for building js/minified css prior to a release"""
734 class DecoratedCommand(command):
741 class DecoratedCommand(command):
735 def run(self):
742 def run(self):
736 self.distribution.run_command('jsversion')
743 self.distribution.run_command('jsversion')
737 css = self.distribution.get_command_obj('css')
744 css = self.distribution.get_command_obj('css')
738 css.minify = True
745 css.minify = True
739 try:
746 try:
740 self.distribution.run_command('css')
747 self.distribution.run_command('css')
741 except Exception as e:
748 except Exception as e:
742 if strict:
749 if strict:
743 raise
750 raise
744 else:
751 else:
745 log.warn("Failed to build css sourcemaps: %s" % e)
752 log.warn("Failed to build css sourcemaps: %s" % e)
746 command.run(self)
753 command.run(self)
747 return DecoratedCommand
754 return DecoratedCommand
General Comments 0
You need to be logged in to leave comments. Login now