Skip to content
Merged
16 changes: 16 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ jobs:
uses: ros-infrastructure/ci/.github/workflows/pytest.yaml@main
with:
matrix-filter: del(.matrix.os[] | select(contains("windows")))

# Dedicated job for testing with empy < 4
pytest-empy-legacy:
runs-on: ubuntu-latest
name: Test empy < 4 compatibility
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
- name: Install dependencies with empy < 4
run: |
python -m pip install --upgrade pip
pip install -e .[test] 'empy<4'
- name: Run tests
run: |
python -m pytest test/ -v
yamllint:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 3 additions & 1 deletion bloom/generators/debian/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
from bloom.logging import is_debug
from bloom.logging import warning

from bloom.util import expand_template_em

from bloom.commands.git.patch.common import get_patch_config
from bloom.commands.git.patch.common import set_patch_config

Expand Down Expand Up @@ -534,7 +536,7 @@ def __process_template_folder(path, subs):
info("Expanding '{0}' -> '{1}'".format(
os.path.relpath(item),
os.path.relpath(template_path)))
result = em.expand(template, **subs)
result = expand_template_em(template, subs)
# Don't write an empty file
if len(result) == 0 and \
os.path.basename(template_path) in ['copyright']:
Expand Down
9 changes: 2 additions & 7 deletions bloom/generators/rpm/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@

from bloom.util import code
from bloom.util import execute_command
from bloom.util import expand_template_em
from bloom.util import maybe_continue

try:
Expand All @@ -89,12 +90,6 @@
debug(traceback.format_exc())
error("rosdistro was not detected, please install it.", exit=True)

try:
import em
except ImportError:
debug(traceback.format_exc())
error("empy was not detected, please install it.", exit=True)

# Drop the first log prefix for this command
enable_drop_first_log_prefix(True)

Expand Down Expand Up @@ -379,7 +374,7 @@ def __process_template_folder(path, subs):
info("Expanding '{0}' -> '{1}'".format(
os.path.relpath(item),
os.path.relpath(template_path)))
result = em.expand(template, **subs)
result = expand_template_em(template, subs)
# Write the result
with io.open(template_path, 'w', encoding='utf-8') as f:
if sys.version_info.major == 2:
Expand Down
17 changes: 17 additions & 0 deletions bloom/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,23 @@
to_unicode = str


def expand_template_em(template, subs):
"""
Compatibility function for EmPy 3 and 4.
EmPy 3: em.expand(template, **kwargs)
EmPy 4: em.expand(template, locals=dict)
"""
try:
import em
except ImportError:
error("empy was not detected, please install it.", exit=True)

if em.__version__.startswith('3'):
return em.expand(template, **subs)
else:
return em.expand(template, locals=subs)


def flush_stdin():
try:
from termios import tcflush, TCIFLUSH
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python

import sys
from setuptools import find_packages, setup


Expand All @@ -20,7 +19,7 @@
install_requires=[
'catkin_pkg >= 0.4.3',
'setuptools < 82',
'empy < 4',
'empy',
'packaging',
'python-dateutil',
'PyYAML',
Expand Down
4 changes: 2 additions & 2 deletions test/unit_tests/test_generators/test_debian/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from ....utils.common import redirected_stdio

from bloom.generators.debian.generator import em
from bloom.generators.debian.generator import get_changelogs
from bloom.generators.debian.generator import format_description
from bloom.util import expand_template_em

from catkin_pkg.packages import find_packages

Expand All @@ -24,7 +24,7 @@ def test_unicode_templating():
assert 'bad_changelog_pkg' in packages
chlogs = get_changelogs(packages['bad_changelog_pkg'])
template = "@(changelog)"
em.expand(template, {'changelog': chlogs[0][2]})
expand_template_em(template, {'changelog': chlogs[0][2]})


def test_format_description():
Expand Down
Loading