Get short form of commit hash given directory `pkg_path` We get the commit hash from (in order of preference): * IPython.utils._sysinfo.commit * git output, if we are in a git repository If these fail, we return a not-found placeholder tuple Parameters ---------- pkg_
(pkg_path)
| 28 | #----------------------------------------------------------------------------- |
| 29 | |
| 30 | def pkg_commit_hash(pkg_path): |
| 31 | """Get short form of commit hash given directory `pkg_path` |
| 32 | |
| 33 | We get the commit hash from (in order of preference): |
| 34 | |
| 35 | * IPython.utils._sysinfo.commit |
| 36 | * git output, if we are in a git repository |
| 37 | |
| 38 | If these fail, we return a not-found placeholder tuple |
| 39 | |
| 40 | Parameters |
| 41 | ---------- |
| 42 | pkg_path : str |
| 43 | directory containing package |
| 44 | only used for getting commit from active repo |
| 45 | |
| 46 | Returns |
| 47 | ------- |
| 48 | hash_from : str |
| 49 | Where we got the hash from - description |
| 50 | hash_str : str |
| 51 | short form of hash |
| 52 | """ |
| 53 | # Try and get commit from written commit text file |
| 54 | if _sysinfo.commit: |
| 55 | return "installation", _sysinfo.commit |
| 56 | |
| 57 | # maybe we are in a repository |
| 58 | proc = subprocess.Popen('git rev-parse --short HEAD'.split(' '), |
| 59 | stdout=subprocess.PIPE, |
| 60 | stderr=subprocess.PIPE, |
| 61 | cwd=pkg_path) |
| 62 | repo_commit, _ = proc.communicate() |
| 63 | if repo_commit: |
| 64 | return 'repository', repo_commit.strip().decode('ascii') |
| 65 | return '(none found)', '<not found>' |
| 66 | |
| 67 | |
| 68 | def pkg_info(pkg_path): |