Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

store git commit hash in utils._sysinfo instead of hidden data file #1538

Merged
merged 2 commits into from

2 participants

@minrk
Owner

Behavior is essentially unchanged, but the hash is stored in a generated Python file instead of hidden data file.

Alternative to PR #1524
Closes #1484

setupbase.py
((5 lines not shown))
# 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 [
@fperez Owner
fperez added a note

Rather than looping manually, I'd just let the writelines method do it for us:

writelines([
   u"# GENERATED BY setup.py\n",
   u"commit = '%s'\n" % repo_commit,])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fperez
Owner

This looks good, with just a very minor tweak I suggested. I vastly prefer this to #1524, so I'll close that and we'll go with this solution instead. Thanks!

@fperez fperez referenced this pull request
Closed

unhide git_commit_info.ini #1524

@minrk
Owner

now uses writelines

@fperez fperez merged commit 576f6f9 into ipython:master
@fperez fperez referenced this pull request from a commit
@fperez fperez Emergency fix for py3 breakage introduced in 576f6f (merge of #1538)
Unicode literals (u'foo') aren't valid in Python 3.{1,2} (they will be
again in 3.3, and I failed to notice this.  This is a quick fix, will
discuss further on-list.  But I want master to remain working for py3
users.
74c10b3
@fperez fperez referenced this pull request from a commit
@fperez fperez Emergency fix for py3 breakage introduced in 576f6f (merge of #1538)
Unicode literals (u'foo') aren't valid in Python 3.{1,2} (they will be
again in 3.3, and I failed to notice this.  This is a quick fix, will
discuss further on-list.  But I want master to remain working for py3
users.
c5987c0
@mattvonrocketstein mattvonrocketstein referenced this pull request from a commit in mattvonrocketstein/ipython
@fperez fperez Emergency fix for py3 breakage introduced in 576f6f (merge of #1538)
Unicode literals (u'foo') aren't valid in Python 3.{1,2} (they will be
again in 3.3, and I failed to notice this.  This is a quick fix, will
discuss further on-list.  But I want master to remain working for py3
users.
e34e5de
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 30, 2012
  1. @minrk
Commits on Apr 14, 2012
  1. @minrk
This page is out of date. Refresh to see the latest.
View
9 IPython/.git_commit_info.ini
@@ -1,9 +0,0 @@
-# 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=
View
2  IPython/utils/_sysinfo.py
@@ -0,0 +1,2 @@
+# GENERATED BY setup.py
+commit = ''
View
38 IPython/utils/sysinfo.py
@@ -23,12 +23,7 @@
from ConfigParser import ConfigParser
from IPython.core import release
-from IPython.utils import py3compat
-
-#-----------------------------------------------------------------------------
-# Globals
-#-----------------------------------------------------------------------------
-COMMIT_INFO_FNAME = '.git_commit_info.ini'
+from IPython.utils import py3compat, _sysinfo
#-----------------------------------------------------------------------------
# Code
@@ -37,25 +32,18 @@
def pkg_commit_hash(pkg_path):
"""Get short form of commit hash given directory `pkg_path`
- There should be a file called 'COMMIT_INFO.txt' in `pkg_path`. This is a
- file in INI file format, with at least one section: ``commit hash``, and two
- variables ``archive_subst_hash`` and ``install_hash``. The first has a
- substitution pattern in it which may have been filled by the execution of
- ``git archive`` if this is an archive generated that way. The second is
- filled in by the installation, if the installation is from a git archive.
-
We get the commit hash from (in order of preference):
- * A substituted value in ``archive_subst_hash``
- * A written commit hash value in ``install_hash`
+ * IPython.utils._sysinfo.commit
* git output, if we are in a git repository
- If all these fail, we return a not-found placeholder tuple
+ If these fail, we return a not-found placeholder tuple
Parameters
----------
pkg_path : str
directory containing package
+ only used for getting commit from active repo
Returns
-------
@@ -65,21 +53,9 @@ def pkg_commit_hash(pkg_path):
short form of hash
"""
# Try and get commit from written commit text file
- pth = os.path.join(pkg_path, COMMIT_INFO_FNAME)
- if not os.path.isfile(pth):
- raise IOError('Missing commit info file %s' % pth)
- cfg_parser = ConfigParser()
- cfg_parser.read(pth)
- try:
- archive_subst = cfg_parser.get('commit hash', 'archive_subst_hash')
- except Exception:
- pass
- else:
- if not archive_subst.startswith('$Format'): # it has been substituted
- return 'archive substitution', archive_subst
- install_subst = cfg_parser.get('commit hash', 'install_hash')
- if install_subst != '':
- return 'installation', install_subst
+ if _sysinfo.commit:
+ return "installation", _sysinfo.commit
+
# maybe we are in a repository
proc = subprocess.Popen('git rev-parse --short HEAD',
stdout=subprocess.PIPE,
View
58 setupbase.py
@@ -20,6 +20,7 @@
#-------------------------------------------------------------------------------
# Imports
#-------------------------------------------------------------------------------
+import io
import os
import sys
@@ -368,41 +369,12 @@ 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``.
-
- 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.
+
+ records git commit in IPython.utils._sysinfo.commit
+
+ 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,12 @@ def run(self):
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:
+ out_file.writelines([
+ u"# GENERATED BY setup.py\n",
+ u"commit = '%s'\n" % repo_commit,
+ ])
return MyBuildPy
Something went wrong with that request. Please try again.