forked from PyMoDAQ/PyMoDAQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_describe.py
More file actions
38 lines (30 loc) · 979 Bytes
/
Copy pathgit_describe.py
File metadata and controls
38 lines (30 loc) · 979 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import subprocess
import sys
from pathlib import Path
FALLBACK_VERSION = "5.1.0"
SEPARATORS = ['~', '^', '-']
try:
package_path = Path(sys.argv[1])
# Get the last commit touching the package
commit_hash = (
subprocess.check_output(
["git", "rev-list", "-1", "HEAD", "--", str(package_path)],
stderr=subprocess.DEVNULL
).decode().strip()
)
try:
version = subprocess.check_output(
["git", "describe", "--contains", "--tags", commit_hash],
stderr=subprocess.DEVNULL
).decode().strip()
except subprocess.CalledProcessError:
version = subprocess.check_output(
["git", "describe", "--tags", commit_hash],
stderr=subprocess.DEVNULL
).decode().strip()
# Remove "~1" or similar suffixes
for separator in SEPARATORS:
version = version.split(separator)[0]
except Exception:
version = FALLBACK_VERSION
print(version)