From 0547b1895a0761f651cd1b6d58e1cceaff1e52ee Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Thu, 24 Nov 2022 12:42:10 -0500 Subject: [PATCH] dist: get commit from Ubuntu PPA directory name if no git information --- setup.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index ecbcac22..23dbcdf3 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,8 @@ #!/usr/bin/env python3 +import os +import re import subprocess +import sys from glob import glob as _glob @@ -17,8 +20,13 @@ try: commit = subprocess.check_output(['git', 'describe', '--always'], stderr=subprocess.DEVNULL).strip().decode() with open('lib/solaar/commit', 'w') as vfile: vfile.write(f'{commit}\n') -except Exception: - pass +except Exception: # get commit from Ubuntu PPA directory name + dir = os.path.basename(sys.path[0]) + print('DIRECTORY', dir) + commit_match = re.search(r'git[0-9]*-([0-9a-f]*)~', dir) + if commit_match: + with open('lib/solaar/commit', 'w') as vfile: + vfile.write(f'{version}-g{commit_match[1]}\n') def _data_files():