Skip to content

Commit

Permalink
Support empy4 and empy3 (#921)
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernández Cordero <[email protected]>
  • Loading branch information
ahcorde authored Aug 22, 2024
1 parent 01ab67c commit f75f4e2
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions ros2pkg/ros2pkg/api/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit f75f4e2

Please sign in to comment.