diff --git a/python/podio/test_MemberParser.py b/python/podio/test_MemberParser.py index 08b4e47ab..9d6e9c55a 100644 --- a/python/podio/test_MemberParser.py +++ b/python/podio/test_MemberParser.py @@ -22,21 +22,25 @@ def test_parse_valid(self): # pylint: disable=too-many-statements self.assertEqual(parsed.name, r'someFloat') self.assertEqual(parsed.description, r'with an additional comment') self.assertTrue(parsed.default_val is None) + self.assertEqual(parsed.julia_type, r'Float32') parsed = parser.parse(r'float float2 // with numbers') self.assertEqual(parsed.full_type, r'float') self.assertEqual(parsed.name, r'float2') self.assertEqual(parsed.description, r'with numbers') + self.assertEqual(parsed.julia_type, r'Float32') parsed = parser.parse(r' float spacefloat // whitespace everywhere ') self.assertEqual(parsed.full_type, r'float') self.assertEqual(parsed.name, r'spacefloat') self.assertEqual(parsed.description, 'whitespace everywhere') + self.assertEqual(parsed.julia_type, r'Float32') parsed = parser.parse(r'int snake_case // snake case') self.assertEqual(parsed.full_type, r'int') self.assertEqual(parsed.name, r'snake_case') self.assertEqual(parsed.description, r'snake case') + self.assertEqual(parsed.julia_type, r'Int32') parsed = parser.parse(r'std::string mixed_UglyCase_12 // who wants this') self.assertEqual(parsed.full_type, r'std::string') @@ -48,11 +52,13 @@ def test_parse_valid(self): # pylint: disable=too-many-statements self.assertEqual(parsed.full_type, r'unsigned long long') self.assertEqual(parsed.name, r'uVar') self.assertEqual(parsed.description, r'an unsigned long variable') + self.assertEqual(parsed.julia_type, r'UInt64') parsed = parser.parse(r'unsigned int uInt // an unsigned integer') self.assertEqual(parsed.full_type, r'unsigned int') self.assertEqual(parsed.name, r'uInt') self.assertEqual(parsed.description, r'an unsigned integer') + self.assertEqual(parsed.julia_type, r'UInt32') # Fixed width integers in their various forms that they can be spelled out # and be considered valid in our case @@ -61,24 +67,28 @@ def test_parse_valid(self): # pylint: disable=too-many-statements self.assertEqual(parsed.name, r'qualified') self.assertEqual(parsed.description, r'qualified fixed width ints work') self.assertTrue(parsed.is_builtin) + self.assertEqual(parsed.julia_type, r'Int16') parsed = parser.parse(r'std::uint64_t bits // fixed width integer types should work') self.assertEqual(parsed.full_type, r'std::uint64_t') self.assertEqual(parsed.name, r'bits') self.assertEqual(parsed.description, r'fixed width integer types should work') self.assertTrue(parsed.is_builtin) + self.assertEqual(parsed.julia_type, r'UInt64') parsed = parser.parse(r'int32_t fixedInt // fixed width signed integer should work') self.assertEqual(parsed.full_type, r'std::int32_t') self.assertEqual(parsed.name, r'fixedInt') self.assertEqual(parsed.description, r'fixed width signed integer should work') self.assertTrue(parsed.is_builtin) + self.assertEqual(parsed.julia_type, r'Int32') parsed = parser.parse(r'uint16_t fixedUInt // fixed width unsigned int with 16 bits') self.assertEqual(parsed.full_type, r'std::uint16_t') self.assertEqual(parsed.name, r'fixedUInt') self.assertEqual(parsed.description, r'fixed width unsigned int with 16 bits') self.assertTrue(parsed.is_builtin) + self.assertEqual(parsed.julia_type, r'UInt16') # an array definition with space everywhere it is allowed parsed = parser.parse(r' std::array < double , 4 > someArray // a comment ') @@ -90,12 +100,14 @@ def test_parse_valid(self): # pylint: disable=too-many-statements self.assertEqual(int(parsed.array_size), 4) self.assertEqual(parsed.array_type, r'double') self.assertTrue(parsed.default_val is None) + self.assertEqual(parsed.julia_type, r'MVector{4, Float64}') # an array definition as terse as possible parsed = parser.parse(r'std::arrayanArray//with a comment') self.assertEqual(parsed.full_type, r'std::array') self.assertEqual(parsed.name, r'anArray') self.assertEqual(parsed.description, r'with a comment') + self.assertEqual(parsed.julia_type, r'MVector{2, Int32}') parsed = parser.parse('::TopLevelNamespaceType aValidType // hopefully') self.assertEqual(parsed.full_type, '::TopLevelNamespaceType') @@ -108,6 +120,7 @@ def test_parse_valid(self): # pylint: disable=too-many-statements self.assertEqual(parsed.description, r'with a top level type') self.assertTrue(not parsed.is_builtin_array) self.assertEqual(parsed.array_type, r'::GlobalType') + self.assertEqual(parsed.julia_type, r'MVector{1, GlobalTypeStruct}') parsed = parser.parse(r'std::array fixedWidthArray // a fixed width type array') self.assertEqual(parsed.full_type, r'std::array') @@ -115,6 +128,7 @@ def test_parse_valid(self): # pylint: disable=too-many-statements self.assertEqual(parsed.description, r'a fixed width type array') self.assertTrue(parsed.is_builtin_array) self.assertEqual(parsed.array_type, r'std::int16_t') + self.assertEqual(parsed.julia_type, r'MVector{42, Int16}') parsed = parser.parse(r'std::array fixedWidthArray // a fixed width type array without namespace') self.assertEqual(parsed.full_type, r'std::array') @@ -122,6 +136,7 @@ def test_parse_valid(self): # pylint: disable=too-many-statements self.assertEqual(parsed.description, r'a fixed width type array without namespace') self.assertTrue(parsed.is_builtin_array) self.assertEqual(parsed.array_type, r'std::uint32_t') + self.assertEqual(parsed.julia_type, r'MVector{42, UInt32}') def test_parse_valid_default_value(self): """Test that member variables can be parsed correctly if they have a user @@ -227,23 +242,27 @@ def test_parse_valid_no_description(self): parsed = parser.parse('unsigned long long aLongWithoutDescription', False) self.assertEqual(parsed.full_type, 'unsigned long long') self.assertEqual(parsed.name, 'aLongWithoutDescription') + self.assertEqual(parsed.julia_type, r'UInt64') parsed = parser.parse('std::array unDescribedArray', False) self.assertEqual(parsed.full_type, 'std::array') self.assertEqual(parsed.name, 'unDescribedArray') self.assertEqual(parsed.array_type, 'unsigned long') self.assertTrue(parsed.is_builtin_array) + self.assertEqual(parsed.julia_type, r'MVector{123, UInt32}') parsed = parser.parse('unsigned long longWithReallyStupidName', False) self.assertEqual(parsed.full_type, 'unsigned long') self.assertEqual(parsed.name, 'longWithReallyStupidName') + self.assertEqual(parsed.julia_type, r'UInt32') parsed = parser.parse('NonBuiltIn aType // descriptions are not ignored even though they are not required', False) self.assertEqual(parsed.full_type, 'NonBuiltIn') self.assertEqual(parsed.name, 'aType') self.assertEqual(parsed.description, 'descriptions are not ignored even though they are not required') self.assertTrue(not parsed.is_builtin) - + self.assertEqual(parsed.julia_type, r'NonBuiltIn') + def test_string_representation(self): """Test that the string representation that is used in the jinja2 templates includes the default initialization""" diff --git a/python/podio_class_generator.py b/python/podio_class_generator.py index c1370ea08..dab2cc297 100755 --- a/python/podio_class_generator.py +++ b/python/podio_class_generator.py @@ -114,6 +114,8 @@ def __init__(self, yamlfile, install_dir, package_name, io_handlers, verbose, dr self.any_changes = False def _process_parent_module(self, datamodel): + """Process parent module of julia that contains constructor definitions + of components and datatypes""" self._fill_templates("ParentModule", datamodel) def process(self): @@ -259,7 +261,7 @@ def _process_component(self, name, component): includes.update(component.get("ExtraCode", {}).get("includes", "").split('\n')) component['includes'] = self._sort_includes(includes) - component['includes_jl'] = {'struct': includes_jl} + component['includes_jl'] = {'struct': sorted(includes_jl)} component['class'] = DataType(name) self._fill_templates('Component', component) @@ -289,6 +291,7 @@ def _preprocess_for_julia(self, datatype): if not member.is_builtin: includes_jl_struct.add(self._build_julia_include(member)) datatype['includes_jl']['struct'].update((includes_jl_struct)) + sorted(datatype['includes_jl']['struct']) @staticmethod def _get_julia_params(datatype): @@ -431,7 +434,7 @@ def _preprocess_datatype(self, name, definition): data['class'] = DataType(name) data['includes_data'] = self._get_member_includes(definition["Members"]) data['includes_jl'] = {'struct': self._get_member_includes(definition["Members"], julia=True)} - data['params_jl'] = self._get_julia_params(data) + data['params_jl'] = sorted(self._get_julia_params(data)) self._preprocess_for_class(data) self._preprocess_for_obj(data) self._preprocess_for_collection(data) diff --git a/python/templates/CMakeLists.txt b/python/templates/CMakeLists.txt index b4f8c1a9e..ba1a57d7e 100644 --- a/python/templates/CMakeLists.txt +++ b/python/templates/CMakeLists.txt @@ -22,8 +22,6 @@ set(PODIO_TEMPLATES ${CMAKE_CURRENT_LIST_DIR}/macros/sioblocks.jinja2 ${CMAKE_CURRENT_LIST_DIR}/macros/utils.jinja2 - ${CMAKE_CURRENT_LIST_DIR}/JuliaCollection.jl.jinja2 - ${CMAKE_CURRENT_LIST_DIR}/Constructor.jl.jinja2 ${CMAKE_CURRENT_LIST_DIR}/MutableStruct.jl.jinja2 ${CMAKE_CURRENT_LIST_DIR}/ParentModule.jl.jinja2 )