1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-12 15:27:14 +03:00

app version: Write a .gitversion file with short hash from setup.py

This commit is contained in:
Athanasius 2021-03-25 14:40:03 +00:00
parent 8b3294ecdd
commit 3f3a4f282e
3 changed files with 27 additions and 0 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.gitversion
.DS_Store .DS_Store
build build
dist.* dist.*

View File

@ -9,6 +9,7 @@ found necessary to move out of other files.
# config.py # config.py
appname = 'EDMarketConnector' appname = 'EDMarketConnector'
applongname = 'E:D Market Connector' applongname = 'E:D Market Connector'
GITVERSION_FILE = '.gitversion'
# protocol.py # protocol.py
protocolhandler_redirect = 'edmc://auth' protocolhandler_redirect = 'edmc://auth'

View File

@ -12,6 +12,7 @@ import os
import platform import platform
import re import re
import shutil import shutil
import subprocess
import sys import sys
from distutils.core import setup from distutils.core import setup
from os.path import exists, isdir, join from os.path import exists, isdir, join
@ -21,10 +22,34 @@ from typing import Any, Generator, Set
import semantic_version import semantic_version
from config import appcmdname, applongname, appname, appversion, copyright, update_feed, update_interval from config import appcmdname, applongname, appname, appversion, copyright, update_feed, update_interval
from constants import GITVERSION_FILE
if sys.version_info[0:2] != (3, 9): if sys.version_info[0:2] != (3, 9):
raise AssertionError(f'Unexpected python version {sys.version}') raise AssertionError(f'Unexpected python version {sys.version}')
# Retrieve current git short hash and store in file GITVERSION_FILE
try:
git_cmd = subprocess.Popen('git rev-parse --short HEAD'.split(),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
out, err = git_cmd.communicate()
except Exception as e:
print(f"Couldn't run git command for short hash: {e!r}")
exit(-1)
else:
git_shorthash: str = out.decode().rstrip('\n')
if re.match(r'^[0-9a-f]{7,}$', git_shorthash) is None:
print(f"'{git_shorthash}' doesn't look like a valid git short hash!")
exit(-2)
with open(GITVERSION_FILE, 'w+', encoding='utf-8') as gvf:
gvf.write(git_shorthash)
print(f'Git short hash: {git_shorthash}')
if sys.platform == 'win32': if sys.platform == 'win32':
assert platform.architecture()[0] == '32bit', 'Assumes a Python built for 32bit' assert platform.architecture()[0] == '32bit', 'Assumes a Python built for 32bit'
import py2exe # noqa: F401 # Yes, this *is* used import py2exe # noqa: F401 # Yes, this *is* used