Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support empy4 and empy3 #921

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines +20 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks totally reasonable to me (though I'm the one who suggested it, so that's not surprising).

Before approving this, I'd like to get @cottsay 's take on this pattern.


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