mirror of
https://github.com/inventree/InvenTree.git
synced 2025-10-14 21:22:20 +00:00
fix(installer): make VERSION information accessible in invoke calls (#10558)
* implement version loading in more contexts closes #10554 * factor version file out * ensure results do not contain new strings
This commit is contained in:
@@ -76,8 +76,9 @@ def get_root_dir() -> Path:
|
||||
|
||||
def inventreeInstaller() -> Optional[str]:
|
||||
"""Returns the installer for the running codebase - if set or detectable."""
|
||||
# First look in the environment variables, e.g. if running in docker
|
||||
load_version_file()
|
||||
|
||||
# First look in the environment variables, e.g. if running in docker
|
||||
installer = os.environ.get('INVENTREE_PKG_INSTALLER', '')
|
||||
|
||||
if installer:
|
||||
@@ -121,6 +122,11 @@ def get_testfolder_dir() -> Path:
|
||||
return get_base_dir().joinpath('_testfolder').resolve()
|
||||
|
||||
|
||||
def get_version_file() -> Path:
|
||||
"""Returns the path of the InvenTree VERSION file. This does not ensure that the file exists."""
|
||||
return get_root_dir().joinpath('VERSION').resolve()
|
||||
|
||||
|
||||
def ensure_dir(path: Path, storage=None) -> None:
|
||||
"""Ensure that a directory exists.
|
||||
|
||||
@@ -592,3 +598,28 @@ def check_config_dir(
|
||||
pass
|
||||
|
||||
return
|
||||
|
||||
|
||||
VERSION_LOADED = False
|
||||
"""Flag to indicate if the VERSION file has been loaded in this process."""
|
||||
|
||||
|
||||
def load_version_file():
|
||||
"""Load the VERSION file if it exists and place the contents into the general execution environment.
|
||||
|
||||
Returns:
|
||||
True if the VERSION file was loaded (now or previously), False otherwise.
|
||||
"""
|
||||
global VERSION_LOADED
|
||||
if VERSION_LOADED:
|
||||
return True
|
||||
|
||||
# Load the VERSION file if it exists
|
||||
from dotenv import load_dotenv
|
||||
|
||||
version_file = get_version_file()
|
||||
if version_file.exists():
|
||||
load_dotenv(version_file)
|
||||
VERSION_LOADED = True
|
||||
return True
|
||||
return False
|
||||
|
@@ -23,7 +23,6 @@ from django.http import Http404, HttpResponseGone
|
||||
|
||||
import structlog
|
||||
from corsheaders.defaults import default_headers as default_cors_headers
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from InvenTree.cache import get_cache_config, is_global_cache_enabled
|
||||
from InvenTree.config import (
|
||||
@@ -80,11 +79,7 @@ BASE_DIR = config.get_base_dir()
|
||||
|
||||
# Load configuration data
|
||||
CONFIG = config.load_config_data(set_cache=True)
|
||||
|
||||
# Load VERSION data if it exists
|
||||
version_file = config.get_root_dir().joinpath('VERSION')
|
||||
if version_file.exists():
|
||||
load_dotenv(version_file)
|
||||
config.load_version_file()
|
||||
|
||||
# Default action is to run the system in Debug mode
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
|
@@ -269,7 +269,7 @@ def inventreeBranch():
|
||||
branch = os.environ.get('INVENTREE_PKG_BRANCH', '')
|
||||
|
||||
if branch:
|
||||
return branch
|
||||
return ' '.join(branch.splitlines())
|
||||
|
||||
if main_branch is None:
|
||||
return None
|
||||
|
Reference in New Issue
Block a user