mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-09 09:22:03 +00:00
Change version util and version number.
This commit is contained in:
parent
7fd9a6cfe8
commit
3eba1c25c7
2 changed files with 39 additions and 4 deletions
|
|
@ -2,6 +2,6 @@ from .utils.versions import Version, Stage
|
|||
from .bot import Bot
|
||||
|
||||
|
||||
VERSION = Version(0, 3, 2, stage=Stage.FINAL, build=3)
|
||||
VERSION = Version(0, 3, 3, stage=Stage.DEV, build=0)
|
||||
|
||||
__version__ = VERSION.version
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
import datetime
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from .helper import Helper, HelperMode, Item
|
||||
|
||||
# Based on https://github.com/django/django/blob/master/django/utils/version.py
|
||||
|
||||
|
||||
class Version:
|
||||
def __init__(self, major=0, minor=0, maintenance=0, stage='final', build=0):
|
||||
|
|
@ -40,6 +46,10 @@ class Version:
|
|||
def build(self):
|
||||
return self.__raw_version[4]
|
||||
|
||||
@property
|
||||
def raw_version(self):
|
||||
return self.raw_version
|
||||
|
||||
def get_version(self):
|
||||
"""
|
||||
Returns a PEP 440-compliant version number from VERSION.
|
||||
|
|
@ -56,9 +66,13 @@ class Version:
|
|||
main = self.get_main_version()
|
||||
|
||||
sub = ''
|
||||
|
||||
if version[3] != 'final':
|
||||
mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'rc'}
|
||||
print(version[3], Stage.DEV, version[3] == Stage.DEV)
|
||||
if version[3] == Stage.DEV and version[4] == 0:
|
||||
git_changeset = self.get_git_changeset()
|
||||
if git_changeset:
|
||||
sub = '.dev{0}'.format(git_changeset)
|
||||
elif version[3] != Stage.FINAL:
|
||||
mapping = {Stage.ALPHA: 'a', Stage.BETA: 'b', Stage.RC: 'rc', Stage.DEV: 'dev'}
|
||||
sub = mapping[version[3]] + str(version[4])
|
||||
|
||||
return str(main + sub)
|
||||
|
|
@ -73,6 +87,26 @@ class Version:
|
|||
parts = 2 if version[2] == 0 else 3
|
||||
return '.'.join(str(x) for x in version[:parts])
|
||||
|
||||
def get_git_changeset(self):
|
||||
"""Return a numeric identifier of the latest git changeset.
|
||||
The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
|
||||
This value isn't guaranteed to be unique, but collisions are very unlikely,
|
||||
so it's sufficient for generating the development version numbers.
|
||||
"""
|
||||
repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
print(repo_dir)
|
||||
git_log = subprocess.Popen(
|
||||
'git log --pretty=format:%ct --quiet -1 HEAD',
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||
shell=True, cwd=repo_dir, universal_newlines=True,
|
||||
)
|
||||
timestamp = git_log.communicate()[0]
|
||||
try:
|
||||
timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
|
||||
except ValueError:
|
||||
return None
|
||||
return timestamp.strftime('%Y%m%d%H%M%S')
|
||||
|
||||
def __str__(self):
|
||||
return self.version
|
||||
|
||||
|
|
@ -87,3 +121,4 @@ class Stage(Helper):
|
|||
ALPHA = Item()
|
||||
BETA = Item()
|
||||
RC = Item()
|
||||
DEV = Item()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue