Skip to content

Commit f0d6d49

Browse files
committed
Add setup.py for versioning
1 parent 6dac202 commit f0d6d49

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

setup.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import re
2+
3+
from setuptools import setup
4+
5+
6+
def get_version() -> str:
7+
version = ""
8+
with open("starlete_plus/__init__.py") as f:
9+
match = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE)
10+
11+
if not match or not match.group(1):
12+
raise RuntimeError("Version is not set")
13+
14+
version = match.group(1)
15+
16+
if version.endswith(("dev", "a", "b", "rc")):
17+
# append version identifier based on commit count
18+
try:
19+
import subprocess
20+
21+
p = subprocess.Popen(["git", "rev-list", "--count", "HEAD"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
22+
out, _ = p.communicate()
23+
if out:
24+
version += out.decode("utf-8").strip()
25+
p = subprocess.Popen(
26+
["git", "rev-parse", "--short", "HEAD"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
27+
)
28+
out, _ = p.communicate()
29+
if out:
30+
version += "+g" + out.decode("utf-8").strip()
31+
except Exception:
32+
pass
33+
34+
return version
35+
36+
37+
setup(version=get_version())

0 commit comments

Comments
 (0)