##// END OF EJS Templates
remove unused finction
M Bussonnier -
Show More
@@ -1,226 +1,214
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 import os
15 import os
16 import re
16 import re
17 import sys
17 import sys
18 from glob import glob
18 from glob import glob
19 from logging import log
19 from logging import log
20
20
21 from setuptools import Command
21 from setuptools import Command
22 from setuptools.command.build_py import build_py
22 from setuptools.command.build_py import build_py
23
23
24 from setuptools.command.install import install
24 from setuptools.command.install import install
25 from setuptools.command.install_scripts import install_scripts
25 from setuptools.command.install_scripts import install_scripts
26
26
27
27
28 #-------------------------------------------------------------------------------
28 #-------------------------------------------------------------------------------
29 # Useful globals and utility functions
29 # Useful globals and utility functions
30 #-------------------------------------------------------------------------------
30 #-------------------------------------------------------------------------------
31
31
32 # A few handy globals
32 # A few handy globals
33 isfile = os.path.isfile
33 isfile = os.path.isfile
34 pjoin = os.path.join
34 pjoin = os.path.join
35 repo_root = os.path.dirname(os.path.abspath(__file__))
35 repo_root = os.path.dirname(os.path.abspath(__file__))
36
36
37 def execfile(fname, globs, locs=None):
37 def execfile(fname, globs, locs=None):
38 locs = locs or globs
38 locs = locs or globs
39 with open(fname, encoding="utf-8") as f:
39 with open(fname, encoding="utf-8") as f:
40 exec(compile(f.read(), fname, "exec"), globs, locs)
40 exec(compile(f.read(), fname, "exec"), globs, locs)
41
41
42 # A little utility we'll need below, since glob() does NOT allow you to do
43 # exclusion on multiple endings!
44 def file_doesnt_endwith(test,endings):
45 """Return true if test is a file and its name does NOT end with any
46 of the strings listed in endings."""
47 if not isfile(test):
48 return False
49 for e in endings:
50 if test.endswith(e):
51 return False
52 return True
53
54 #---------------------------------------------------------------------------
42 #---------------------------------------------------------------------------
55 # Basic project information
43 # Basic project information
56 #---------------------------------------------------------------------------
44 #---------------------------------------------------------------------------
57
45
58 # release.py contains version, authors, license, url, keywords, etc.
46 # release.py contains version, authors, license, url, keywords, etc.
59 execfile(pjoin(repo_root, 'IPython','core','release.py'), globals())
47 execfile(pjoin(repo_root, 'IPython','core','release.py'), globals())
60
48
61 # Create a dict with the basic information
49 # Create a dict with the basic information
62 # This dict is eventually passed to setup after additional keys are added.
50 # This dict is eventually passed to setup after additional keys are added.
63 setup_args = dict(
51 setup_args = dict(
64 author = author,
52 author = author,
65 author_email = author_email,
53 author_email = author_email,
66 license = license,
54 license = license,
67 )
55 )
68
56
69 #---------------------------------------------------------------------------
57 #---------------------------------------------------------------------------
70 # Check package data
58 # Check package data
71 #---------------------------------------------------------------------------
59 #---------------------------------------------------------------------------
72
60
73 def check_package_data(package_data):
61 def check_package_data(package_data):
74 """verify that package_data globs make sense"""
62 """verify that package_data globs make sense"""
75 print("checking package data")
63 print("checking package data")
76 for pkg, data in package_data.items():
64 for pkg, data in package_data.items():
77 pkg_root = pjoin(*pkg.split('.'))
65 pkg_root = pjoin(*pkg.split('.'))
78 for d in data:
66 for d in data:
79 path = pjoin(pkg_root, d)
67 path = pjoin(pkg_root, d)
80 if '*' in path:
68 if '*' in path:
81 assert len(glob(path)) > 0, "No files match pattern %s" % path
69 assert len(glob(path)) > 0, "No files match pattern %s" % path
82 else:
70 else:
83 assert os.path.exists(path), "Missing package data: %s" % path
71 assert os.path.exists(path), "Missing package data: %s" % path
84
72
85
73
86 def check_package_data_first(command):
74 def check_package_data_first(command):
87 """decorator for checking package_data before running a given command
75 """decorator for checking package_data before running a given command
88
76
89 Probably only needs to wrap build_py
77 Probably only needs to wrap build_py
90 """
78 """
91 class DecoratedCommand(command):
79 class DecoratedCommand(command):
92 def run(self):
80 def run(self):
93 check_package_data(self.package_data)
81 check_package_data(self.package_data)
94 command.run(self)
82 command.run(self)
95 return DecoratedCommand
83 return DecoratedCommand
96
84
97
85
98 #---------------------------------------------------------------------------
86 #---------------------------------------------------------------------------
99 # Find data files
87 # Find data files
100 #---------------------------------------------------------------------------
88 #---------------------------------------------------------------------------
101
89
102 def find_data_files():
90 def find_data_files():
103 """
91 """
104 Find IPython's data_files.
92 Find IPython's data_files.
105
93
106 Just man pages at this point.
94 Just man pages at this point.
107 """
95 """
108
96
109 if "freebsd" in sys.platform:
97 if "freebsd" in sys.platform:
110 manpagebase = pjoin('man', 'man1')
98 manpagebase = pjoin('man', 'man1')
111 else:
99 else:
112 manpagebase = pjoin('share', 'man', 'man1')
100 manpagebase = pjoin('share', 'man', 'man1')
113
101
114 # Simple file lists can be made by hand
102 # Simple file lists can be made by hand
115 manpages = [f for f in glob(pjoin('docs','man','*.1.gz')) if isfile(f)]
103 manpages = [f for f in glob(pjoin('docs','man','*.1.gz')) if isfile(f)]
116 if not manpages:
104 if not manpages:
117 # When running from a source tree, the manpages aren't gzipped
105 # When running from a source tree, the manpages aren't gzipped
118 manpages = [f for f in glob(pjoin('docs','man','*.1')) if isfile(f)]
106 manpages = [f for f in glob(pjoin('docs','man','*.1')) if isfile(f)]
119
107
120 # And assemble the entire output list
108 # And assemble the entire output list
121 data_files = [ (manpagebase, manpages) ]
109 data_files = [ (manpagebase, manpages) ]
122
110
123 return data_files
111 return data_files
124
112
125
113
126 # The two functions below are copied from IPython.utils.path, so we don't need
114 # The two functions below are copied from IPython.utils.path, so we don't need
127 # to import IPython during setup, which fails on Python 3.
115 # to import IPython during setup, which fails on Python 3.
128
116
129 def target_outdated(target,deps):
117 def target_outdated(target,deps):
130 """Determine whether a target is out of date.
118 """Determine whether a target is out of date.
131
119
132 target_outdated(target,deps) -> 1/0
120 target_outdated(target,deps) -> 1/0
133
121
134 deps: list of filenames which MUST exist.
122 deps: list of filenames which MUST exist.
135 target: single filename which may or may not exist.
123 target: single filename which may or may not exist.
136
124
137 If target doesn't exist or is older than any file listed in deps, return
125 If target doesn't exist or is older than any file listed in deps, return
138 true, otherwise return false.
126 true, otherwise return false.
139 """
127 """
140 try:
128 try:
141 target_time = os.path.getmtime(target)
129 target_time = os.path.getmtime(target)
142 except os.error:
130 except os.error:
143 return 1
131 return 1
144 for dep in deps:
132 for dep in deps:
145 dep_time = os.path.getmtime(dep)
133 dep_time = os.path.getmtime(dep)
146 if dep_time > target_time:
134 if dep_time > target_time:
147 # print("For target",target,"Dep failed:",dep) # dbg
135 # print("For target",target,"Dep failed:",dep) # dbg
148 # print("times (dep,tar):",dep_time,target_time) # dbg
136 # print("times (dep,tar):",dep_time,target_time) # dbg
149 return 1
137 return 1
150 return 0
138 return 0
151
139
152
140
153 def target_update(target,deps,cmd):
141 def target_update(target,deps,cmd):
154 """Update a target with a given command given a list of dependencies.
142 """Update a target with a given command given a list of dependencies.
155
143
156 target_update(target,deps,cmd) -> runs cmd if target is outdated.
144 target_update(target,deps,cmd) -> runs cmd if target is outdated.
157
145
158 This is just a wrapper around target_outdated() which calls the given
146 This is just a wrapper around target_outdated() which calls the given
159 command if target is outdated."""
147 command if target is outdated."""
160
148
161 if target_outdated(target,deps):
149 if target_outdated(target,deps):
162 os.system(cmd)
150 os.system(cmd)
163
151
164 #---------------------------------------------------------------------------
152 #---------------------------------------------------------------------------
165 # VCS related
153 # VCS related
166 #---------------------------------------------------------------------------
154 #---------------------------------------------------------------------------
167
155
168 def git_prebuild(pkg_dir, build_cmd=build_py):
156 def git_prebuild(pkg_dir, build_cmd=build_py):
169 """Return extended build or sdist command class for recording commit
157 """Return extended build or sdist command class for recording commit
170
158
171 records git commit in IPython.utils._sysinfo.commit
159 records git commit in IPython.utils._sysinfo.commit
172
160
173 for use in IPython.utils.sysinfo.sys_info() calls after installation.
161 for use in IPython.utils.sysinfo.sys_info() calls after installation.
174 """
162 """
175
163
176 class MyBuildPy(build_cmd):
164 class MyBuildPy(build_cmd):
177 ''' Subclass to write commit data into installation tree '''
165 ''' Subclass to write commit data into installation tree '''
178 def run(self):
166 def run(self):
179 # loose as `.dev` is suppose to be invalid
167 # loose as `.dev` is suppose to be invalid
180 print("check version number")
168 print("check version number")
181 loose_pep440re = re.compile(r'^(\d+)\.(\d+)\.(\d+((a|b|rc)\d+)?)(\.post\d+)?(\.dev\d*)?$')
169 loose_pep440re = re.compile(r'^(\d+)\.(\d+)\.(\d+((a|b|rc)\d+)?)(\.post\d+)?(\.dev\d*)?$')
182 if not loose_pep440re.match(version):
170 if not loose_pep440re.match(version):
183 raise ValueError("Version number '%s' is not valid (should match [N!]N(.N)*[{a|b|rc}N][.postN][.devN])" % version)
171 raise ValueError("Version number '%s' is not valid (should match [N!]N(.N)*[{a|b|rc}N][.postN][.devN])" % version)
184
172
185
173
186 build_cmd.run(self)
174 build_cmd.run(self)
187 # this one will only fire for build commands
175 # this one will only fire for build commands
188 if hasattr(self, 'build_lib'):
176 if hasattr(self, 'build_lib'):
189 self._record_commit(self.build_lib)
177 self._record_commit(self.build_lib)
190
178
191 def make_release_tree(self, base_dir, files):
179 def make_release_tree(self, base_dir, files):
192 # this one will fire for sdist
180 # this one will fire for sdist
193 build_cmd.make_release_tree(self, base_dir, files)
181 build_cmd.make_release_tree(self, base_dir, files)
194 self._record_commit(base_dir)
182 self._record_commit(base_dir)
195
183
196 def _record_commit(self, base_dir):
184 def _record_commit(self, base_dir):
197 import subprocess
185 import subprocess
198 proc = subprocess.Popen('git rev-parse --short HEAD',
186 proc = subprocess.Popen('git rev-parse --short HEAD',
199 stdout=subprocess.PIPE,
187 stdout=subprocess.PIPE,
200 stderr=subprocess.PIPE,
188 stderr=subprocess.PIPE,
201 shell=True)
189 shell=True)
202 repo_commit, _ = proc.communicate()
190 repo_commit, _ = proc.communicate()
203 repo_commit = repo_commit.strip().decode("ascii")
191 repo_commit = repo_commit.strip().decode("ascii")
204
192
205 out_pth = pjoin(base_dir, pkg_dir, 'utils', '_sysinfo.py')
193 out_pth = pjoin(base_dir, pkg_dir, 'utils', '_sysinfo.py')
206 if os.path.isfile(out_pth) and not repo_commit:
194 if os.path.isfile(out_pth) and not repo_commit:
207 # nothing to write, don't clobber
195 # nothing to write, don't clobber
208 return
196 return
209
197
210 print("writing git commit '%s' to %s" % (repo_commit, out_pth))
198 print("writing git commit '%s' to %s" % (repo_commit, out_pth))
211
199
212 # remove to avoid overwriting original via hard link
200 # remove to avoid overwriting original via hard link
213 try:
201 try:
214 os.remove(out_pth)
202 os.remove(out_pth)
215 except (IOError, OSError):
203 except (IOError, OSError):
216 pass
204 pass
217 with open(out_pth, "w", encoding="utf-8") as out_file:
205 with open(out_pth, "w", encoding="utf-8") as out_file:
218 out_file.writelines(
206 out_file.writelines(
219 [
207 [
220 "# GENERATED BY setup.py\n",
208 "# GENERATED BY setup.py\n",
221 'commit = "%s"\n' % repo_commit,
209 'commit = "%s"\n' % repo_commit,
222 ]
210 ]
223 )
211 )
224
212
225 return MyBuildPy
213 return MyBuildPy
226
214
General Comments 0
You need to be logged in to leave comments. Login now