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