Skip to content

Commit

Permalink
More version specifier fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
EvieePy committed Nov 18, 2024
1 parent dee0033 commit a25d91e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 37 deletions.
29 changes: 27 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
import re

from setuptools import setup # type: ignore

from twitchio._version import _get_version

def get_version() -> str:
version = ""
with open("twitchio/__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()
except Exception:
pass

return version


setup(version=_get_version(with_hash=False))
setup(version=get_version())
1 change: 1 addition & 0 deletions twitchio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
__copyright__ = "Copyright 2017-Present (c) TwitchIO, PythonistaGuild"
__version__ = "3.0.0dev"


from . import authentication as authentication, eventsub as eventsub, utils as utils, web as web
from .assets import Asset as Asset
from .authentication import Scopes as Scopes
Expand Down
34 changes: 31 additions & 3 deletions twitchio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@

import argparse
import platform
import re
import sys

import aiohttp

from ._version import _get_version


try:
import starlette
Expand All @@ -52,11 +51,40 @@
args = parser.parse_args()


def get_version() -> str:
version = ""
with open("twitchio/__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


def version_info() -> None:
python_info = "\n".join(sys.version.split("\n"))

info: str = f"""
twitchio : {_get_version()}
twitchio : {get_version()}
aiohttp : {aiohttp.__version__}
Python:
Expand Down
32 changes: 0 additions & 32 deletions twitchio/_version.py

This file was deleted.

0 comments on commit a25d91e

Please sign in to comment.