##// END OF EJS Templates
setupbase.py (find_packages): Unused, remove
Matthias Koeppe -
Show More
@@ -1,332 +1,310 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
12 12 # Copyright (c) IPython Development Team.
13 13 # Distributed under the terms of the Modified BSD License.
14 14
15 15 import os
16 16 import re
17 17 import sys
18 18 from glob import glob
19 19 from logging import log
20 20
21 21 from setuptools import Command
22 22 from setuptools.command.build_py import build_py
23 23
24 24 from setuptools.command.install import install
25 25 from setuptools.command.install_scripts import install_scripts
26 26
27 27
28 28 #-------------------------------------------------------------------------------
29 29 # Useful globals and utility functions
30 30 #-------------------------------------------------------------------------------
31 31
32 32 # A few handy globals
33 33 isfile = os.path.isfile
34 34 pjoin = os.path.join
35 35 repo_root = os.path.dirname(os.path.abspath(__file__))
36 36
37 37 def execfile(fname, globs, locs=None):
38 38 locs = locs or globs
39 39 with open(fname, encoding="utf-8") as f:
40 40 exec(compile(f.read(), fname, "exec"), globs, locs)
41 41
42 42 # A little utility we'll need below, since glob() does NOT allow you to do
43 43 # exclusion on multiple endings!
44 44 def file_doesnt_endwith(test,endings):
45 45 """Return true if test is a file and its name does NOT end with any
46 46 of the strings listed in endings."""
47 47 if not isfile(test):
48 48 return False
49 49 for e in endings:
50 50 if test.endswith(e):
51 51 return False
52 52 return True
53 53
54 54 #---------------------------------------------------------------------------
55 55 # Basic project information
56 56 #---------------------------------------------------------------------------
57 57
58 58 # release.py contains version, authors, license, url, keywords, etc.
59 59 execfile(pjoin(repo_root, 'IPython','core','release.py'), globals())
60 60
61 61 # Create a dict with the basic information
62 62 # This dict is eventually passed to setup after additional keys are added.
63 63 setup_args = dict(
64 64 author = author,
65 65 author_email = author_email,
66 66 license = license,
67 67 )
68 68
69
70 #---------------------------------------------------------------------------
71 # Find packages
72 #---------------------------------------------------------------------------
73
74 def find_packages():
75 """
76 Find all of IPython's packages.
77 """
78 excludes = ['deathrow', 'quarantine']
79 packages = []
80 for directory, subdirs, files in os.walk("IPython"):
81 package = directory.replace(os.path.sep, ".")
82 if any(package.startswith("IPython." + exc) for exc in excludes):
83 # package is to be excluded (e.g. deathrow)
84 continue
85 if '__init__.py' not in files:
86 # not a package
87 continue
88 packages.append(package)
89 return packages
90
91 69 #---------------------------------------------------------------------------
92 70 # Check package data
93 71 #---------------------------------------------------------------------------
94 72
95 73 def check_package_data(package_data):
96 74 """verify that package_data globs make sense"""
97 75 print("checking package data")
98 76 for pkg, data in package_data.items():
99 77 pkg_root = pjoin(*pkg.split('.'))
100 78 for d in data:
101 79 path = pjoin(pkg_root, d)
102 80 if '*' in path:
103 81 assert len(glob(path)) > 0, "No files match pattern %s" % path
104 82 else:
105 83 assert os.path.exists(path), "Missing package data: %s" % path
106 84
107 85
108 86 def check_package_data_first(command):
109 87 """decorator for checking package_data before running a given command
110 88
111 89 Probably only needs to wrap build_py
112 90 """
113 91 class DecoratedCommand(command):
114 92 def run(self):
115 93 check_package_data(self.package_data)
116 94 command.run(self)
117 95 return DecoratedCommand
118 96
119 97
120 98 #---------------------------------------------------------------------------
121 99 # Find data files
122 100 #---------------------------------------------------------------------------
123 101
124 102 def find_data_files():
125 103 """
126 104 Find IPython's data_files.
127 105
128 106 Just man pages at this point.
129 107 """
130 108
131 109 if "freebsd" in sys.platform:
132 110 manpagebase = pjoin('man', 'man1')
133 111 else:
134 112 manpagebase = pjoin('share', 'man', 'man1')
135 113
136 114 # Simple file lists can be made by hand
137 115 manpages = [f for f in glob(pjoin('docs','man','*.1.gz')) if isfile(f)]
138 116 if not manpages:
139 117 # When running from a source tree, the manpages aren't gzipped
140 118 manpages = [f for f in glob(pjoin('docs','man','*.1')) if isfile(f)]
141 119
142 120 # And assemble the entire output list
143 121 data_files = [ (manpagebase, manpages) ]
144 122
145 123 return data_files
146 124
147 125
148 126 # The two functions below are copied from IPython.utils.path, so we don't need
149 127 # to import IPython during setup, which fails on Python 3.
150 128
151 129 def target_outdated(target,deps):
152 130 """Determine whether a target is out of date.
153 131
154 132 target_outdated(target,deps) -> 1/0
155 133
156 134 deps: list of filenames which MUST exist.
157 135 target: single filename which may or may not exist.
158 136
159 137 If target doesn't exist or is older than any file listed in deps, return
160 138 true, otherwise return false.
161 139 """
162 140 try:
163 141 target_time = os.path.getmtime(target)
164 142 except os.error:
165 143 return 1
166 144 for dep in deps:
167 145 dep_time = os.path.getmtime(dep)
168 146 if dep_time > target_time:
169 147 #print "For target",target,"Dep failed:",dep # dbg
170 148 #print "times (dep,tar):",dep_time,target_time # dbg
171 149 return 1
172 150 return 0
173 151
174 152
175 153 def target_update(target,deps,cmd):
176 154 """Update a target with a given command given a list of dependencies.
177 155
178 156 target_update(target,deps,cmd) -> runs cmd if target is outdated.
179 157
180 158 This is just a wrapper around target_outdated() which calls the given
181 159 command if target is outdated."""
182 160
183 161 if target_outdated(target,deps):
184 162 os.system(cmd)
185 163
186 164 #---------------------------------------------------------------------------
187 165 # Find scripts
188 166 #---------------------------------------------------------------------------
189 167
190 168 def find_entry_points():
191 169 """Defines the command line entry points for IPython
192 170
193 171 This always uses setuptools-style entry points. When setuptools is not in
194 172 use, our own build_scripts_entrypt class below parses these and builds
195 173 command line scripts.
196 174
197 175 Each of our entry points gets a plain name, e.g. ipython, and a name
198 176 suffixed with the Python major version number, e.g. ipython3.
199 177 """
200 178 ep = [
201 179 'ipython%s = IPython:start_ipython',
202 180 ]
203 181 major_suffix = str(sys.version_info[0])
204 182 return [e % "" for e in ep] + [e % major_suffix for e in ep]
205 183
206 184
207 185 class install_lib_symlink(Command):
208 186 user_options = [
209 187 ('install-dir=', 'd', "directory to install to"),
210 188 ]
211 189
212 190 def initialize_options(self):
213 191 self.install_dir = None
214 192
215 193 def finalize_options(self):
216 194 self.set_undefined_options('symlink',
217 195 ('install_lib', 'install_dir'),
218 196 )
219 197
220 198 def run(self):
221 199 if sys.platform == 'win32':
222 200 raise Exception("This doesn't work on Windows.")
223 201 pkg = os.path.join(os.getcwd(), 'IPython')
224 202 dest = os.path.join(self.install_dir, 'IPython')
225 203 if os.path.islink(dest):
226 204 print('removing existing symlink at %s' % dest)
227 205 os.unlink(dest)
228 206 print('symlinking %s -> %s' % (pkg, dest))
229 207 os.symlink(pkg, dest)
230 208
231 209 class unsymlink(install):
232 210 def run(self):
233 211 dest = os.path.join(self.install_lib, 'IPython')
234 212 if os.path.islink(dest):
235 213 print('removing symlink at %s' % dest)
236 214 os.unlink(dest)
237 215 else:
238 216 print('No symlink exists at %s' % dest)
239 217
240 218 class install_symlinked(install):
241 219 def run(self):
242 220 if sys.platform == 'win32':
243 221 raise Exception("This doesn't work on Windows.")
244 222
245 223 # Run all sub-commands (at least those that need to be run)
246 224 for cmd_name in self.get_sub_commands():
247 225 self.run_command(cmd_name)
248 226
249 227 # 'sub_commands': a list of commands this command might have to run to
250 228 # get its work done. See cmd.py for more info.
251 229 sub_commands = [('install_lib_symlink', lambda self:True),
252 230 ('install_scripts_sym', lambda self:True),
253 231 ]
254 232
255 233 class install_scripts_for_symlink(install_scripts):
256 234 """Redefined to get options from 'symlink' instead of 'install'.
257 235
258 236 I love distutils almost as much as I love setuptools.
259 237 """
260 238 def finalize_options(self):
261 239 self.set_undefined_options('build', ('build_scripts', 'build_dir'))
262 240 self.set_undefined_options('symlink',
263 241 ('install_scripts', 'install_dir'),
264 242 ('force', 'force'),
265 243 ('skip_build', 'skip_build'),
266 244 )
267 245
268 246
269 247 #---------------------------------------------------------------------------
270 248 # VCS related
271 249 #---------------------------------------------------------------------------
272 250
273 251
274 252 def git_prebuild(pkg_dir, build_cmd=build_py):
275 253 """Return extended build or sdist command class for recording commit
276 254
277 255 records git commit in IPython.utils._sysinfo.commit
278 256
279 257 for use in IPython.utils.sysinfo.sys_info() calls after installation.
280 258 """
281 259
282 260 class MyBuildPy(build_cmd):
283 261 ''' Subclass to write commit data into installation tree '''
284 262 def run(self):
285 263 # loose as `.dev` is suppose to be invalid
286 264 print("check version number")
287 265 loose_pep440re = re.compile(r'^(\d+)\.(\d+)\.(\d+((a|b|rc)\d+)?)(\.post\d+)?(\.dev\d*)?$')
288 266 if not loose_pep440re.match(version):
289 267 raise ValueError("Version number '%s' is not valid (should match [N!]N(.N)*[{a|b|rc}N][.postN][.devN])" % version)
290 268
291 269
292 270 build_cmd.run(self)
293 271 # this one will only fire for build commands
294 272 if hasattr(self, 'build_lib'):
295 273 self._record_commit(self.build_lib)
296 274
297 275 def make_release_tree(self, base_dir, files):
298 276 # this one will fire for sdist
299 277 build_cmd.make_release_tree(self, base_dir, files)
300 278 self._record_commit(base_dir)
301 279
302 280 def _record_commit(self, base_dir):
303 281 import subprocess
304 282 proc = subprocess.Popen('git rev-parse --short HEAD',
305 283 stdout=subprocess.PIPE,
306 284 stderr=subprocess.PIPE,
307 285 shell=True)
308 286 repo_commit, _ = proc.communicate()
309 287 repo_commit = repo_commit.strip().decode("ascii")
310 288
311 289 out_pth = pjoin(base_dir, pkg_dir, 'utils', '_sysinfo.py')
312 290 if os.path.isfile(out_pth) and not repo_commit:
313 291 # nothing to write, don't clobber
314 292 return
315 293
316 294 print("writing git commit '%s' to %s" % (repo_commit, out_pth))
317 295
318 296 # remove to avoid overwriting original via hard link
319 297 try:
320 298 os.remove(out_pth)
321 299 except (IOError, OSError):
322 300 pass
323 301 with open(out_pth, "w", encoding="utf-8") as out_file:
324 302 out_file.writelines(
325 303 [
326 304 "# GENERATED BY setup.py\n",
327 305 'commit = "%s"\n' % repo_commit,
328 306 ]
329 307 )
330 308
331 309 return MyBuildPy
332 310
General Comments 0
You need to be logged in to leave comments. Login now