Skip to content

Commit a25d91e

Browse files
committed
More version specifier fixes.
1 parent dee0033 commit a25d91e

File tree

4 files changed

+59
-37
lines changed

4 files changed

+59
-37
lines changed

setup.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
1+
import re
2+
13
from setuptools import setup # type: ignore
24

3-
from twitchio._version import _get_version
5+
6+
def get_version() -> str:
7+
version = ""
8+
with open("twitchio/__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+
except Exception:
26+
pass
27+
28+
return version
429

530

6-
setup(version=_get_version(with_hash=False))
31+
setup(version=get_version())

twitchio/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
__copyright__ = "Copyright 2017-Present (c) TwitchIO, PythonistaGuild"
2929
__version__ = "3.0.0dev"
3030

31+
3132
from . import authentication as authentication, eventsub as eventsub, utils as utils, web as web
3233
from .assets import Asset as Asset
3334
from .authentication import Scopes as Scopes

twitchio/__main__.py

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

2525
import argparse
2626
import platform
27+
import re
2728
import sys
2829

2930
import aiohttp
3031

31-
from ._version import _get_version
32-
3332

3433
try:
3534
import starlette
@@ -52,11 +51,40 @@
5251
args = parser.parse_args()
5352

5453

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+
5583
def version_info() -> None:
5684
python_info = "\n".join(sys.version.split("\n"))
5785

5886
info: str = f"""
59-
twitchio : {_get_version()}
87+
twitchio : {get_version()}
6088
aiohttp : {aiohttp.__version__}
6189
6290
Python:

twitchio/_version.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)