store git commit hash in utils._sysinfo instead of hidden git_commit_info.ini data file.

This commit is contained in:
MinRK 2012-03-26 14:40:06 -07:00
parent c7de46e6cc
commit 0495291a83

View File

@ -20,6 +20,7 @@ from __future__ import print_function
#-------------------------------------------------------------------------------
# Imports
#-------------------------------------------------------------------------------
import io
import os
import sys
@ -369,40 +370,11 @@ def check_for_dependencies():
def record_commit_info(pkg_dir, build_cmd=build_py):
""" Return extended build command class for recording commit
The extended command tries to run git to find the current commit, getting
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``.
records git commit in IPython.utils._sysinfo.commit
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.
for use in IPython.utils.sysinfo.sys_info() calls after installation.
"""
class MyBuildPy(build_cmd):
''' Subclass to write commit data into installation tree '''
def run(self):
@ -413,16 +385,13 @@ def record_commit_info(pkg_dir, build_cmd=build_py):
stderr=subprocess.PIPE,
shell=True)
repo_commit, _ = proc.communicate()
repo_commit = repo_commit.strip()
# We write the installation commit even if it's empty
cfg_parser = ConfigParser()
cfg_parser.read(pjoin(pkg_dir, '.git_commit_info.ini'))
if not cfg_parser.has_section('commit hash'):
# just in case the ini file is empty or doesn't exist, somehow
# we don't want the next line to raise
cfg_parser.add_section('commit hash')
cfg_parser.set('commit hash', 'install_hash', repo_commit.decode('ascii'))
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()
out_pth = pjoin(self.build_lib, pkg_dir, 'utils', '_sysinfo.py')
with io.open(out_pth, 'w') as out_file:
for line in [
u"# GENERATED BY setup.py",
u"commit = '%s'" % repo_commit,
]:
out_file.write(line + u'\n')
return MyBuildPy