Include j2 files in MANIFEST.in. 75/9375/1
authormagnussonl <lars-goran.magnusson@arctoslabs.com>
Thu, 9 Jul 2020 14:30:41 +0000 (16:30 +0200)
committermagnussonl <lars-goran.magnusson@arctoslabs.com>
Thu, 9 Jul 2020 14:30:50 +0000 (16:30 +0200)
Updated mechanism to load jinja templates.

1134

Change-Id: Idfbdb4de0f90e63b49c4b27d8d5190eb1fa069c3
Signed-off-by: magnussonl <lars-goran.magnusson@arctoslabs.com>
MANIFEST.in
osm_pla/placement/mznplacement.py

index 22675f6..60da55a 100755 (executable)
@@ -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 *
index 56a448d..3dcf0bc 100755 (executable)
@@ -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)