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

This commit is contained in:
Athanasius committed 2021-04-01 14:45:52 +01:00
1 parent 8b3294ecdd
commit 3f3a4f282e
3 files changed
+27

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
.gitversion
.DS_Store
build
dist.*
+1
View File
@@ -9,6 +9,7 @@ found necessary to move out of other files.
# config.py
appname = 'EDMarketConnector'
applongname = 'E:D Market Connector'
GITVERSION_FILE = '.gitversion'
# protocol.py
protocolhandler_redirect = 'edmc://auth'
+25
View File
@@ -12,6 +12,7 @@ import os
import platform
import re
import shutil
import subprocess
import sys
from distutils.core import setup
from os.path import exists, isdir, join
@@ -21,10 +22,34 @@ from typing import Any, Generator, Set
import semantic_version
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):
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':
assert platform.architecture()[0] == '32bit', 'Assumes a Python built for 32bit'
import py2exe # noqa: F401 # Yes, this *is* used