Skip to content

Commit

Permalink
Add indirection for changes in empy 3 vs 4
Browse files Browse the repository at this point in the history
Fixes  #259
  • Loading branch information
tfoote committed Dec 5, 2023
1 parent 85464b1 commit 0e09053
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
23 changes: 23 additions & 0 deletions src/rocker/em.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2019 Open Source Robotics Foundation

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import em

def empy_expand(template, substitution_variables):
"""Indirection for empy version compatibility."""
if em.__version__.startswith('3'):
return em.expand(template, substitution_variables)
else:
return em.expand(template, globals=substitution_variables)
7 changes: 4 additions & 3 deletions src/rocker/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import sys

from .core import get_docker_client
from .em import empy_expand


def name_to_argument(name):
Expand Down Expand Up @@ -81,7 +82,7 @@ def get_preamble(self, cliargs):

def get_snippet(self, cliargs):
snippet = pkgutil.get_data('rocker', 'templates/%s_snippet.Dockerfile.em' % self.name).decode('utf-8')
return em.expand(snippet, globals=self.get_environment_subs())
return empy_expand(snippet, self.get_environment_subs())

@staticmethod
def register_arguments(parser, defaults={}):
Expand Down Expand Up @@ -238,7 +239,7 @@ def get_preamble(self, cliargs):

def get_snippet(self, cliargs):
snippet = pkgutil.get_data('rocker', 'templates/%s_snippet.Dockerfile.em' % self.name).decode('utf-8')
return em.expand(snippet, globals=self.get_environment_subs())
return empy_expand(snippet, self.get_environment_subs())

def get_docker_args(self, cliargs):
args = ' -v /run/user/%(user_id)s/pulse:/run/user/%(user_id)s/pulse --device /dev/snd '\
Expand Down Expand Up @@ -318,7 +319,7 @@ def get_snippet(self, cliargs):
substitutions['shell'] = None
else:
substitutions['shell'] = cliargs['user_override_shell']
return em.expand(snippet, globals=substitutions)
return empy_expand(snippet, substitutions)

@staticmethod
def register_arguments(parser, defaults={}):
Expand Down
10 changes: 6 additions & 4 deletions src/rocker/nvidia_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from .extensions import name_to_argument
from .core import get_docker_client
from .core import RockerExtension
from .em import empy_expand


def get_docker_version():
docker_version_raw = get_docker_client().version()['Version']
Expand Down Expand Up @@ -116,11 +118,11 @@ def get_environment_subs(self, cliargs={}):

def get_preamble(self, cliargs):
preamble = pkgutil.get_data('rocker', 'templates/%s_preamble.Dockerfile.em' % self.name).decode('utf-8')
return em.expand(preamble, globals=self.get_environment_subs(cliargs))
return empy_expand(preamble, self.get_environment_subs(cliargs))

def get_snippet(self, cliargs):
snippet = pkgutil.get_data('rocker', 'templates/%s_snippet.Dockerfile.em' % self.name).decode('utf-8')
return em.expand(snippet, globals=self.get_environment_subs(cliargs))
return empy_expand(snippet, self.get_environment_subs(cliargs))

def get_docker_args(self, cliargs):
force_flag = cliargs.get('nvidia', None)
Expand Down Expand Up @@ -184,11 +186,11 @@ def get_environment_subs(self, cliargs={}):
def get_preamble(self, cliargs):
return ''
# preamble = pkgutil.get_data('rocker', 'templates/%s_preamble.Dockerfile.em' % self.name).decode('utf-8')
# return em.expand(preamble, globals=self.get_environment_subs(cliargs))
# return empy_expand(preamble, self.get_environment_subs(cliargs))

def get_snippet(self, cliargs):
snippet = pkgutil.get_data('rocker', 'templates/%s_snippet.Dockerfile.em' % self.name).decode('utf-8')
return em.expand(snippet, globals=self.get_environment_subs(cliargs))
return empy_expand(snippet, self.get_environment_subs(cliargs))

def get_docker_args(self, cliargs):
return ""
Expand Down

0 comments on commit 0e09053

Please sign in to comment.