Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e071291

Browse files
committed
store git commit hash in utils._sysinfo instead of hidden git_commit_info.ini data file.
1 parent 99d5bcb commit e071291

File tree

4 files changed

+23
-85
lines changed

4 files changed

+23
-85
lines changed

IPython/.git_commit_info.ini

Lines changed: 0 additions & 9 deletions
This file was deleted.

IPython/utils/_sysinfo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# GENERATED BY setup.py
2+
commit = ''

IPython/utils/sysinfo.py

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@
2323
from ConfigParser import ConfigParser
2424

2525
from IPython.core import release
26-
from IPython.utils import py3compat
27-
28-
#-----------------------------------------------------------------------------
29-
# Globals
30-
#-----------------------------------------------------------------------------
31-
COMMIT_INFO_FNAME = '.git_commit_info.ini'
26+
from IPython.utils import py3compat, _sysinfo
3227

3328
#-----------------------------------------------------------------------------
3429
# Code
@@ -37,25 +32,18 @@
3732
def pkg_commit_hash(pkg_path):
3833
"""Get short form of commit hash given directory `pkg_path`
3934
40-
There should be a file called 'COMMIT_INFO.txt' in `pkg_path`. This is a
41-
file in INI file format, with at least one section: ``commit hash``, and two
42-
variables ``archive_subst_hash`` and ``install_hash``. The first has a
43-
substitution pattern in it which may have been filled by the execution of
44-
``git archive`` if this is an archive generated that way. The second is
45-
filled in by the installation, if the installation is from a git archive.
46-
4735
We get the commit hash from (in order of preference):
4836
49-
* A substituted value in ``archive_subst_hash``
50-
* A written commit hash value in ``install_hash`
37+
* IPython.utils._sysinfo.commit
5138
* git output, if we are in a git repository
5239
53-
If all these fail, we return a not-found placeholder tuple
40+
If these fail, we return a not-found placeholder tuple
5441
5542
Parameters
5643
----------
5744
pkg_path : str
5845
directory containing package
46+
only used for getting commit from active repo
5947
6048
Returns
6149
-------
@@ -65,21 +53,9 @@ def pkg_commit_hash(pkg_path):
6553
short form of hash
6654
"""
6755
# Try and get commit from written commit text file
68-
pth = os.path.join(pkg_path, COMMIT_INFO_FNAME)
69-
if not os.path.isfile(pth):
70-
raise IOError('Missing commit info file %s' % pth)
71-
cfg_parser = ConfigParser()
72-
cfg_parser.read(pth)
73-
try:
74-
archive_subst = cfg_parser.get('commit hash', 'archive_subst_hash')
75-
except Exception:
76-
pass
77-
else:
78-
if not archive_subst.startswith('$Format'): # it has been substituted
79-
return 'archive substitution', archive_subst
80-
install_subst = cfg_parser.get('commit hash', 'install_hash')
81-
if install_subst != '':
82-
return 'installation', install_subst
56+
if _sysinfo.commit:
57+
return "installation", _sysinfo.commit
58+
8359
# maybe we are in a repository
8460
proc = subprocess.Popen('git rev-parse --short HEAD',
8561
stdout=subprocess.PIPE,

setupbase.py

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#-------------------------------------------------------------------------------
2121
# Imports
2222
#-------------------------------------------------------------------------------
23+
import io
2324
import os
2425
import sys
2526

@@ -330,41 +331,12 @@ def check_for_dependencies():
330331

331332
def record_commit_info(pkg_dir, build_cmd=build_py):
332333
""" Return extended build command class for recording commit
333-
334-
The extended command tries to run git to find the current commit, getting
335-
the empty string if it fails. It then writes the commit hash into a file
336-
in the `pkg_dir` path, named ``.git_commit_info.ini``.
337-
338-
In due course this information can be used by the package after it is
339-
installed, to tell you what commit it was installed from if known.
340-
341-
To make use of this system, you need a package with a .git_commit_info.ini
342-
file - e.g. ``myproject/.git_commit_info.ini`` - that might well look like
343-
this::
344-
345-
# This is an ini file that may contain information about the code state
346-
[commit hash]
347-
# The line below may contain a valid hash if it has been substituted
348-
# during 'git archive'
349-
archive_subst_hash=$Format:%h$
350-
# This line may be modified by the install process
351-
install_hash=
352-
353-
The .git_commit_info file above is also designed to be used with git
354-
substitution - so you probably also want a ``.gitattributes`` file in the
355-
root directory of your working tree that contains something like this::
356-
357-
myproject/.git_commit_info.ini export-subst
358-
359-
That will cause the ``.git_commit_info.ini`` file to get filled in by ``git
360-
archive`` - useful in case someone makes such an archive - for example with
361-
via the github 'download source' button.
362-
363-
Although all the above will work as is, you might consider having something
364-
like a ``get_info()`` function in your package to display the commit
365-
information at the terminal. See the ``pkg_info.py`` module in the nipy
366-
package for an example.
334+
335+
records git commit in IPython.utils._sysinfo.commit
336+
337+
for use in IPython.utils.sysinfo.sys_info() calls after installation.
367338
"""
339+
368340
class MyBuildPy(build_cmd):
369341
''' Subclass to write commit data into installation tree '''
370342
def run(self):
@@ -375,16 +347,13 @@ def run(self):
375347
stderr=subprocess.PIPE,
376348
shell=True)
377349
repo_commit, _ = proc.communicate()
350+
repo_commit = repo_commit.strip()
378351
# We write the installation commit even if it's empty
379-
cfg_parser = ConfigParser()
380-
cfg_parser.read(pjoin(pkg_dir, '.git_commit_info.ini'))
381-
if not cfg_parser.has_section('commit hash'):
382-
# just in case the ini file is empty or doesn't exist, somehow
383-
# we don't want the next line to raise
384-
cfg_parser.add_section('commit hash')
385-
cfg_parser.set('commit hash', 'install_hash', repo_commit.decode('ascii'))
386-
out_pth = pjoin(self.build_lib, pkg_dir, '.git_commit_info.ini')
387-
out_file = open(out_pth, 'wt')
388-
cfg_parser.write(out_file)
389-
out_file.close()
352+
out_pth = pjoin(self.build_lib, pkg_dir, 'utils', '_sysinfo.py')
353+
with io.open(out_pth, 'w') as out_file:
354+
for line in [
355+
u"# GENERATED BY setup.py",
356+
u"commit = '%s'" % repo_commit,
357+
]:
358+
out_file.write(line + u'\n')
390359
return MyBuildPy

0 commit comments

Comments
 (0)