11'''
2- Copyright (c) 2017 HERE Europe B.V.
2+ Copyright (c) 2025 HERE Europe B.V.
33 See the LICENSE file in the root of this project for license details.
44'''
55
@@ -61,14 +61,15 @@ def render(self, generator_name):
6161 output_content = generator .render (self .tree )
6262 return output_content
6363
64- def render_python_module (self , module_name = None , archive_name = None ):
64+ def render_python_module (self , module_name = None , archive_name = None , root_namespace = None ):
6565 """
6666 Render python module.
6767 :param module_name: Module name to use. If none, root namespace name is used.
6868 :param archive_name: Archive name to lookup,
6969 if specified, archive type is returned along with the model
70+ :param root_namespace: Root namespace to pick in case of multiple top level namespaces.
7071 """
71- root_namespace = self ._find_root_namespace (self .tree )
72+ root_namespace = self ._find_root_namespace (self .tree , root_namespace )
7273 module_code = self .render ("py" )
7374 module = types .ModuleType (module_name if module_name is not None else root_namespace .name )
7475 #pylint: disable=exec-used
@@ -89,14 +90,20 @@ def _create_generator(cls, name):
8990 return generator_type ()
9091
9192 @staticmethod
92- def _find_root_namespace (tree ):
93+ def _find_root_namespace (tree , root_namespace = None ):
9394 root_children = tree .root .children
9495 root_namespaces = [
9596 child for child in root_children
9697 if isinstance (child , Namespace ) and "builtin" not in child .name
9798 ]
9899 if not root_namespaces :
99100 raise RuntimeError ("No root namespace found." )
101+ elif root_namespace :
102+ for namespace in root_namespaces :
103+ if namespace .name == root_namespace :
104+ return namespace
105+ raise RuntimeError ("Invalid root namespace provided. Could not find root namespace in archive." )
100106 elif len (root_namespaces ) > 1 :
101107 raise RuntimeError ("Ambiguous root namespace. Could not find root archive." )
108+
102109 return root_namespaces [0 ]
0 commit comments