Skip to content

Commit

Permalink
Deprecate 'options' argument to 'expand_template' (#1085)
Browse files Browse the repository at this point in the history
The only known use of the 'options' argument is to force EmPy to treat
bangpaths as comments. This change promotes that option to an explicit
keyword argument of 'expand_template', which decouples the API from the
EmPy API.

Any current uses of 'options' will continue to work, and the new
'ignore_bangpath' option will take precedence in a collision.
  • Loading branch information
cottsay authored Mar 6, 2025
1 parent 4a6c695 commit f0254ed
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 13 deletions.
3 changes: 1 addition & 2 deletions ros_buildfarm/scripts/ci/generate_ci_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import re
import sys

from em import BANGPATH_OPT
from em import Hook
from ros_buildfarm.argument import add_argument_arch
from ros_buildfarm.argument import add_argument_build_name
Expand Down Expand Up @@ -163,7 +162,7 @@ def beforeInclude(self, *_, **kwargs):
'scripts': hook.scripts,
'build_tool': args.build_tool or build_file.build_tool,
'parameters': hook.parameters},
options={BANGPATH_OPT: False})
ignore_bangpath=True)
value = re.sub(r'(^| )python3 ', r'\1' + sys.executable + ' ', value, flags=re.M)
print(value)

Expand Down
3 changes: 1 addition & 2 deletions ros_buildfarm/scripts/devel/generate_devel_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import re
import sys

from em import BANGPATH_OPT
from em import Hook
from ros_buildfarm.argument import add_argument_arch
from ros_buildfarm.argument import add_argument_build_name
Expand Down Expand Up @@ -140,7 +139,7 @@ def beforeInclude(self, *_, **kwargs):
'scms': hook.scms,
'scripts': hook.scripts,
'build_tool': args.build_tool or build_file.build_tool},
options={BANGPATH_OPT: False})
ignore_bangpath=True)
value = re.sub(r'(^| )python3 ', r'\1' + sys.executable + ' ', value, flags=re.M)
print(value)

Expand Down
3 changes: 1 addition & 2 deletions ros_buildfarm/scripts/doc/generate_doc_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import re
import sys

from em import BANGPATH_OPT
from em import Hook
from ros_buildfarm.argument import add_argument_arch
from ros_buildfarm.argument import add_argument_build_name
Expand Down Expand Up @@ -127,7 +126,7 @@ def beforeInclude(self, *args, **kwargs):
'scms': hook.scms,
'scripts': scripts,
'doc_path': doc_path},
options={BANGPATH_OPT: False})
ignore_bangpath=True)
value = re.sub(r'(^| )python3 ', r'\1' + sys.executable + ' ', value, flags=re.M)
print(value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import sys

from catkin_pkg.packages import find_packages
from em import BANGPATH_OPT
from ros_buildfarm.argument import add_argument_arch
from ros_buildfarm.argument import add_argument_config_url
from ros_buildfarm.argument import add_argument_os_code_name
Expand Down Expand Up @@ -111,7 +110,7 @@ def main(argv=sys.argv[1:]):
value = expand_template(
'prerelease/prerelease_overlay_script.sh.em', {
'scms': scms},
options={BANGPATH_OPT: False})
ignore_bangpath=True)
print(value)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import stat
import sys

from em import BANGPATH_OPT
from em import Hook
from ros_buildfarm.argument import add_argument_arch
from ros_buildfarm.argument import add_argument_build_name
Expand Down Expand Up @@ -294,7 +293,7 @@ def beforeInclude(self, *_, **kwargs):
'prerelease_clone_underlay']:
content = expand_template(
'prerelease/%s_script.sh.em' % script_name, data,
options={BANGPATH_OPT: False})
ignore_bangpath=True)
script_file = os.path.join(args.output_dir, script_name + '.sh')
with open(script_file, 'w') as h:
h.write(content)
Expand Down
3 changes: 1 addition & 2 deletions ros_buildfarm/scripts/release/generate_release_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import re
import sys

from em import BANGPATH_OPT
from em import Hook
from ros_buildfarm.argument import add_argument_arch
from ros_buildfarm.argument import add_argument_build_name
Expand Down Expand Up @@ -151,7 +150,7 @@ def beforeInclude(self, *args, **kwargs):
'source_scripts': source_scripts,
'binary_scripts': binary_scripts,
'package_format': package_format},
options={BANGPATH_OPT: False})
ignore_bangpath=True)
value = re.sub(r'(^| )python3 ', r'\1' + sys.executable + ' ', value, flags=re.M)
print(value)

Expand Down
18 changes: 17 additions & 1 deletion ros_buildfarm/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import os
import sys
import time
import warnings
from xml.sax.saxutils import escape

from em import BANGPATH_OPT
from em import Interpreter

template_prefix_path = [os.path.abspath(os.path.dirname(__file__))]
Expand Down Expand Up @@ -67,10 +69,24 @@ def parse(self, scanner, locals=None):
token.run(self, locals)


def expand_template(template_name, data, options=None):
def expand_template(
template_name, data, options=None, *, ignore_bangpath=None,
):
global interpreter
global template_hooks

if options is not None:
warnings.warn(
"The 'options' argument is deprecated",
category=DeprecationWarning,
stacklevel=2)

if ignore_bangpath:
options = {
**(options or {}),
BANGPATH_OPT: False,
}

output = StringIO()
try:
interpreter = CachingInterpreter(output=output, options=options)
Expand Down

0 comments on commit f0254ed

Please sign in to comment.