Merge branch 'check_python_version_at_startup' into 'master'

Check python version at startup

See merge request ngsolve/netgen!568
This commit is contained in:
Schöberl, Joachim 2023-04-28 11:34:42 +02:00
commit fe3abbdec4
2 changed files with 30 additions and 0 deletions

View File

@ -5,6 +5,32 @@ from . import config
_netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..',config.NETGEN_PYTHON_RPATH_BIN)) _netgen_bin_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..',config.NETGEN_PYTHON_RPATH_BIN))
_netgen_lib_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..',config.NETGEN_PYTHON_RPATH)) _netgen_lib_dir=os.path.realpath(os.path.join(os.path.dirname(__file__),'..',config.NETGEN_PYTHON_RPATH))
__diagnostics_template = """
Netgen diagnostics:
sys.platform: {sys.platform}
sys.executable: {sys.executable}
sys.version: {sys.version}
Netgen python version: {config.PYTHON_VERSION}
Netgen path {__file__}
Netgen config {config.__file__}
Netgen version {config.NETGEN_VERSION}
sys.path: {sys.path}
"""
def _get_diagnostics():
return __diagnostics_template.format(sys=sys, config=config, __file__=__file__)
# compare compile-time and run-time python version
def _check_python_version():
sys_version = f"{sys.version_info.major}.{sys.version_info.minor}"
compile_version = f"{config.PYTHON_VERSION_MAJOR}.{config.PYTHON_VERSION_MINOR}"
if sys_version != compile_version:
print(get_diagnostics(), file=sys.stderr)
raise RuntimeError(f"Python version mismatch: compile-time version is {compile_version}, run-time version is {sys_version}")
_check_python_version()
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
v = sys.version_info v = sys.version_info
if v.major == 3 and v.minor >= 8: if v.major == 3 and v.minor >= 8:

View File

@ -52,4 +52,8 @@ NETGEN_VERSION_TWEAK = "@NETGEN_VERSION_TWEAK@"
NETGEN_VERSION_PATCH = "@NETGEN_VERSION_PATCH@" NETGEN_VERSION_PATCH = "@NETGEN_VERSION_PATCH@"
NETGEN_VERSION_HASH = "@NETGEN_VERSION_HASH@" NETGEN_VERSION_HASH = "@NETGEN_VERSION_HASH@"
PYTHON_VERSION = "@PYTHON_VERSION@"
PYTHON_VERSION_MAJOR = "@PYTHON_VERSION_MAJOR@"
PYTHON_VERSION_MINOR = "@PYTHON_VERSION_MINOR@"
version = NETGEN_VERSION_GIT version = NETGEN_VERSION_GIT