From f75f4e2499fcd0037eb4ae277d424b4618ae4af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Thu, 22 Aug 2024 10:30:37 +0200 Subject: [PATCH] Support empy4 and empy3 (#921) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alejandro Hernández Cordero --- ros2pkg/ros2pkg/api/create.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) 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)