mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-20 08:44:07 +03:00
Re-factor git short hash into a config.py function.
This should clear the way for using it in running code when not frozen.
This commit is contained in:
parent
3f3a4f282e
commit
cc571e44b1
30
config.py
30
config.py
@ -13,6 +13,8 @@ import functools
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
import warnings
|
import warnings
|
||||||
@ -89,6 +91,34 @@ elif platform == 'linux':
|
|||||||
_T = TypeVar('_T')
|
_T = TypeVar('_T')
|
||||||
|
|
||||||
|
|
||||||
|
###########################################################################
|
||||||
|
def git_shorthash_from_head() -> str:
|
||||||
|
"""
|
||||||
|
Determine short hash for current git HEAD.
|
||||||
|
|
||||||
|
:return: str - None if we couldn't determine the short hash.
|
||||||
|
"""
|
||||||
|
shorthash: str = None # type: ignore
|
||||||
|
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:
|
||||||
|
logger.error(f"Couldn't run git command for short hash: {e!r}")
|
||||||
|
|
||||||
|
else:
|
||||||
|
shorthash = out.decode().rstrip('\n')
|
||||||
|
if re.match(r'^[0-9a-f]{7,}$', shorthash) is None:
|
||||||
|
logger.error(f"'{shorthash}' doesn't look like a valid git short hash, forcing to None")
|
||||||
|
shorthash = None # type: ignore
|
||||||
|
|
||||||
|
return shorthash
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
|
||||||
class AbstractConfig(abc.ABC):
|
class AbstractConfig(abc.ABC):
|
||||||
"""Abstract root class of all platform specific Config implementations."""
|
"""Abstract root class of all platform specific Config implementations."""
|
||||||
|
|
||||||
|
28
setup.py
28
setup.py
@ -12,7 +12,6 @@ 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,34 +20,25 @@ 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, git_shorthash_from_head, update_feed, update_interval
|
||||||
|
)
|
||||||
from constants import GITVERSION_FILE
|
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
|
# Retrieve current git short hash and store in file GITVERSION_FILE
|
||||||
try:
|
git_shorthash = git_shorthash_from_head()
|
||||||
git_cmd = subprocess.Popen('git rev-parse --short HEAD'.split(),
|
if git_shorthash is None:
|
||||||
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)
|
exit(-1)
|
||||||
|
|
||||||
else:
|
with open(GITVERSION_FILE, 'w+', encoding='utf-8') as gvf:
|
||||||
git_shorthash: str = out.decode().rstrip('\n')
|
gvf.write(git_shorthash)
|
||||||
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}')
|
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'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user