Repository: ipython/ipython

Issue:
unhide .git_commit_info.ini
.git_commit_info is installed into system paths by setup.py
some security audit tools do not like this.

I see no reason why this file should be hidden, can the dot be removed?

see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=663256



Discussion:

Resolving patch:
diff --git a/IPython/utils/_sysinfo.py b/IPython/utils/_sysinfo.py
new file mode 100644
--- /dev/null
+++ b/IPython/utils/_sysinfo.py
@@ -0,0 +1,2 @@
+# GENERATED BY setup.py
+commit = ''
diff --git a/IPython/utils/sysinfo.py b/IPython/utils/sysinfo.py
--- a/IPython/utils/sysinfo.py
+++ b/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,
diff --git a/setupbase.py b/setupbase.py
--- a/setupbase.py
+++ b/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


Test patch: