mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-27 04:20:22 +08:00
Merge pull request #2068 from minrk/sysinfo
record sysinfo in sdist closes #2054
This commit is contained in:
commit
3171c69214
13
setup.py
13
setup.py
@ -52,7 +52,6 @@ from glob import glob
|
|||||||
if os.path.exists('MANIFEST'): os.remove('MANIFEST')
|
if os.path.exists('MANIFEST'): os.remove('MANIFEST')
|
||||||
|
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
from distutils.command.upload import upload
|
|
||||||
|
|
||||||
# On Python 3, we need distribute (new setuptools) to do the 2to3 conversion
|
# On Python 3, we need distribute (new setuptools) to do the 2to3 conversion
|
||||||
if PY3:
|
if PY3:
|
||||||
@ -166,14 +165,16 @@ packages = find_packages()
|
|||||||
package_data = find_package_data()
|
package_data = find_package_data()
|
||||||
data_files = find_data_files()
|
data_files = find_data_files()
|
||||||
|
|
||||||
setup_args['cmdclass'] = {'build_py': record_commit_info('IPython')}
|
|
||||||
setup_args['packages'] = packages
|
setup_args['packages'] = packages
|
||||||
setup_args['package_data'] = package_data
|
setup_args['package_data'] = package_data
|
||||||
setup_args['data_files'] = data_files
|
setup_args['data_files'] = data_files
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# custom upload_wininst command
|
# custom distutils commands
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
# imports here, so they are after setuptools import if there was one
|
||||||
|
from distutils.command.sdist import sdist
|
||||||
|
from distutils.command.upload import upload
|
||||||
|
|
||||||
class UploadWindowsInstallers(upload):
|
class UploadWindowsInstallers(upload):
|
||||||
|
|
||||||
@ -194,7 +195,11 @@ class UploadWindowsInstallers(upload):
|
|||||||
for dist_file in glob(self.files):
|
for dist_file in glob(self.files):
|
||||||
self.upload_file('bdist_wininst', 'any', dist_file)
|
self.upload_file('bdist_wininst', 'any', dist_file)
|
||||||
|
|
||||||
setup_args['cmdclass']['upload_wininst'] = UploadWindowsInstallers
|
setup_args['cmdclass'] = {
|
||||||
|
'build_py': record_commit_info('IPython'),
|
||||||
|
'sdist' : record_commit_info('IPython', sdist),
|
||||||
|
'upload_wininst' : UploadWindowsInstallers,
|
||||||
|
}
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
# Handle scripts, dependencies, and setuptools specific things
|
# Handle scripts, dependencies, and setuptools specific things
|
||||||
|
32
setupbase.py
32
setupbase.py
@ -369,7 +369,7 @@ def check_for_dependencies():
|
|||||||
check_for_readline()
|
check_for_readline()
|
||||||
|
|
||||||
def record_commit_info(pkg_dir, build_cmd=build_py):
|
def record_commit_info(pkg_dir, build_cmd=build_py):
|
||||||
""" Return extended build command class for recording commit
|
""" Return extended build or sdist command class for recording commit
|
||||||
|
|
||||||
records git commit in IPython.utils._sysinfo.commit
|
records git commit in IPython.utils._sysinfo.commit
|
||||||
|
|
||||||
@ -380,18 +380,40 @@ def record_commit_info(pkg_dir, build_cmd=build_py):
|
|||||||
''' Subclass to write commit data into installation tree '''
|
''' Subclass to write commit data into installation tree '''
|
||||||
def run(self):
|
def run(self):
|
||||||
build_cmd.run(self)
|
build_cmd.run(self)
|
||||||
|
# this one will only fire for build commands
|
||||||
|
if hasattr(self, 'build_lib'):
|
||||||
|
self._record_commit(self.build_lib)
|
||||||
|
|
||||||
|
def make_release_tree(self, base_dir, files):
|
||||||
|
# this one will fire for sdist
|
||||||
|
build_cmd.make_release_tree(self, base_dir, files)
|
||||||
|
self._record_commit(base_dir)
|
||||||
|
|
||||||
|
def _record_commit(self, base_dir):
|
||||||
import subprocess
|
import subprocess
|
||||||
proc = subprocess.Popen('git rev-parse --short HEAD',
|
proc = subprocess.Popen('git rev-parse --short HEAD',
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
shell=True)
|
shell=True)
|
||||||
repo_commit, _ = proc.communicate()
|
repo_commit, _ = proc.communicate()
|
||||||
repo_commit = repo_commit.strip()
|
repo_commit = repo_commit.strip().decode("ascii")
|
||||||
# We write the installation commit even if it's empty
|
|
||||||
out_pth = pjoin(self.build_lib, pkg_dir, 'utils', '_sysinfo.py')
|
out_pth = pjoin(base_dir, pkg_dir, 'utils', '_sysinfo.py')
|
||||||
|
if os.path.isfile(out_pth) and not repo_commit:
|
||||||
|
# nothing to write, don't clobber
|
||||||
|
return
|
||||||
|
|
||||||
|
print("writing git commit '%s' to %s" % (repo_commit, out_pth))
|
||||||
|
|
||||||
|
# remove to avoid overwriting original via hard link
|
||||||
|
try:
|
||||||
|
os.remove(out_pth)
|
||||||
|
except (IOError, OSError):
|
||||||
|
pass
|
||||||
|
print (out_pth, file=sys.stderr)
|
||||||
with open(out_pth, 'w') as out_file:
|
with open(out_pth, 'w') as out_file:
|
||||||
out_file.writelines([
|
out_file.writelines([
|
||||||
'# GENERATED BY setup.py\n',
|
'# GENERATED BY setup.py\n',
|
||||||
'commit = "%s"\n' % repo_commit.decode('ascii'),
|
'commit = "%s"\n' % repo_commit,
|
||||||
])
|
])
|
||||||
return MyBuildPy
|
return MyBuildPy
|
||||||
|
Loading…
Reference in New Issue
Block a user