(version)
| 19 | |
| 20 | |
| 21 | def git_version(version): |
| 22 | # Append last commit date and hash to dev version information, |
| 23 | # if available |
| 24 | |
| 25 | import subprocess |
| 26 | import os.path |
| 27 | |
| 28 | git_hash = '' |
| 29 | try: |
| 30 | p = subprocess.Popen( |
| 31 | ['git', 'log', '-1', '--format="%H %aI"'], |
| 32 | stdout=subprocess.PIPE, |
| 33 | stderr=subprocess.PIPE, |
| 34 | cwd=os.path.dirname(__file__), |
| 35 | ) |
| 36 | except FileNotFoundError: |
| 37 | pass |
| 38 | else: |
| 39 | out, err = p.communicate() |
| 40 | if p.returncode == 0: |
| 41 | git_hash, git_date = ( |
| 42 | out.decode('utf-8') |
| 43 | .strip() |
| 44 | .replace('"', '') |
| 45 | .split('T')[0] |
| 46 | .replace('-', '') |
| 47 | .split() |
| 48 | ) |
| 49 | |
| 50 | # Only attach git tag to development versions |
| 51 | if 'dev' in version: |
| 52 | version += f'+git{git_date}.{git_hash[:7]}' |
| 53 | |
| 54 | return version, git_hash |
| 55 | |
| 56 | |
| 57 | if __name__ == "__main__": |
no test coverage detected