Repository: inventree/InvenTree

Issue:
[FR] Add Installer type, branch and publisher to version info
Might be a checkpoint for system checks - depending on no installer type being detected.


Discussion:
@matmair any further thoughts on this one? 

Resolving patch:
diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py
--- a/InvenTree/InvenTree/settings.py
+++ b/InvenTree/InvenTree/settings.py
@@ -22,6 +22,7 @@
 from django.utils.translation import gettext_lazy as _
 
 import moneyed
+from dotenv import load_dotenv
 
 from InvenTree.config import get_boolean_setting, get_custom_file, get_setting
 from InvenTree.sentry import default_sentry_dsn, init_sentry
@@ -65,6 +66,12 @@
 # Load configuration data
 CONFIG = config.load_config_data(set_cache=True)
 
+# Load VERSION data if it exists
+version_file = BASE_DIR.parent.joinpath('VERSION')
+if version_file.exists():
+    print('load version from file')
+    load_dotenv(version_file)
+
 # Default action is to run the system in Debug mode
 # SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = get_boolean_setting('INVENTREE_DEBUG', 'debug', True)
diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py
--- a/InvenTree/InvenTree/version.py
+++ b/InvenTree/InvenTree/version.py
@@ -5,11 +5,13 @@
 
 import os
 import pathlib
+import platform
 import re
 from datetime import datetime as dt
 from datetime import timedelta as td
 
 import django
+from django.conf import settings
 
 from dulwich.repo import NotGitRepository, Repo
 
@@ -130,3 +132,48 @@ def inventreeCommitDate():
 
     commit_dt = dt.fromtimestamp(main_commit.commit_time) + td(seconds=main_commit.commit_timezone)
     return str(commit_dt.date())
+
+
+def inventreeInstaller():
+    """Returns the installer for the running codebase - if set."""
+    # First look in the environment variables, e.g. if running in docker
+
+    installer = os.environ.get('INVENTREE_PKG_INSTALLER', '')
+
+    if installer:
+        return installer
+    elif settings.DOCKER:
+        return 'DOC'
+    elif main_commit is not None:
+        return 'GIT'
+
+    return None
+
+
+def inventreeBranch():
+    """Returns the branch for the running codebase - if set."""
+    # First look in the environment variables, e.g. if running in docker
+
+    branch = os.environ.get('INVENTREE_PKG_BRANCH', '')
+
+    if branch:
+        return branch
+
+    if main_commit is None:
+        return None
+
+    branch = main_repo.refs.follow(b'HEAD')[0][1].decode()
+    return branch.removeprefix('refs/heads/')
+
+
+def inventreeTarget():
+    """Returns the target platform for the running codebase - if set."""
+    # First look in the environment variables, e.g. if running in docker
+
+    return os.environ.get('INVENTREE_PKG_TARGET', None)
+
+
+def inventreePlatform():
+    """Returns the platform for the instance."""
+
+    return platform.platform(aliased=True)
diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py
--- a/InvenTree/part/templatetags/inventree_extras.py
+++ b/InvenTree/part/templatetags/inventree_extras.py
@@ -287,6 +287,30 @@ def inventree_commit_date(*args, **kwargs):
     return version.inventreeCommitDate()
 
 
+@register.simple_tag()
+def inventree_installer(*args, **kwargs):
+    """Return InvenTree package installer string."""
+    return version.inventreeInstaller()
+
+
+@register.simple_tag()
+def inventree_branch(*args, **kwargs):
+    """Return InvenTree git branch string."""
+    return version.inventreeBranch()
+
+
+@register.simple_tag()
+def inventree_target(*args, **kwargs):
+    """Return InvenTree target string."""
+    return version.inventreeTarget()
+
+
+@register.simple_tag()
+def inventree_platform(*args, **kwargs):
+    """Return InvenTree platform string."""
+    return version.inventreePlatform()
+
+
 @register.simple_tag()
 def inventree_github_url(*args, **kwargs):
     """Return URL for InvenTree github site."""


Test patch: