From 27696611043b0a5e5a7087c951f6ea84159c4293 Mon Sep 17 00:00:00 2001 From: Ananya2003Gupta Date: Sat, 29 Jul 2023 16:35:01 +0530 Subject: [PATCH] Modified code generation method to cater multiple namespaces --- python/podio_class_generator.py | 18 +++++++++--------- python/templates/ParentModule.jl.jinja2 | 19 +++++++++++-------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/python/podio_class_generator.py b/python/podio_class_generator.py index 3519194b7..4cc76f646 100755 --- a/python/podio_class_generator.py +++ b/python/podio_class_generator.py @@ -122,11 +122,15 @@ def _get_namespace_dict(self): namespace[parent_namespace]['Datatypes'].append(child) namespace[parent_namespace]['Collections'].append(child + 'Collection') + namespace_dict = {} + namespace_dict['class'] = DataType(self.package_name.capitalize()) + namespace_dict['children'] = [] for parent, child in namespace.items(): - namespace_dict = {} - namespace_dict['class'] = DataType(parent) - namespace_dict['children'] = child - self._fill_templates("ParentModule", namespace_dict) + if(parent!=""): + namespace_dict['children'].append({'parent' : parent, 'child' : child}) + else: + namespace_dict['children'].append({'parent' : self.package_name, 'child' : child}) + self._fill_templates("ParentModule", namespace_dict) def process(self): """Run the actual generation""" @@ -229,11 +233,7 @@ def _fill_templates(self, template_base, data): data['use_get_syntax'] = self.get_syntax data['incfolder'] = self.incfolder for filename, template in self._get_filenames_templates(template_base, data['class'].bare_type): - # package_name as file name for parent module template - if (template == "ParentModule.jl.jinja2"): - self._write_file(f'{self.package_name.capitalize()}.jl', self._eval_template(template, data)) - else: - self._write_file(filename, self._eval_template(template, data)) + self._write_file(filename, self._eval_template(template, data)) def _process_component(self, name, component): """Process one component""" diff --git a/python/templates/ParentModule.jl.jinja2 b/python/templates/ParentModule.jl.jinja2 index e0464b527..902524b9c 100644 --- a/python/templates/ParentModule.jl.jinja2 +++ b/python/templates/ParentModule.jl.jinja2 @@ -1,12 +1,15 @@ -{% for child in children['Components'] + children['Datatypes'] + children['Collections'] %} -include("{{ child }}.jl") +{% for value in children %} +{% for childvalue in value['child']['Components'] + value['child']['Datatypes'] + value['child']['Collections'] %} +include("{{ childvalue }}.jl") +{% endfor %} {% endfor %} -module {{ package_name|capitalize }} - -{% for child in children['Components'] + children['Datatypes'] %} -using ..{{child}}Module: {{child}} -export {{child}} +{% for value in children %} +module {{ value['parent']|capitalize }} +{% for childvalue in value['child']['Components'] + value['child']['Datatypes'] %} +using ..{{childvalue}}Module: {{childvalue}} +export {{childvalue}} {% endfor %} +end -end \ No newline at end of file +{% endfor %}