diff --git a/ros2pkg/ros2pkg/api/create.py b/ros2pkg/ros2pkg/api/create.py index 02e08281f..98cc13962 100644 --- a/ros2pkg/ros2pkg/api/create.py +++ b/ros2pkg/ros2pkg/api/create.py @@ -17,6 +17,12 @@ import sys import em +try: + from em import Configuration + em_has_configuration = True +except ImportError: + em_has_configuration = False + try: import importlib.resources as importlib_resources except ModuleNotFoundError: @@ -25,14 +31,25 @@ def _expand_template(template_file, data, output_file): output = StringIO() - interpreter = em.Interpreter( - output=output, - options={ - em.BUFFERED_OPT: True, - em.RAW_OPT: True, - }, - globals=data, - ) + if em_has_configuration: + config = Configuration( + defaultStdout=output, + deleteOnError=True, + rawErrors=True, + useProxy=True) + interpreter = em.Interpreter( + config=config, + dispatcher=False, + globals=data) + else: + interpreter = em.Interpreter( + output=output, + options={ + em.BUFFERED_OPT: True, + em.RAW_OPT: True, + }, + globals=data) + with open(template_file, 'r') as h: try: interpreter.file(h)