diff --git a/src/backend/InvenTree/InvenTree/config.py b/src/backend/InvenTree/InvenTree/config.py index f51cf924d3..600e9e7864 100644 --- a/src/backend/InvenTree/InvenTree/config.py +++ b/src/backend/InvenTree/InvenTree/config.py @@ -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 diff --git a/src/backend/InvenTree/InvenTree/settings.py b/src/backend/InvenTree/InvenTree/settings.py index 965fbc05de..a8ce065b04 100644 --- a/src/backend/InvenTree/InvenTree/settings.py +++ b/src/backend/InvenTree/InvenTree/settings.py @@ -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! diff --git a/src/backend/InvenTree/InvenTree/version.py b/src/backend/InvenTree/InvenTree/version.py index ca699f0190..30aa8bd07d 100644 --- a/src/backend/InvenTree/InvenTree/version.py +++ b/src/backend/InvenTree/InvenTree/version.py @@ -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