Skip to content

Commit dee0033

Browse files
committed
Add git count for devN without hash
1 parent a1309bb commit dee0033

File tree

3 files changed

+40
-30
lines changed

3 files changed

+40
-30
lines changed

setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from setuptools import setup # type: ignore
2+
3+
from twitchio._version import _get_version
4+
5+
6+
setup(version=_get_version(with_hash=False))

twitchio/__main__.py

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424

2525
import argparse
2626
import platform
27-
import re
2827
import sys
2928

3029
import aiohttp
3130

31+
from ._version import _get_version
32+
3233

3334
try:
3435
import starlette
@@ -51,35 +52,6 @@
5152
args = parser.parse_args()
5253

5354

54-
def _get_version() -> str:
55-
version = ""
56-
with open("twitchio/__init__.py") as f:
57-
match = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE)
58-
59-
if not match or not match.group(1):
60-
raise RuntimeError("Version is not set")
61-
62-
version = match.group(1)
63-
64-
if version.endswith(("dev", "a", "b", "rc")):
65-
# append version identifier based on commit count
66-
try:
67-
import subprocess
68-
69-
p = subprocess.Popen(["git", "rev-list", "--count", "HEAD"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
70-
out, _ = p.communicate()
71-
if out:
72-
version += out.decode("utf-8").strip()
73-
p = subprocess.Popen(["git", "rev-parse", "--short", "HEAD"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
74-
out, _ = p.communicate()
75-
if out:
76-
version += "+g" + out.decode("utf-8").strip()
77-
except Exception:
78-
pass
79-
80-
return version
81-
82-
8355
def version_info() -> None:
8456
python_info = "\n".join(sys.version.split("\n"))
8557

twitchio/_version.py

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

0 commit comments

Comments
 (0)