add a file to generate version
This commit is contained in:
8
setup.py
8
setup.py
@@ -1,6 +1,6 @@
|
||||
# flake8: noqa
|
||||
import sys
|
||||
from game_backuper import __version__
|
||||
from version import version, dversion
|
||||
from setuptools import Extension
|
||||
try:
|
||||
from Cython.Build import cythonize
|
||||
@@ -17,9 +17,9 @@ if "py2exe" in sys.argv:
|
||||
"console": [{
|
||||
'script': "game_backuper/__main__.py",
|
||||
"dest_base": 'game-backuper',
|
||||
'version': __version__,
|
||||
'version': version,
|
||||
'product_name': 'game-backuper',
|
||||
'product_version': __version__,
|
||||
'product_version': dversion,
|
||||
'company_name': 'lifegpc',
|
||||
'description': 'A game backuper',
|
||||
}],
|
||||
@@ -46,7 +46,7 @@ else:
|
||||
}
|
||||
setup(
|
||||
name="game-backuper",
|
||||
version=__version__,
|
||||
version=version,
|
||||
url="https://github.com/lifegpc/game-backuper",
|
||||
author="lifegpc",
|
||||
author_email="[email protected]",
|
||||
|
||||
60
version.py
Normal file
60
version.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import sys
|
||||
from os.path import exists, dirname, abspath, join
|
||||
from subprocess import Popen, DEVNULL, PIPE
|
||||
|
||||
|
||||
def check_git():
|
||||
p = Popen(['git', '--help'], stdout=DEVNULL, stderr=DEVNULL)
|
||||
p.wait()
|
||||
return True if p.poll() == 0 else False
|
||||
|
||||
|
||||
def get_git_desc():
|
||||
p = Popen(['git', 'describe', '--tags', '--long', '--dirty'], stdout=PIPE,
|
||||
stderr=DEVNULL)
|
||||
p.wait()
|
||||
if p.poll() == 0:
|
||||
return p.stdout.read()
|
||||
|
||||
|
||||
def normalize(s: str):
|
||||
li = s.split("-")
|
||||
nv = li[0].split('.')
|
||||
nv = [int(i) for i in nv if i.isnumeric()]
|
||||
if len(li) == 1:
|
||||
nv = [str(i) for i in nv]
|
||||
return '.'.join(nv)
|
||||
if li[1].isnumeric():
|
||||
if len(nv) >= 4:
|
||||
nv[-1] += int(li[1])
|
||||
else:
|
||||
while len(nv) <= 2:
|
||||
nv += [0]
|
||||
nv += [int(li[1])]
|
||||
nv = [str(i) for i in nv]
|
||||
return '.'.join(nv)
|
||||
|
||||
|
||||
default_version = "1.0.0"
|
||||
use_git = True
|
||||
if '--no-git-version' in sys.argv:
|
||||
use_git = False
|
||||
sys.argv.remove("--no-git-version")
|
||||
d = abspath(join(dirname(abspath(__file__)), ".git"))
|
||||
if not exists(d):
|
||||
use_git = False
|
||||
if use_git and not check_git():
|
||||
use_git = False
|
||||
if use_git:
|
||||
d = get_git_desc()
|
||||
if d is None:
|
||||
use_git = False
|
||||
version = default_version
|
||||
dversion = version
|
||||
else:
|
||||
d = d.decode().splitlines(False)[0]
|
||||
dversion = d[1:]
|
||||
version = normalize(dversion)
|
||||
else:
|
||||
version = default_version
|
||||
dversion = version
|
||||
Reference in New Issue
Block a user