summaryrefslogtreecommitdiff
path: root/python/vyos/template.py
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-03-28 20:01:33 +0100
committerGitHub <noreply@github.com>2024-03-28 20:01:33 +0100
commit7c650ae9a41d90d863906fec388de427dfdb7195 (patch)
tree18e75d4930d2ec8c5395975567dcdd1f83e5ea4d /python/vyos/template.py
parent82001265750fec18bab13161734ff1a90d2f7fc3 (diff)
parent8344e7ba6a0a356e821b2b72d22a9ef2ef7b0fdd (diff)
downloadvyos-1x-7c650ae9a41d90d863906fec388de427dfdb7195.tar.gz
vyos-1x-7c650ae9a41d90d863906fec388de427dfdb7195.zip
Merge pull request #3208 from dmbaturin/T3664-template-env-var
vyos.template: T3664: add an environment variable for template location
Diffstat (limited to 'python/vyos/template.py')
-rw-r--r--python/vyos/template.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py
index bde8e3554..392322d46 100644
--- a/python/vyos/template.py
+++ b/python/vyos/template.py
@@ -1,4 +1,4 @@
-# Copyright 2019-2023 VyOS maintainers and contributors <maintainers@vyos.io>
+# Copyright 2019-2024 VyOS maintainers and contributors <maintainers@vyos.io>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -32,8 +32,21 @@ _TESTS = {}
# reuse Environments with identical settings to improve performance
@functools.lru_cache(maxsize=2)
def _get_environment(location=None):
+ from os import getenv
+
if location is None:
- loc_loader=FileSystemLoader(directories["templates"])
+ # Sometimes functions that rely on templates need to be executed outside of VyOS installations:
+ # for example, installer functions are executed for image builds,
+ # and anything may be invoked for testing from a developer's machine.
+ # This environment variable allows running any unmodified code
+ # with a custom template location.
+ location_env_var = getenv("VYOS_TEMPLATE_DIR")
+ if location_env_var:
+ print(f"Using environment variable {location_env_var}")
+ template_dir = location_env_var
+ else:
+ template_dir = directories["templates"]
+ loc_loader=FileSystemLoader(template_dir)
else:
loc_loader=FileSystemLoader(location)
env = Environment(