##// END OF EJS Templates
store git commit hash in utils._sysinfo instead of hidden git_commit_info.ini data file.
MinRK -
Show More
@@ -0,0 +1,2 b''
1 # GENERATED BY setup.py
2 commit = ''
@@ -23,12 +23,7 b' import subprocess'
23 23 from ConfigParser import ConfigParser
24 24
25 25 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
32 27
33 28 #-----------------------------------------------------------------------------
34 29 # Code
@@ -37,25 +32,18 b" COMMIT_INFO_FNAME = '.git_commit_info.ini'"
37 32 def pkg_commit_hash(pkg_path):
38 33 """Get short form of commit hash given directory `pkg_path`
39 34
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
47 35 We get the commit hash from (in order of preference):
48 36
49 * A substituted value in ``archive_subst_hash``
50 * A written commit hash value in ``install_hash`
37 * IPython.utils._sysinfo.commit
51 38 * git output, if we are in a git repository
52 39
53 If all these fail, we return a not-found placeholder tuple
40 If these fail, we return a not-found placeholder tuple
54 41
55 42 Parameters
56 43 ----------
57 44 pkg_path : str
58 45 directory containing package
46 only used for getting commit from active repo
59 47
60 48 Returns
61 49 -------
@@ -65,21 +53,9 b' def pkg_commit_hash(pkg_path):'
65 53 short form of hash
66 54 """
67 55 # 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
83 59 # maybe we are in a repository
84 60 proc = subprocess.Popen('git rev-parse --short HEAD',
85 61 stdout=subprocess.PIPE,
@@ -20,6 +20,7 b' from __future__ import print_function'
20 20 #-------------------------------------------------------------------------------
21 21 # Imports
22 22 #-------------------------------------------------------------------------------
23 import io
23 24 import os
24 25 import sys
25 26
@@ -368,41 +369,12 b' def check_for_dependencies():'
368 369
369 370 def record_commit_info(pkg_dir, build_cmd=build_py):
370 371 """ Return extended build command class for recording commit
371
372 The extended command tries to run git to find the current commit, getting
373 the empty string if it fails. It then writes the commit hash into a file
374 in the `pkg_dir` path, named ``.git_commit_info.ini``.
375
376 In due course this information can be used by the package after it is
377 installed, to tell you what commit it was installed from if known.
378
379 To make use of this system, you need a package with a .git_commit_info.ini
380 file - e.g. ``myproject/.git_commit_info.ini`` - that might well look like
381 this::
382
383 # This is an ini file that may contain information about the code state
384 [commit hash]
385 # The line below may contain a valid hash if it has been substituted
386 # during 'git archive'
387 archive_subst_hash=$Format:%h$
388 # This line may be modified by the install process
389 install_hash=
390
391 The .git_commit_info file above is also designed to be used with git
392 substitution - so you probably also want a ``.gitattributes`` file in the
393 root directory of your working tree that contains something like this::
394
395 myproject/.git_commit_info.ini export-subst
396
397 That will cause the ``.git_commit_info.ini`` file to get filled in by ``git
398 archive`` - useful in case someone makes such an archive - for example with
399 via the github 'download source' button.
400
401 Although all the above will work as is, you might consider having something
402 like a ``get_info()`` function in your package to display the commit
403 information at the terminal. See the ``pkg_info.py`` module in the nipy
404 package for an example.
372
373 records git commit in IPython.utils._sysinfo.commit
374
375 for use in IPython.utils.sysinfo.sys_info() calls after installation.
405 376 """
377
406 378 class MyBuildPy(build_cmd):
407 379 ''' Subclass to write commit data into installation tree '''
408 380 def run(self):
@@ -413,16 +385,13 b' def record_commit_info(pkg_dir, build_cmd=build_py):'
413 385 stderr=subprocess.PIPE,
414 386 shell=True)
415 387 repo_commit, _ = proc.communicate()
388 repo_commit = repo_commit.strip()
416 389 # We write the installation commit even if it's empty
417 cfg_parser = ConfigParser()
418 cfg_parser.read(pjoin(pkg_dir, '.git_commit_info.ini'))
419 if not cfg_parser.has_section('commit hash'):
420 # just in case the ini file is empty or doesn't exist, somehow
421 # we don't want the next line to raise
422 cfg_parser.add_section('commit hash')
423 cfg_parser.set('commit hash', 'install_hash', repo_commit.decode('ascii'))
424 out_pth = pjoin(self.build_lib, pkg_dir, '.git_commit_info.ini')
425 out_file = open(out_pth, 'wt')
426 cfg_parser.write(out_file)
427 out_file.close()
390 out_pth = pjoin(self.build_lib, pkg_dir, 'utils', '_sysinfo.py')
391 with io.open(out_pth, 'w') as out_file:
392 for line in [
393 u"# GENERATED BY setup.py",
394 u"commit = '%s'" % repo_commit,
395 ]:
396 out_file.write(line + u'\n')
428 397 return MyBuildPy
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now