Show More
@@ -1,589 +1,590 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | """ |
|
3 | 3 | This module defines the things that are used in setup.py for building IPython |
|
4 | 4 | |
|
5 | 5 | This includes: |
|
6 | 6 | |
|
7 | 7 | * The basic arguments to setup |
|
8 | 8 | * Functions for finding things like packages, package data, etc. |
|
9 | 9 | * A function for checking dependencies. |
|
10 | 10 | """ |
|
11 | 11 | from __future__ import print_function |
|
12 | 12 | |
|
13 | 13 | #------------------------------------------------------------------------------- |
|
14 | 14 | # Copyright (C) 2008 The IPython Development Team |
|
15 | 15 | # |
|
16 | 16 | # Distributed under the terms of the BSD License. The full license is in |
|
17 | 17 | # the file COPYING, distributed as part of this software. |
|
18 | 18 | #------------------------------------------------------------------------------- |
|
19 | 19 | |
|
20 | 20 | #------------------------------------------------------------------------------- |
|
21 | 21 | # Imports |
|
22 | 22 | #------------------------------------------------------------------------------- |
|
23 | 23 | import errno |
|
24 | 24 | import os |
|
25 | 25 | import sys |
|
26 | 26 | |
|
27 | 27 | from distutils.command.build_py import build_py |
|
28 | 28 | from distutils.command.build_scripts import build_scripts |
|
29 | 29 | from distutils.command.install import install |
|
30 | 30 | from distutils.command.install_scripts import install_scripts |
|
31 | 31 | from distutils.cmd import Command |
|
32 | 32 | from glob import glob |
|
33 | 33 | from subprocess import call |
|
34 | 34 | |
|
35 | 35 | from setupext import install_data_ext |
|
36 | 36 | |
|
37 | 37 | #------------------------------------------------------------------------------- |
|
38 | 38 | # Useful globals and utility functions |
|
39 | 39 | #------------------------------------------------------------------------------- |
|
40 | 40 | |
|
41 | 41 | # A few handy globals |
|
42 | 42 | isfile = os.path.isfile |
|
43 | 43 | pjoin = os.path.join |
|
44 | 44 | repo_root = os.path.dirname(os.path.abspath(__file__)) |
|
45 | 45 | |
|
46 | 46 | def oscmd(s): |
|
47 | 47 | print(">", s) |
|
48 | 48 | os.system(s) |
|
49 | 49 | |
|
50 | 50 | # Py3 compatibility hacks, without assuming IPython itself is installed with |
|
51 | 51 | # the full py3compat machinery. |
|
52 | 52 | |
|
53 | 53 | try: |
|
54 | 54 | execfile |
|
55 | 55 | except NameError: |
|
56 | 56 | def execfile(fname, globs, locs=None): |
|
57 | 57 | locs = locs or globs |
|
58 | 58 | exec(compile(open(fname).read(), fname, "exec"), globs, locs) |
|
59 | 59 | |
|
60 | 60 | # A little utility we'll need below, since glob() does NOT allow you to do |
|
61 | 61 | # exclusion on multiple endings! |
|
62 | 62 | def file_doesnt_endwith(test,endings): |
|
63 | 63 | """Return true if test is a file and its name does NOT end with any |
|
64 | 64 | of the strings listed in endings.""" |
|
65 | 65 | if not isfile(test): |
|
66 | 66 | return False |
|
67 | 67 | for e in endings: |
|
68 | 68 | if test.endswith(e): |
|
69 | 69 | return False |
|
70 | 70 | return True |
|
71 | 71 | |
|
72 | 72 | #--------------------------------------------------------------------------- |
|
73 | 73 | # Basic project information |
|
74 | 74 | #--------------------------------------------------------------------------- |
|
75 | 75 | |
|
76 | 76 | # release.py contains version, authors, license, url, keywords, etc. |
|
77 | 77 | execfile(pjoin(repo_root, 'IPython','core','release.py'), globals()) |
|
78 | 78 | |
|
79 | 79 | # Create a dict with the basic information |
|
80 | 80 | # This dict is eventually passed to setup after additional keys are added. |
|
81 | 81 | setup_args = dict( |
|
82 | 82 | name = name, |
|
83 | 83 | version = version, |
|
84 | 84 | description = description, |
|
85 | 85 | long_description = long_description, |
|
86 | 86 | author = author, |
|
87 | 87 | author_email = author_email, |
|
88 | 88 | url = url, |
|
89 | 89 | download_url = download_url, |
|
90 | 90 | license = license, |
|
91 | 91 | platforms = platforms, |
|
92 | 92 | keywords = keywords, |
|
93 | 93 | classifiers = classifiers, |
|
94 | 94 | cmdclass = {'install_data': install_data_ext}, |
|
95 | 95 | ) |
|
96 | 96 | |
|
97 | 97 | |
|
98 | 98 | #--------------------------------------------------------------------------- |
|
99 | 99 | # Find packages |
|
100 | 100 | #--------------------------------------------------------------------------- |
|
101 | 101 | |
|
102 | 102 | def find_packages(): |
|
103 | 103 | """ |
|
104 | 104 | Find all of IPython's packages. |
|
105 | 105 | """ |
|
106 | 106 | excludes = ['deathrow', 'quarantine'] |
|
107 | 107 | packages = [] |
|
108 | 108 | for dir,subdirs,files in os.walk('IPython'): |
|
109 | 109 | package = dir.replace(os.path.sep, '.') |
|
110 | 110 | if any(package.startswith('IPython.'+exc) for exc in excludes): |
|
111 | 111 | # package is to be excluded (e.g. deathrow) |
|
112 | 112 | continue |
|
113 | 113 | if '__init__.py' not in files: |
|
114 | 114 | # not a package |
|
115 | 115 | continue |
|
116 | 116 | packages.append(package) |
|
117 | 117 | return packages |
|
118 | 118 | |
|
119 | 119 | #--------------------------------------------------------------------------- |
|
120 | 120 | # Find package data |
|
121 | 121 | #--------------------------------------------------------------------------- |
|
122 | 122 | |
|
123 | 123 | def find_package_data(): |
|
124 | 124 | """ |
|
125 | 125 | Find IPython's package_data. |
|
126 | 126 | """ |
|
127 | 127 | # This is not enough for these things to appear in an sdist. |
|
128 | 128 | # We need to muck with the MANIFEST to get this to work |
|
129 | 129 | |
|
130 | 130 | # exclude static things that we don't ship (e.g. mathjax) |
|
131 | 131 | excludes = ['mathjax'] |
|
132 | 132 | |
|
133 | 133 | # add 'static/' prefix to exclusions, and tuplify for use in startswith |
|
134 | 134 | excludes = tuple([os.path.join('static', ex) for ex in excludes]) |
|
135 | 135 | |
|
136 | 136 | # walk notebook resources: |
|
137 | 137 | cwd = os.getcwd() |
|
138 | 138 | os.chdir(os.path.join('IPython', 'html')) |
|
139 | 139 | static_walk = list(os.walk('static')) |
|
140 | 140 | static_data = [] |
|
141 | 141 | for parent, dirs, files in static_walk: |
|
142 | 142 | if parent.startswith(excludes): |
|
143 | 143 | continue |
|
144 | 144 | for f in files: |
|
145 | 145 | static_data.append(os.path.join(parent, f)) |
|
146 | 146 | |
|
147 | 147 | os.chdir(os.path.join('tests',)) |
|
148 | 148 | js_tests = glob('casperjs/*.*') + glob('casperjs/*/*') |
|
149 | 149 | os.chdir(cwd) |
|
150 | 150 | |
|
151 | 151 | package_data = { |
|
152 | 152 | 'IPython.config.profile' : ['README*', '*/*.py'], |
|
153 | 153 | 'IPython.core.tests' : ['*.png', '*.jpg'], |
|
154 | 154 | 'IPython.lib.tests' : ['*.wav'], |
|
155 | 155 | 'IPython.testing' : ['*.txt'], |
|
156 | 156 | 'IPython.testing.plugin' : ['*.txt'], |
|
157 | 157 | 'IPython.html' : ['templates/*'] + static_data, |
|
158 | 158 | 'IPython.html.tests' : js_tests, |
|
159 | 159 | 'IPython.qt.console' : ['resources/icon/*.svg'], |
|
160 | 160 | 'IPython.nbconvert' : ['templates/*.tpl', 'templates/latex/*.tplx', |
|
161 | 161 | 'templates/latex/skeleton/*.tplx', 'templates/skeleton/*', |
|
162 | 162 | 'templates/reveal_internals/*.tpl', 'tests/files/*.*', |
|
163 | 163 | 'exporters/tests/files/*.*'], |
|
164 | 164 | 'IPython.nbformat' : ['tests/*.ipynb'] |
|
165 | 165 | } |
|
166 | 166 | return package_data |
|
167 | 167 | |
|
168 | 168 | |
|
169 | 169 | #--------------------------------------------------------------------------- |
|
170 | 170 | # Find data files |
|
171 | 171 | #--------------------------------------------------------------------------- |
|
172 | 172 | |
|
173 | 173 | def make_dir_struct(tag,base,out_base): |
|
174 | 174 | """Make the directory structure of all files below a starting dir. |
|
175 | 175 | |
|
176 | 176 | This is just a convenience routine to help build a nested directory |
|
177 | 177 | hierarchy because distutils is too stupid to do this by itself. |
|
178 | 178 | |
|
179 | 179 | XXX - this needs a proper docstring! |
|
180 | 180 | """ |
|
181 | 181 | |
|
182 | 182 | # we'll use these a lot below |
|
183 | 183 | lbase = len(base) |
|
184 | 184 | pathsep = os.path.sep |
|
185 | 185 | lpathsep = len(pathsep) |
|
186 | 186 | |
|
187 | 187 | out = [] |
|
188 | 188 | for (dirpath,dirnames,filenames) in os.walk(base): |
|
189 | 189 | # we need to strip out the dirpath from the base to map it to the |
|
190 | 190 | # output (installation) path. This requires possibly stripping the |
|
191 | 191 | # path separator, because otherwise pjoin will not work correctly |
|
192 | 192 | # (pjoin('foo/','/bar') returns '/bar'). |
|
193 | 193 | |
|
194 | 194 | dp_eff = dirpath[lbase:] |
|
195 | 195 | if dp_eff.startswith(pathsep): |
|
196 | 196 | dp_eff = dp_eff[lpathsep:] |
|
197 | 197 | # The output path must be anchored at the out_base marker |
|
198 | 198 | out_path = pjoin(out_base,dp_eff) |
|
199 | 199 | # Now we can generate the final filenames. Since os.walk only produces |
|
200 | 200 | # filenames, we must join back with the dirpath to get full valid file |
|
201 | 201 | # paths: |
|
202 | 202 | pfiles = [pjoin(dirpath,f) for f in filenames] |
|
203 | 203 | # Finally, generate the entry we need, which is a pari of (output |
|
204 | 204 | # path, files) for use as a data_files parameter in install_data. |
|
205 | 205 | out.append((out_path, pfiles)) |
|
206 | 206 | |
|
207 | 207 | return out |
|
208 | 208 | |
|
209 | 209 | |
|
210 | 210 | def find_data_files(): |
|
211 | 211 | """ |
|
212 | 212 | Find IPython's data_files. |
|
213 | 213 | |
|
214 | 214 | Most of these are docs. |
|
215 | 215 | """ |
|
216 | 216 | |
|
217 | 217 | docdirbase = pjoin('share', 'doc', 'ipython') |
|
218 | 218 | manpagebase = pjoin('share', 'man', 'man1') |
|
219 | 219 | |
|
220 | 220 | # Simple file lists can be made by hand |
|
221 | 221 | manpages = [f for f in glob(pjoin('docs','man','*.1.gz')) if isfile(f)] |
|
222 | 222 | if not manpages: |
|
223 | 223 | # When running from a source tree, the manpages aren't gzipped |
|
224 | 224 | manpages = [f for f in glob(pjoin('docs','man','*.1')) if isfile(f)] |
|
225 | 225 | |
|
226 | 226 | igridhelpfiles = [f for f in glob(pjoin('IPython','extensions','igrid_help.*')) if isfile(f)] |
|
227 | 227 | |
|
228 | 228 | # For nested structures, use the utility above |
|
229 | 229 | example_files = make_dir_struct( |
|
230 | 230 | 'data', |
|
231 | 231 | pjoin('docs','examples'), |
|
232 | 232 | pjoin(docdirbase,'examples') |
|
233 | 233 | ) |
|
234 | 234 | manual_files = make_dir_struct( |
|
235 | 235 | 'data', |
|
236 | 236 | pjoin('docs','html'), |
|
237 | 237 | pjoin(docdirbase,'manual') |
|
238 | 238 | ) |
|
239 | 239 | |
|
240 | 240 | # And assemble the entire output list |
|
241 | 241 | data_files = [ (manpagebase, manpages), |
|
242 | 242 | (pjoin(docdirbase, 'extensions'), igridhelpfiles), |
|
243 | 243 | ] + manual_files + example_files |
|
244 | 244 | |
|
245 | 245 | return data_files |
|
246 | 246 | |
|
247 | 247 | |
|
248 | 248 | def make_man_update_target(manpage): |
|
249 | 249 | """Return a target_update-compliant tuple for the given manpage. |
|
250 | 250 | |
|
251 | 251 | Parameters |
|
252 | 252 | ---------- |
|
253 | 253 | manpage : string |
|
254 | 254 | Name of the manpage, must include the section number (trailing number). |
|
255 | 255 | |
|
256 | 256 | Example |
|
257 | 257 | ------- |
|
258 | 258 | |
|
259 | 259 | >>> make_man_update_target('ipython.1') #doctest: +NORMALIZE_WHITESPACE |
|
260 | 260 | ('docs/man/ipython.1.gz', |
|
261 | 261 | ['docs/man/ipython.1'], |
|
262 | 262 | 'cd docs/man && gzip -9c ipython.1 > ipython.1.gz') |
|
263 | 263 | """ |
|
264 | 264 | man_dir = pjoin('docs', 'man') |
|
265 | 265 | manpage_gz = manpage + '.gz' |
|
266 | 266 | manpath = pjoin(man_dir, manpage) |
|
267 | 267 | manpath_gz = pjoin(man_dir, manpage_gz) |
|
268 | 268 | gz_cmd = ( "cd %(man_dir)s && gzip -9c %(manpage)s > %(manpage_gz)s" % |
|
269 | 269 | locals() ) |
|
270 | 270 | return (manpath_gz, [manpath], gz_cmd) |
|
271 | 271 | |
|
272 | 272 | # The two functions below are copied from IPython.utils.path, so we don't need |
|
273 | 273 | # to import IPython during setup, which fails on Python 3. |
|
274 | 274 | |
|
275 | 275 | def target_outdated(target,deps): |
|
276 | 276 | """Determine whether a target is out of date. |
|
277 | 277 | |
|
278 | 278 | target_outdated(target,deps) -> 1/0 |
|
279 | 279 | |
|
280 | 280 | deps: list of filenames which MUST exist. |
|
281 | 281 | target: single filename which may or may not exist. |
|
282 | 282 | |
|
283 | 283 | If target doesn't exist or is older than any file listed in deps, return |
|
284 | 284 | true, otherwise return false. |
|
285 | 285 | """ |
|
286 | 286 | try: |
|
287 | 287 | target_time = os.path.getmtime(target) |
|
288 | 288 | except os.error: |
|
289 | 289 | return 1 |
|
290 | 290 | for dep in deps: |
|
291 | 291 | dep_time = os.path.getmtime(dep) |
|
292 | 292 | if dep_time > target_time: |
|
293 | 293 | #print "For target",target,"Dep failed:",dep # dbg |
|
294 | 294 | #print "times (dep,tar):",dep_time,target_time # dbg |
|
295 | 295 | return 1 |
|
296 | 296 | return 0 |
|
297 | 297 | |
|
298 | 298 | |
|
299 | 299 | def target_update(target,deps,cmd): |
|
300 | 300 | """Update a target with a given command given a list of dependencies. |
|
301 | 301 | |
|
302 | 302 | target_update(target,deps,cmd) -> runs cmd if target is outdated. |
|
303 | 303 | |
|
304 | 304 | This is just a wrapper around target_outdated() which calls the given |
|
305 | 305 | command if target is outdated.""" |
|
306 | 306 | |
|
307 | 307 | if target_outdated(target,deps): |
|
308 | 308 | os.system(cmd) |
|
309 | 309 | |
|
310 | 310 | #--------------------------------------------------------------------------- |
|
311 | 311 | # Find scripts |
|
312 | 312 | #--------------------------------------------------------------------------- |
|
313 | 313 | |
|
314 | 314 | def find_entry_points(): |
|
315 | 315 | """Find IPython's scripts. |
|
316 | 316 | |
|
317 | 317 | if entry_points is True: |
|
318 | 318 | return setuptools entry_point-style definitions |
|
319 | 319 | else: |
|
320 | 320 | return file paths of plain scripts [default] |
|
321 | 321 | |
|
322 | 322 | suffix is appended to script names if entry_points is True, so that the |
|
323 | 323 | Python 3 scripts get named "ipython3" etc. |
|
324 | 324 | """ |
|
325 | 325 | ep = [ |
|
326 | 326 | 'ipython%s = IPython:start_ipython', |
|
327 | 327 | 'ipcontroller%s = IPython.parallel.apps.ipcontrollerapp:launch_new_instance', |
|
328 | 328 | 'ipengine%s = IPython.parallel.apps.ipengineapp:launch_new_instance', |
|
329 | 329 | 'iplogger%s = IPython.parallel.apps.iploggerapp:launch_new_instance', |
|
330 | 330 | 'ipcluster%s = IPython.parallel.apps.ipclusterapp:launch_new_instance', |
|
331 | 331 | 'iptest%s = IPython.testing.iptestcontroller:main', |
|
332 | 332 | 'irunner%s = IPython.lib.irunner:main', |
|
333 | 333 | ] |
|
334 | 334 | suffix = str(sys.version_info[0]) |
|
335 | 335 | return [e % '' for e in ep] + [e % suffix for e in ep] |
|
336 | 336 | |
|
337 | 337 | script_src = """#!{executable} |
|
338 | 338 | # This script was automatically generated by setup.py |
|
339 | 339 | from {mod} import {func} |
|
340 | {func}() | |
|
340 | if __name__ == '__main__': | |
|
341 | {func}() | |
|
341 | 342 | """ |
|
342 | 343 | |
|
343 | 344 | class build_scripts_entrypt(build_scripts): |
|
344 | 345 | def run(self): |
|
345 | 346 | self.mkpath(self.build_dir) |
|
346 | 347 | outfiles = [] |
|
347 | 348 | for script in find_entry_points(): |
|
348 | 349 | name, entrypt = script.split('=') |
|
349 | 350 | name = name.strip() |
|
350 | 351 | entrypt = entrypt.strip() |
|
351 | 352 | outfile = os.path.join(self.build_dir, name) |
|
352 | 353 | outfiles.append(outfile) |
|
353 | 354 | print('Writing script to', outfile) |
|
354 | 355 | |
|
355 | 356 | mod, func = entrypt.split(':') |
|
356 | 357 | with open(outfile, 'w') as f: |
|
357 | 358 | f.write(script_src.format(executable=sys.executable, |
|
358 | 359 | mod=mod, func=func)) |
|
359 | 360 | |
|
360 | 361 | return outfiles, outfiles |
|
361 | 362 | |
|
362 | 363 | class install_lib_symlink(Command): |
|
363 | 364 | user_options = [ |
|
364 | 365 | ('install-dir=', 'd', "directory to install to"), |
|
365 | 366 | ] |
|
366 | 367 | |
|
367 | 368 | def initialize_options(self): |
|
368 | 369 | self.install_dir = None |
|
369 | 370 | |
|
370 | 371 | def finalize_options(self): |
|
371 | 372 | self.set_undefined_options('symlink', |
|
372 | 373 | ('install_lib', 'install_dir'), |
|
373 | 374 | ) |
|
374 | 375 | |
|
375 | 376 | def run(self): |
|
376 | 377 | if sys.platform == 'win32': |
|
377 | 378 | raise Exception("This doesn't work on Windows.") |
|
378 | 379 | pkg = os.path.join(os.getcwd(), 'IPython') |
|
379 | 380 | dest = os.path.join(self.install_dir, 'IPython') |
|
380 | 381 | print('symlinking %s -> %s' % (pkg, dest)) |
|
381 | 382 | try: |
|
382 | 383 | os.symlink(pkg, dest) |
|
383 | 384 | except OSError as e: |
|
384 | 385 | if e.errno == errno.EEXIST: |
|
385 | 386 | print('ALREADY EXISTS') |
|
386 | 387 | else: |
|
387 | 388 | raise |
|
388 | 389 | |
|
389 | 390 | class install_symlinked(install): |
|
390 | 391 | def run(self): |
|
391 | 392 | if sys.platform == 'win32': |
|
392 | 393 | raise Exception("This doesn't work on Windows.") |
|
393 | 394 | install.run(self) |
|
394 | 395 | |
|
395 | 396 | # 'sub_commands': a list of commands this command might have to run to |
|
396 | 397 | # get its work done. See cmd.py for more info. |
|
397 | 398 | sub_commands = [('install_lib_symlink', lambda self:True), |
|
398 | 399 | ('install_scripts_sym', lambda self:True), |
|
399 | 400 | ] |
|
400 | 401 | |
|
401 | 402 | class install_scripts_for_symlink(install_scripts): |
|
402 | 403 | """Redefined to get options from 'symlink' instead of 'install'. |
|
403 | 404 | |
|
404 | 405 | I love distutils almost as much as I love setuptools. |
|
405 | 406 | """ |
|
406 | 407 | def finalize_options(self): |
|
407 | 408 | self.set_undefined_options('build', ('build_scripts', 'build_dir')) |
|
408 | 409 | self.set_undefined_options('symlink', |
|
409 | 410 | ('install_scripts', 'install_dir'), |
|
410 | 411 | ('force', 'force'), |
|
411 | 412 | ('skip_build', 'skip_build'), |
|
412 | 413 | ) |
|
413 | 414 | |
|
414 | 415 | #--------------------------------------------------------------------------- |
|
415 | 416 | # Verify all dependencies |
|
416 | 417 | #--------------------------------------------------------------------------- |
|
417 | 418 | |
|
418 | 419 | def check_for_dependencies(): |
|
419 | 420 | """Check for IPython's dependencies. |
|
420 | 421 | |
|
421 | 422 | This function should NOT be called if running under setuptools! |
|
422 | 423 | """ |
|
423 | 424 | from setupext.setupext import ( |
|
424 | 425 | print_line, print_raw, print_status, |
|
425 | 426 | check_for_sphinx, check_for_pygments, |
|
426 | 427 | check_for_nose, check_for_pexpect, |
|
427 | 428 | check_for_pyzmq, check_for_readline, |
|
428 | 429 | check_for_jinja2, check_for_tornado |
|
429 | 430 | ) |
|
430 | 431 | print_line() |
|
431 | 432 | print_raw("BUILDING IPYTHON") |
|
432 | 433 | print_status('python', sys.version) |
|
433 | 434 | print_status('platform', sys.platform) |
|
434 | 435 | if sys.platform == 'win32': |
|
435 | 436 | print_status('Windows version', sys.getwindowsversion()) |
|
436 | 437 | |
|
437 | 438 | print_raw("") |
|
438 | 439 | print_raw("OPTIONAL DEPENDENCIES") |
|
439 | 440 | |
|
440 | 441 | check_for_sphinx() |
|
441 | 442 | check_for_pygments() |
|
442 | 443 | check_for_nose() |
|
443 | 444 | check_for_pexpect() |
|
444 | 445 | check_for_pyzmq() |
|
445 | 446 | check_for_tornado() |
|
446 | 447 | check_for_readline() |
|
447 | 448 | check_for_jinja2() |
|
448 | 449 | |
|
449 | 450 | #--------------------------------------------------------------------------- |
|
450 | 451 | # VCS related |
|
451 | 452 | #--------------------------------------------------------------------------- |
|
452 | 453 | |
|
453 | 454 | # utils.submodule has checks for submodule status |
|
454 | 455 | execfile(pjoin('IPython','utils','submodule.py'), globals()) |
|
455 | 456 | |
|
456 | 457 | class UpdateSubmodules(Command): |
|
457 | 458 | """Update git submodules |
|
458 | 459 | |
|
459 | 460 | IPython's external javascript dependencies live in a separate repo. |
|
460 | 461 | """ |
|
461 | 462 | description = "Update git submodules" |
|
462 | 463 | user_options = [] |
|
463 | 464 | |
|
464 | 465 | def initialize_options(self): |
|
465 | 466 | pass |
|
466 | 467 | |
|
467 | 468 | def finalize_options(self): |
|
468 | 469 | pass |
|
469 | 470 | |
|
470 | 471 | def run(self): |
|
471 | 472 | failure = False |
|
472 | 473 | try: |
|
473 | 474 | self.spawn('git submodule init'.split()) |
|
474 | 475 | self.spawn('git submodule update --recursive'.split()) |
|
475 | 476 | except Exception as e: |
|
476 | 477 | failure = e |
|
477 | 478 | print(e) |
|
478 | 479 | |
|
479 | 480 | if not check_submodule_status(repo_root) == 'clean': |
|
480 | 481 | print("submodules could not be checked out") |
|
481 | 482 | sys.exit(1) |
|
482 | 483 | |
|
483 | 484 | |
|
484 | 485 | def git_prebuild(pkg_dir, build_cmd=build_py): |
|
485 | 486 | """Return extended build or sdist command class for recording commit |
|
486 | 487 | |
|
487 | 488 | records git commit in IPython.utils._sysinfo.commit |
|
488 | 489 | |
|
489 | 490 | for use in IPython.utils.sysinfo.sys_info() calls after installation. |
|
490 | 491 | |
|
491 | 492 | Also ensures that submodules exist prior to running |
|
492 | 493 | """ |
|
493 | 494 | |
|
494 | 495 | class MyBuildPy(build_cmd): |
|
495 | 496 | ''' Subclass to write commit data into installation tree ''' |
|
496 | 497 | def run(self): |
|
497 | 498 | build_cmd.run(self) |
|
498 | 499 | # this one will only fire for build commands |
|
499 | 500 | if hasattr(self, 'build_lib'): |
|
500 | 501 | self._record_commit(self.build_lib) |
|
501 | 502 | |
|
502 | 503 | def make_release_tree(self, base_dir, files): |
|
503 | 504 | # this one will fire for sdist |
|
504 | 505 | build_cmd.make_release_tree(self, base_dir, files) |
|
505 | 506 | self._record_commit(base_dir) |
|
506 | 507 | |
|
507 | 508 | def _record_commit(self, base_dir): |
|
508 | 509 | import subprocess |
|
509 | 510 | proc = subprocess.Popen('git rev-parse --short HEAD', |
|
510 | 511 | stdout=subprocess.PIPE, |
|
511 | 512 | stderr=subprocess.PIPE, |
|
512 | 513 | shell=True) |
|
513 | 514 | repo_commit, _ = proc.communicate() |
|
514 | 515 | repo_commit = repo_commit.strip().decode("ascii") |
|
515 | 516 | |
|
516 | 517 | out_pth = pjoin(base_dir, pkg_dir, 'utils', '_sysinfo.py') |
|
517 | 518 | if os.path.isfile(out_pth) and not repo_commit: |
|
518 | 519 | # nothing to write, don't clobber |
|
519 | 520 | return |
|
520 | 521 | |
|
521 | 522 | print("writing git commit '%s' to %s" % (repo_commit, out_pth)) |
|
522 | 523 | |
|
523 | 524 | # remove to avoid overwriting original via hard link |
|
524 | 525 | try: |
|
525 | 526 | os.remove(out_pth) |
|
526 | 527 | except (IOError, OSError): |
|
527 | 528 | pass |
|
528 | 529 | with open(out_pth, 'w') as out_file: |
|
529 | 530 | out_file.writelines([ |
|
530 | 531 | '# GENERATED BY setup.py\n', |
|
531 | 532 | 'commit = "%s"\n' % repo_commit, |
|
532 | 533 | ]) |
|
533 | 534 | return require_submodules(MyBuildPy) |
|
534 | 535 | |
|
535 | 536 | |
|
536 | 537 | def require_submodules(command): |
|
537 | 538 | """decorator for instructing a command to check for submodules before running""" |
|
538 | 539 | class DecoratedCommand(command): |
|
539 | 540 | def run(self): |
|
540 | 541 | if not check_submodule_status(repo_root) == 'clean': |
|
541 | 542 | print("submodules missing! Run `setup.py submodule` and try again") |
|
542 | 543 | sys.exit(1) |
|
543 | 544 | command.run(self) |
|
544 | 545 | return DecoratedCommand |
|
545 | 546 | |
|
546 | 547 | #--------------------------------------------------------------------------- |
|
547 | 548 | # Notebook related |
|
548 | 549 | #--------------------------------------------------------------------------- |
|
549 | 550 | |
|
550 | 551 | class CompileCSS(Command): |
|
551 | 552 | """Recompile Notebook CSS |
|
552 | 553 | |
|
553 | 554 | Regenerate the compiled CSS from LESS sources. |
|
554 | 555 | |
|
555 | 556 | Requires various dev dependencies, such as fabric and lessc. |
|
556 | 557 | """ |
|
557 | 558 | description = "Recompile Notebook CSS" |
|
558 | 559 | user_options = [] |
|
559 | 560 | |
|
560 | 561 | def initialize_options(self): |
|
561 | 562 | pass |
|
562 | 563 | |
|
563 | 564 | def finalize_options(self): |
|
564 | 565 | pass |
|
565 | 566 | |
|
566 | 567 | def run(self): |
|
567 | 568 | call("fab css", shell=True, cwd=pjoin(repo_root, "IPython", "html")) |
|
568 | 569 | |
|
569 | 570 | class JavascriptVersion(Command): |
|
570 | 571 | """write the javascript version to notebook javascript""" |
|
571 | 572 | description = "Write IPython version to javascript" |
|
572 | 573 | user_options = [] |
|
573 | 574 | |
|
574 | 575 | def initialize_options(self): |
|
575 | 576 | pass |
|
576 | 577 | |
|
577 | 578 | def finalize_options(self): |
|
578 | 579 | pass |
|
579 | 580 | |
|
580 | 581 | def run(self): |
|
581 | 582 | nsfile = pjoin(repo_root, "IPython", "html", "static", "base", "js", "namespace.js") |
|
582 | 583 | with open(nsfile) as f: |
|
583 | 584 | lines = f.readlines() |
|
584 | 585 | with open(nsfile, 'w') as f: |
|
585 | 586 | for line in lines: |
|
586 | 587 | if line.startswith("IPython.version"): |
|
587 | 588 | line = 'IPython.version = "{0}";\n'.format(version) |
|
588 | 589 | f.write(line) |
|
589 | 590 |
General Comments 0
You need to be logged in to leave comments.
Login now