Skip to content

Commit

Permalink
Modified code generation method to cater multiple namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Ananya2003Gupta committed Jul 29, 2023
1 parent f638f09 commit 2769661
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
18 changes: 9 additions & 9 deletions python/podio_class_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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"""
Expand Down
19 changes: 11 additions & 8 deletions python/templates/ParentModule.jl.jinja2
Original file line number Diff line number Diff line change
@@ -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
{% endfor %}

0 comments on commit 2769661

Please sign in to comment.