From 23be619282ca9f93f3bde22b0cdbb96b7e233208 Mon Sep 17 00:00:00 2001 From: magnussonl Date: Thu, 9 Jul 2020 16:30:41 +0200 Subject: [PATCH] Include j2 files in MANIFEST.in. Updated mechanism to load jinja templates. 1134 Change-Id: Idfbdb4de0f90e63b49c4b27d8d5190eb1fa069c3 Signed-off-by: magnussonl (cherry picked from commit de4f7820a050a7ed18aa93a298c5a59e379e752b) --- MANIFEST.in | 2 +- osm_pla/placement/mznplacement.py | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 22675f6..60da55a 100755 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -16,5 +16,5 @@ # under the License. include requirements.txt include README.md -recursive-include osm_pla *.py *.sh *.yaml +recursive-include osm_pla *.py *.sh *.yaml *.j2 recursive-include devops-stages * diff --git a/osm_pla/placement/mznplacement.py b/osm_pla/placement/mznplacement.py index 56a448d..3dcf0bc 100755 --- a/osm_pla/placement/mznplacement.py +++ b/osm_pla/placement/mznplacement.py @@ -18,7 +18,7 @@ import itertools import pymzn from jinja2 import Environment -from jinja2.loaders import FileSystemLoader +from jinja2.loaders import FileSystemLoader, PackageLoader, ChoiceLoader class MznPlacementConductor(object): @@ -88,7 +88,8 @@ class MznModelGenerator(object): NsPlacementData objects. Uses jinja2 as templating language for the model ''' default_j2_template = "osm_pla_dynamic_template.j2" - template_search_path = ['osm_pla/placement', '../placement', '/pla/osm_pla/placement'] + template_search_path = ['osm_pla/placement', '../placement', '/pla/osm_pla/placement', + './', '/usr/lib/python3/dist-packages/osm_pla/placement'] def __init__(self, log): ''' @@ -111,7 +112,9 @@ class MznModelGenerator(object): def _load_jinja_template(self, template_name=default_j2_template): """loads the jinja template used for model generation""" - env = Environment(loader=FileSystemLoader(MznModelGenerator.template_search_path)) + loader1 = FileSystemLoader(MznModelGenerator.template_search_path) + loader2 = PackageLoader('osm_pla', '.') + env = Environment(loader=ChoiceLoader([loader1, loader2])) return env.get_template(template_name) -- 2.25.1