Show More
@@ -23,12 +23,7 b' import subprocess' | |||||
23 | from ConfigParser import ConfigParser |
|
23 | from ConfigParser import ConfigParser | |
24 |
|
24 | |||
25 | from IPython.core import release |
|
25 | from IPython.core import release | |
26 | from IPython.utils import py3compat |
|
26 | from IPython.utils import py3compat, _sysinfo | |
27 |
|
||||
28 | #----------------------------------------------------------------------------- |
|
|||
29 | # Globals |
|
|||
30 | #----------------------------------------------------------------------------- |
|
|||
31 | COMMIT_INFO_FNAME = '.git_commit_info.ini' |
|
|||
32 |
|
27 | |||
33 | #----------------------------------------------------------------------------- |
|
28 | #----------------------------------------------------------------------------- | |
34 | # Code |
|
29 | # Code | |
@@ -37,25 +32,18 b" COMMIT_INFO_FNAME = '.git_commit_info.ini'" | |||||
37 | def pkg_commit_hash(pkg_path): |
|
32 | def pkg_commit_hash(pkg_path): | |
38 | """Get short form of commit hash given directory `pkg_path` |
|
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 | We get the commit hash from (in order of preference): |
|
35 | We get the commit hash from (in order of preference): | |
48 |
|
36 | |||
49 | * A substituted value in ``archive_subst_hash`` |
|
37 | * IPython.utils._sysinfo.commit | |
50 | * A written commit hash value in ``install_hash` |
|
|||
51 | * git output, if we are in a git repository |
|
38 | * git output, if we are in a git repository | |
52 |
|
39 | |||
53 |
If |
|
40 | If these fail, we return a not-found placeholder tuple | |
54 |
|
41 | |||
55 | Parameters |
|
42 | Parameters | |
56 | ---------- |
|
43 | ---------- | |
57 | pkg_path : str |
|
44 | pkg_path : str | |
58 | directory containing package |
|
45 | directory containing package | |
|
46 | only used for getting commit from active repo | |||
59 |
|
47 | |||
60 | Returns |
|
48 | Returns | |
61 | ------- |
|
49 | ------- | |
@@ -65,21 +53,9 b' def pkg_commit_hash(pkg_path):' | |||||
65 | short form of hash |
|
53 | short form of hash | |
66 | """ |
|
54 | """ | |
67 | # Try and get commit from written commit text file |
|
55 | # Try and get commit from written commit text file | |
68 | pth = os.path.join(pkg_path, COMMIT_INFO_FNAME) |
|
56 | if _sysinfo.commit: | |
69 | if not os.path.isfile(pth): |
|
57 | return "installation", _sysinfo.commit | |
70 | raise IOError('Missing commit info file %s' % pth) |
|
58 | ||
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 |
|
|||
83 | # maybe we are in a repository |
|
59 | # maybe we are in a repository | |
84 | proc = subprocess.Popen('git rev-parse --short HEAD', |
|
60 | proc = subprocess.Popen('git rev-parse --short HEAD', | |
85 | stdout=subprocess.PIPE, |
|
61 | stdout=subprocess.PIPE, |
@@ -20,6 +20,7 b' from __future__ import print_function' | |||||
20 | #------------------------------------------------------------------------------- |
|
20 | #------------------------------------------------------------------------------- | |
21 | # Imports |
|
21 | # Imports | |
22 | #------------------------------------------------------------------------------- |
|
22 | #------------------------------------------------------------------------------- | |
|
23 | import io | |||
23 | import os |
|
24 | import os | |
24 | import sys |
|
25 | import sys | |
25 |
|
26 | |||
@@ -368,41 +369,12 b' def check_for_dependencies():' | |||||
368 |
|
369 | |||
369 | def record_commit_info(pkg_dir, build_cmd=build_py): |
|
370 | def record_commit_info(pkg_dir, build_cmd=build_py): | |
370 | """ Return extended build command class for recording commit |
|
371 | """ Return extended build command class for recording commit | |
371 |
|
372 | |||
372 | The extended command tries to run git to find the current commit, getting |
|
373 | records git commit in IPython.utils._sysinfo.commit | |
373 | the empty string if it fails. It then writes the commit hash into a file |
|
374 | ||
374 | in the `pkg_dir` path, named ``.git_commit_info.ini``. |
|
375 | for use in IPython.utils.sysinfo.sys_info() calls after installation. | |
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. |
|
|||
405 | """ |
|
376 | """ | |
|
377 | ||||
406 | class MyBuildPy(build_cmd): |
|
378 | class MyBuildPy(build_cmd): | |
407 | ''' Subclass to write commit data into installation tree ''' |
|
379 | ''' Subclass to write commit data into installation tree ''' | |
408 | def run(self): |
|
380 | def run(self): | |
@@ -413,16 +385,13 b' def record_commit_info(pkg_dir, build_cmd=build_py):' | |||||
413 | stderr=subprocess.PIPE, |
|
385 | stderr=subprocess.PIPE, | |
414 | shell=True) |
|
386 | shell=True) | |
415 | repo_commit, _ = proc.communicate() |
|
387 | repo_commit, _ = proc.communicate() | |
|
388 | repo_commit = repo_commit.strip() | |||
416 | # We write the installation commit even if it's empty |
|
389 | # We write the installation commit even if it's empty | |
417 | cfg_parser = ConfigParser() |
|
390 | out_pth = pjoin(self.build_lib, pkg_dir, 'utils', '_sysinfo.py') | |
418 | cfg_parser.read(pjoin(pkg_dir, '.git_commit_info.ini')) |
|
391 | with io.open(out_pth, 'w') as out_file: | |
419 | if not cfg_parser.has_section('commit hash'): |
|
392 | for line in [ | |
420 | # just in case the ini file is empty or doesn't exist, somehow |
|
393 | u"# GENERATED BY setup.py", | |
421 | # we don't want the next line to raise |
|
394 | u"commit = '%s'" % repo_commit, | |
422 | cfg_parser.add_section('commit hash') |
|
395 | ]: | |
423 | cfg_parser.set('commit hash', 'install_hash', repo_commit.decode('ascii')) |
|
396 | out_file.write(line + u'\n') | |
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() |
|
|||
428 | return MyBuildPy |
|
397 | return MyBuildPy |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now