From 6cdc07ee4f7d6f869b78d624299b60156c885217 Mon Sep 17 00:00:00 2001 From: Ananya2003Gupta Date: Mon, 27 Nov 2023 14:59:03 +0530 Subject: [PATCH] Suggested Changes --- .gitignore | 2 ++ cmake/podioMacros.cmake | 4 ++-- python/podio_class_generator.py | 10 ++++---- python/templates/MutableStruct.jl.jinja2 | 4 ++-- python/templates/ParentModule.jl.jinja2 | 24 ++++++++++++------- python/templates/macros/abstracttypes.jinja2 | 17 ------------- .../{params.jinja2 => julia_helpers.jinja2} | 19 +++++++++++++++ tests/CMakeLists.txt | 3 ++- tests/{ => unittests}/unittest.jl | 3 +-- 9 files changed, 47 insertions(+), 39 deletions(-) delete mode 100644 python/templates/macros/abstracttypes.jinja2 rename python/templates/macros/{params.jinja2 => julia_helpers.jinja2} (50%) rename tests/{ => unittests}/unittest.jl (97%) diff --git a/.gitignore b/.gitignore index e2d019fed..5c074cd6e 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ tests/src tests/datamodel tests/extension_model tests/datamodeljulia +tests/unittests/Project.toml +tests/unittests/Manifest.toml # Python *pyc diff --git a/cmake/podioMacros.cmake b/cmake/podioMacros.cmake index e419244b3..9ac7bd3af 100644 --- a/cmake/podioMacros.cmake +++ b/cmake/podioMacros.cmake @@ -157,9 +157,9 @@ function(PODIO_GENERATE_DATAMODEL datamodel YAML_FILE RETURN_HEADERS RETURN_SOUR # Check if the LANG argument is specified and set the language accordingly. IF(ARG_LANG) - SET(LANGUAGE_ARG "-l=${ARG_LANG}") + SET(LANGUAGE_ARG "--lang=${ARG_LANG}") ELSE() - SET(LANGUAGE_ARG "-l=cpp") # Default to C++ + SET(LANGUAGE_ARG "--lang=cpp") # Default to C++ ENDIF() SET(SCHEMA_EVOLUTION_ARG "") diff --git a/python/podio_class_generator.py b/python/podio_class_generator.py index 3b8b3079e..eb688c6a6 100755 --- a/python/podio_class_generator.py +++ b/python/podio_class_generator.py @@ -315,9 +315,6 @@ def _process_component(self, name, component): if self.upstream_edm: component['upstream_edm_name'] = self.upstream_edm.options["includeSubfolder"].split("/")[-2].capitalize() - if self.proglang == "julia": - self._fill_templates('MutableStruct', component) - if self.proglang == "cpp": self._fill_templates('Component', component) # Add potentially older schema for schema evolution @@ -336,6 +333,8 @@ def _process_component(self, name, component): self._fill_templates('Component', component) self.root_schema_component_names.add(name + self.old_schema_version) + if self.proglang == "julia": + self._fill_templates('MutableStruct', component) return component @staticmethod @@ -354,9 +353,6 @@ def _process_datatype(self, name, definition): """Process one datatype""" datatype = self._preprocess_datatype(name, definition) - if self.proglang == "julia": - self._fill_templates('MutableStruct', datatype) - if self.proglang == "cpp": # ROOT schema evolution preparation # Compute and prepare the potential schema evolution parts @@ -399,6 +395,8 @@ def _process_datatype(self, name, definition): if 'SIO' in self.io_handlers: self._fill_templates('SIOBlock', datatype) + if self.proglang == "julia": + self._fill_templates('MutableStruct', datatype) return datatype def prepare_iorules(self): diff --git a/python/templates/MutableStruct.jl.jinja2 b/python/templates/MutableStruct.jl.jinja2 index 55262bff7..302ac35af 100644 --- a/python/templates/MutableStruct.jl.jinja2 +++ b/python/templates/MutableStruct.jl.jinja2 @@ -1,5 +1,5 @@ -{% import "macros/params.jinja2" as params %} -mutable struct {{ class.bare_type }}Struct{{ params.julia_parameters(params_jl,"T" ) }} +{% import "macros/julia_helpers.jinja2" as julia_helpers %} +mutable struct {{ class.bare_type }}Struct{{ julia_helpers.julia_parameters(params_jl,"T" ) }} {% for member in Members %} {% if member.is_array %} {% if not member.is_builtin_array and upstream_edm and (member.array_type in upstream_edm.components or member.array_type in upstream_edm.datatypes) %} diff --git a/python/templates/ParentModule.jl.jinja2 b/python/templates/ParentModule.jl.jinja2 index 78026f0ec..827f46cf5 100644 --- a/python/templates/ParentModule.jl.jinja2 +++ b/python/templates/ParentModule.jl.jinja2 @@ -1,5 +1,4 @@ -{% import "macros/params.jinja2" as params %} -{% import "macros/abstracttypes.jinja2" as abstdatatype %} +{% import "macros/julia_helpers.jinja2" as julia_helpers %} {% if upstream_edm %} include("{{ upstream_edm.options["includeSubfolder"] }}{{ upstream_edm_name }}.jl") {% endif %} @@ -18,7 +17,14 @@ import ..{{ upstream_edm_name }} {% endif %} {% if static_arrays_import %} -using StaticArrays +try + using StaticArrays +catch + import Pkg + Pkg.activate(@__DIR__) + Pkg.add("StaticArrays") + using StaticArrays +end {% endif %} {% for sort_include in includes %} include("{{ sort_include }}Struct.jl") @@ -38,7 +44,7 @@ function {{ component['class'].bare_type }}( {% endif %} {% endif %} {% elif member.is_builtin %} - {{ member.name }}::{{ abstdatatype.classify_data_type(member.julia_type) }} = {{ member.julia_type }}(0), + {{ member.name }}::{{ julia_helpers.classify_data_type(member.julia_type) }} = {{ member.julia_type }}(0), {% else %} {% if upstream_edm and (member.full_type in upstream_edm.components or member.full_type in upstream_edm.datatypes) %} {{ member.name }}::{{ upstream_edm_name }}.{{ member.julia_type }}Struct = {{ upstream_edm_name }}.{{ member.julia_type }}(), @@ -48,7 +54,7 @@ function {{ component['class'].bare_type }}( {% endif %} {% endfor %} ) - return {{ component['class'].bare_type }}Struct{{ params.julia_parameters(component['params_jl'], "Struct", upstream_edm, upstream_edm_name) }}( + return {{ component['class'].bare_type }}Struct{{ julia_helpers.julia_parameters(component['params_jl'], "Struct", upstream_edm, upstream_edm_name) }}( {% for member in component['Members'] %} {% if member.is_builtin %} {{ member.julia_type }}({{ member.name }}), @@ -75,7 +81,7 @@ function {{ datatype['class'].bare_type }}( {% endif %} {% endif %} {% elif member.is_builtin %} - {{ member.name }}::{{ abstdatatype.classify_data_type(member.julia_type) }} = {{ member.julia_type }}(0), + {{ member.name }}::{{ julia_helpers.classify_data_type(member.julia_type) }} = {{ member.julia_type }}(0), {% else %} {% if upstream_edm and (member.full_type in upstream_edm.components or member.full_type in upstream_edm.datatypes) %} {{ member.name }}::{{ upstream_edm_name }}.{{ member.julia_type }}Struct = {{ upstream_edm_name }}.{{ member.julia_type }}(), @@ -115,13 +121,13 @@ function {{ datatype['class'].bare_type }}( where {{ structure_start -}} {% for member in datatype['VectorMembers'] %} {% if member.is_builtin %} -{{ member.name }}T<:{{ abstdatatype.classify_data_type(member.julia_type) }}{% if not loop.last %},{% endif %} +{{ member.name }}T<:{{ julia_helpers.classify_data_type(member.julia_type) }}{% if not loop.last %},{% endif %} {% endif %} {% endfor -%} {{ structure_end }} {% endif %} - return {{ datatype['class'].bare_type }}Struct{{ params.julia_parameters(datatype['params_jl'], "Struct", upstream_edm, upstream_edm_name) }}( + return {{ datatype['class'].bare_type }}Struct{{ julia_helpers.julia_parameters(datatype['params_jl'], "Struct", upstream_edm, upstream_edm_name) }}( {% for member in datatype['Members'] %} {% if member.is_builtin %} {{ member.julia_type }}({{ member.name }}), @@ -145,7 +151,7 @@ function {{ datatype['class'].bare_type }}( ) end -{{ datatype['class'].bare_type }}Collection = Vector{ {{ datatype['class'].bare_type }}Struct{{ params.julia_parameters(datatype['params_jl'], "Struct", upstream_edm, upstream_edm_name) }} } +{{ datatype['class'].bare_type }}Collection = Vector{ {{ datatype['class'].bare_type }}Struct{{ julia_helpers.julia_parameters(datatype['params_jl'], "Struct", upstream_edm, upstream_edm_name) }} } {% endfor %} end diff --git a/python/templates/macros/abstracttypes.jinja2 b/python/templates/macros/abstracttypes.jinja2 deleted file mode 100644 index 4e6bdda9f..000000000 --- a/python/templates/macros/abstracttypes.jinja2 +++ /dev/null @@ -1,17 +0,0 @@ -{% macro classify_data_type(data_type) %} - {%- set type_map = { - 'Int8': 'Integer', - 'UInt8': 'Integer', - 'Int16': 'Integer', - 'UInt16': 'Integer', - 'Int32': 'Integer', - 'UInt32': 'Integer', - 'Int64': 'Integer', - 'UInt64': 'Integer', - 'Float16': 'Real', - 'Float32': 'Real', - 'Float64': 'Real' - } -%} - - {{ type_map.get(data_type, data_type) }} -{%- endmacro -%} diff --git a/python/templates/macros/params.jinja2 b/python/templates/macros/julia_helpers.jinja2 similarity index 50% rename from python/templates/macros/params.jinja2 rename to python/templates/macros/julia_helpers.jinja2 index e8a56da8d..c90e8138f 100644 --- a/python/templates/macros/params.jinja2 +++ b/python/templates/macros/julia_helpers.jinja2 @@ -1,3 +1,22 @@ +{% macro classify_data_type(data_type) %} + {%- set type_map = { + 'Int8': 'Integer', + 'UInt8': 'Integer', + 'Int16': 'Integer', + 'UInt16': 'Integer', + 'Int32': 'Integer', + 'UInt32': 'Integer', + 'Int64': 'Integer', + 'UInt64': 'Integer', + 'Float16': 'Real', + 'Float32': 'Real', + 'Float64': 'Real' + } -%} + + {{ type_map.get(data_type, data_type) }} +{%- endmacro -%} + + {% macro julia_parameters(params, suffix, upstream_edm=None, upstream_edm_name=None) %} {%- if params -%}{ {%- set comma = joiner(',') -%} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cbfb0b479..c49ad74c2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -78,7 +78,8 @@ PODIO_GENERATE_DATAMODEL(extensionmodeljulia datalayout_extension.yaml ext_heade find_program(Julia_EXECUTABLE julia) if (Julia_EXECUTABLE) message(STATUS "Found Julia, will add the Julia tests") - add_test(NAME julia-unittests COMMAND julia unittest.jl) + set(UNITTEST_SCRIPT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/unittests/unittest.jl) + add_test(NAME julia-unittests COMMAND julia ${UNITTEST_SCRIPT_PATH}) set_tests_properties(julia-unittests PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} ) diff --git a/tests/unittest.jl b/tests/unittests/unittest.jl similarity index 97% rename from tests/unittest.jl rename to tests/unittests/unittest.jl index 08a6a42e1..990610cc5 100644 --- a/tests/unittest.jl +++ b/tests/unittests/unittest.jl @@ -7,9 +7,8 @@ catch Pkg.add("StaticArrays") using StaticArrays end - # datamodeljulia/Datamodeljulia.jl file included inside extension_model/extensionmodeljulia/Extensionmodeljulia.jl file -include("extension_model/extensionmodeljulia/Extensionmodeljulia.jl") +include("../extension_model/extensionmodeljulia/Extensionmodeljulia.jl") using .Datamodeljulia using .Extensionmodeljulia using Test