Show More
@@ -52,7 +52,6 b' from glob import glob' | |||||
52 | if os.path.exists('MANIFEST'): os.remove('MANIFEST') |
|
52 | if os.path.exists('MANIFEST'): os.remove('MANIFEST') | |
53 |
|
53 | |||
54 | from distutils.core import setup |
|
54 | from distutils.core import setup | |
55 | from distutils.command.upload import upload |
|
|||
56 |
|
55 | |||
57 | # On Python 3, we need distribute (new setuptools) to do the 2to3 conversion |
|
56 | # On Python 3, we need distribute (new setuptools) to do the 2to3 conversion | |
58 | if PY3: |
|
57 | if PY3: | |
@@ -166,14 +165,16 b' packages = find_packages()' | |||||
166 | package_data = find_package_data() |
|
165 | package_data = find_package_data() | |
167 | data_files = find_data_files() |
|
166 | data_files = find_data_files() | |
168 |
|
167 | |||
169 | setup_args['cmdclass'] = {'build_py': record_commit_info('IPython')} |
|
|||
170 | setup_args['packages'] = packages |
|
168 | setup_args['packages'] = packages | |
171 | setup_args['package_data'] = package_data |
|
169 | setup_args['package_data'] = package_data | |
172 | setup_args['data_files'] = data_files |
|
170 | setup_args['data_files'] = data_files | |
173 |
|
171 | |||
174 | #--------------------------------------------------------------------------- |
|
172 | #--------------------------------------------------------------------------- | |
175 |
# custom |
|
173 | # custom distutils commands | |
176 | #--------------------------------------------------------------------------- |
|
174 | #--------------------------------------------------------------------------- | |
|
175 | # imports here, so they are after setuptools import if there was one | |||
|
176 | from distutils.command.sdist import sdist | |||
|
177 | from distutils.command.upload import upload | |||
177 |
|
178 | |||
178 | class UploadWindowsInstallers(upload): |
|
179 | class UploadWindowsInstallers(upload): | |
179 |
|
180 | |||
@@ -194,7 +195,11 b' class UploadWindowsInstallers(upload):' | |||||
194 | for dist_file in glob(self.files): |
|
195 | for dist_file in glob(self.files): | |
195 | self.upload_file('bdist_wininst', 'any', dist_file) |
|
196 | self.upload_file('bdist_wininst', 'any', dist_file) | |
196 |
|
197 | |||
197 | setup_args['cmdclass']['upload_wininst'] = UploadWindowsInstallers |
|
198 | setup_args['cmdclass'] = { | |
|
199 | 'build_py': record_commit_info('IPython'), | |||
|
200 | 'sdist' : record_commit_info('IPython', sdist), | |||
|
201 | 'upload_wininst' : UploadWindowsInstallers, | |||
|
202 | } | |||
198 |
|
203 | |||
199 | #--------------------------------------------------------------------------- |
|
204 | #--------------------------------------------------------------------------- | |
200 | # Handle scripts, dependencies, and setuptools specific things |
|
205 | # Handle scripts, dependencies, and setuptools specific things |
@@ -369,7 +369,7 b' def check_for_dependencies():' | |||||
369 | check_for_readline() |
|
369 | check_for_readline() | |
370 |
|
370 | |||
371 | def record_commit_info(pkg_dir, build_cmd=build_py): |
|
371 | def record_commit_info(pkg_dir, build_cmd=build_py): | |
372 | """ Return extended build command class for recording commit |
|
372 | """ Return extended build or sdist command class for recording commit | |
373 |
|
373 | |||
374 | records git commit in IPython.utils._sysinfo.commit |
|
374 | records git commit in IPython.utils._sysinfo.commit | |
375 |
|
375 | |||
@@ -380,18 +380,40 b' def record_commit_info(pkg_dir, build_cmd=build_py):' | |||||
380 | ''' Subclass to write commit data into installation tree ''' |
|
380 | ''' Subclass to write commit data into installation tree ''' | |
381 | def run(self): |
|
381 | def run(self): | |
382 | build_cmd.run(self) |
|
382 | build_cmd.run(self) | |
|
383 | # this one will only fire for build commands | |||
|
384 | if hasattr(self, 'build_lib'): | |||
|
385 | self._record_commit(self.build_lib) | |||
|
386 | ||||
|
387 | def make_release_tree(self, base_dir, files): | |||
|
388 | # this one will fire for sdist | |||
|
389 | build_cmd.make_release_tree(self, base_dir, files) | |||
|
390 | self._record_commit(base_dir) | |||
|
391 | ||||
|
392 | def _record_commit(self, base_dir): | |||
383 | import subprocess |
|
393 | import subprocess | |
384 | proc = subprocess.Popen('git rev-parse --short HEAD', |
|
394 | proc = subprocess.Popen('git rev-parse --short HEAD', | |
385 | stdout=subprocess.PIPE, |
|
395 | stdout=subprocess.PIPE, | |
386 | stderr=subprocess.PIPE, |
|
396 | stderr=subprocess.PIPE, | |
387 | shell=True) |
|
397 | shell=True) | |
388 | repo_commit, _ = proc.communicate() |
|
398 | repo_commit, _ = proc.communicate() | |
389 | repo_commit = repo_commit.strip() |
|
399 | repo_commit = repo_commit.strip().decode("ascii") | |
390 | # We write the installation commit even if it's empty |
|
400 | ||
391 |
out_pth = pjoin( |
|
401 | out_pth = pjoin(base_dir, pkg_dir, 'utils', '_sysinfo.py') | |
|
402 | if os.path.isfile(out_pth) and not repo_commit: | |||
|
403 | # nothing to write, don't clobber | |||
|
404 | return | |||
|
405 | ||||
|
406 | print("writing git commit '%s' to %s" % (repo_commit, out_pth)) | |||
|
407 | ||||
|
408 | # remove to avoid overwriting original via hard link | |||
|
409 | try: | |||
|
410 | os.remove(out_pth) | |||
|
411 | except (IOError, OSError): | |||
|
412 | pass | |||
|
413 | print (out_pth, file=sys.stderr) | |||
392 | with open(out_pth, 'w') as out_file: |
|
414 | with open(out_pth, 'w') as out_file: | |
393 | out_file.writelines([ |
|
415 | out_file.writelines([ | |
394 | '# GENERATED BY setup.py\n', |
|
416 | '# GENERATED BY setup.py\n', | |
395 |
'commit = "%s"\n' % repo_commit |
|
417 | 'commit = "%s"\n' % repo_commit, | |
396 | ]) |
|
418 | ]) | |
397 | return MyBuildPy |
|
419 | return MyBuildPy |
General Comments 0
You need to be logged in to leave comments.
Login now