mirror of
https://github.com/jupyter/notebook.git
synced 2025-02-23 12:49:41 +08:00
store git commit hash in utils._sysinfo instead of hidden git_commit_info.ini data file.
This commit is contained in:
parent
c7de46e6cc
commit
0495291a83
59
setupbase.py
59
setupbase.py
@ -20,6 +20,7 @@ from __future__ import print_function
|
|||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# Imports
|
# Imports
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -368,41 +369,12 @@ def check_for_dependencies():
|
|||||||
|
|
||||||
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 command class for recording commit
|
||||||
|
|
||||||
The extended command tries to run git to find the current commit, getting
|
records git commit in IPython.utils._sysinfo.commit
|
||||||
the empty string if it fails. It then writes the commit hash into a file
|
|
||||||
in the `pkg_dir` path, named ``.git_commit_info.ini``.
|
for use in IPython.utils.sysinfo.sys_info() calls after installation.
|
||||||
|
|
||||||
In due course this information can be used by the package after it is
|
|
||||||
installed, to tell you what commit it was installed from if known.
|
|
||||||
|
|
||||||
To make use of this system, you need a package with a .git_commit_info.ini
|
|
||||||
file - e.g. ``myproject/.git_commit_info.ini`` - that might well look like
|
|
||||||
this::
|
|
||||||
|
|
||||||
# This is an ini file that may contain information about the code state
|
|
||||||
[commit hash]
|
|
||||||
# The line below may contain a valid hash if it has been substituted
|
|
||||||
# during 'git archive'
|
|
||||||
archive_subst_hash=$Format:%h$
|
|
||||||
# This line may be modified by the install process
|
|
||||||
install_hash=
|
|
||||||
|
|
||||||
The .git_commit_info file above is also designed to be used with git
|
|
||||||
substitution - so you probably also want a ``.gitattributes`` file in the
|
|
||||||
root directory of your working tree that contains something like this::
|
|
||||||
|
|
||||||
myproject/.git_commit_info.ini export-subst
|
|
||||||
|
|
||||||
That will cause the ``.git_commit_info.ini`` file to get filled in by ``git
|
|
||||||
archive`` - useful in case someone makes such an archive - for example with
|
|
||||||
via the github 'download source' button.
|
|
||||||
|
|
||||||
Although all the above will work as is, you might consider having something
|
|
||||||
like a ``get_info()`` function in your package to display the commit
|
|
||||||
information at the terminal. See the ``pkg_info.py`` module in the nipy
|
|
||||||
package for an example.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class MyBuildPy(build_cmd):
|
class MyBuildPy(build_cmd):
|
||||||
''' Subclass to write commit data into installation tree '''
|
''' Subclass to write commit data into installation tree '''
|
||||||
def run(self):
|
def run(self):
|
||||||
@ -413,16 +385,13 @@ def record_commit_info(pkg_dir, build_cmd=build_py):
|
|||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
shell=True)
|
shell=True)
|
||||||
repo_commit, _ = proc.communicate()
|
repo_commit, _ = proc.communicate()
|
||||||
|
repo_commit = repo_commit.strip()
|
||||||
# We write the installation commit even if it's empty
|
# We write the installation commit even if it's empty
|
||||||
cfg_parser = ConfigParser()
|
out_pth = pjoin(self.build_lib, pkg_dir, 'utils', '_sysinfo.py')
|
||||||
cfg_parser.read(pjoin(pkg_dir, '.git_commit_info.ini'))
|
with io.open(out_pth, 'w') as out_file:
|
||||||
if not cfg_parser.has_section('commit hash'):
|
for line in [
|
||||||
# just in case the ini file is empty or doesn't exist, somehow
|
u"# GENERATED BY setup.py",
|
||||||
# we don't want the next line to raise
|
u"commit = '%s'" % repo_commit,
|
||||||
cfg_parser.add_section('commit hash')
|
]:
|
||||||
cfg_parser.set('commit hash', 'install_hash', repo_commit.decode('ascii'))
|
out_file.write(line + u'\n')
|
||||||
out_pth = pjoin(self.build_lib, pkg_dir, '.git_commit_info.ini')
|
|
||||||
out_file = open(out_pth, 'wt')
|
|
||||||
cfg_parser.write(out_file)
|
|
||||||
out_file.close()
|
|
||||||
return MyBuildPy
|
return MyBuildPy
|
||||||
|
Loading…
Reference in New Issue
Block a user