-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
37 lines (27 loc) · 1.07 KB
/
setup.py
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 re
from setuptools import setup
def get_version() -> str:
version = ""
with open("starlette_plus/__init__.py") as f:
match = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE)
if not match or not match.group(1):
raise RuntimeError("Version is not set")
version = match.group(1)
if version.endswith(("dev", "a", "b", "rc")):
# append version identifier based on commit count
try:
import subprocess
p = subprocess.Popen(["git", "rev-list", "--count", "HEAD"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, _ = p.communicate()
if out:
version += out.decode("utf-8").strip()
p = subprocess.Popen(
["git", "rev-parse", "--short", "HEAD"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
out, _ = p.communicate()
if out:
version += "+g" + out.decode("utf-8").strip()
except Exception:
pass
return version
setup(version=get_version())