Skip to content

Commit

Permalink
monkey patch shell_quote in vsc.utils.generaloption to fix easybuilde…
Browse files Browse the repository at this point in the history
  • Loading branch information
boegel committed Sep 16, 2016
1 parent 2cfe64c commit 1a3bfab
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
20 changes: 18 additions & 2 deletions easybuild/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
import shutil
import sys
import tempfile
import vsc.utils.generaloption
from distutils.version import LooseVersion
from vsc.utils import fancylogger
from vsc.utils.generaloption import GeneralOption

import easybuild.tools.environment as env
from easybuild.framework.easyblock import MODULE_ONLY_STEPS, SOURCE_STEP, EasyBlock
Expand Down Expand Up @@ -78,8 +81,6 @@
from easybuild.tools.toolchain.utilities import search_toolchain
from easybuild.tools.repository.repository import avail_repositories
from easybuild.tools.version import this_is_easybuild
from vsc.utils import fancylogger
from vsc.utils.generaloption import GeneralOption

try:
from humanfriendly.terminal import terminal_supports_colors
Expand All @@ -92,6 +93,21 @@ def terminal_supports_colors(stream):
# in case of errors do not bother and just return the safe default
return False

# monkey patch shell_quote in vsc.utils.generaloption, used by generate_cmd_line,
# to fix known issue, cfr. https://github.com/hpcugent/vsc-base/issues/152;
# inspired by https://github.com/hpcugent/vsc-base/pull/151
# this fixes https://github.com/hpcugent/easybuild-framework/issues/1438
# proper fix would be to implement a serialiser for command line options
def eb_shell_quote(token):
"""
Wrap provided token in single quotes (to escape space and characters with special meaning in a shell),
so it can be used in a shell command. This results in token that is not expanded/interpolated by the shell.
"""
# escape any non-escaped single quotes, and wrap entire token in single quotes
return "'%s'" % re.sub(r"(?<!\\)'", r"\'", str(token))

vsc.utils.generaloption.shell_quote = eb_shell_quote


CONFIG_ENV_VAR_PREFIX = 'EASYBUILD'

Expand Down
14 changes: 13 additions & 1 deletion test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1811,12 +1811,24 @@ def generate_cmd_line(ebopts):
self.assertEqual(generate_cmd_line(ebopts), ['--force'])

ebopts = EasyBuildOptions(go_args=['--search=bar', '--search', 'foobar'], envvar_prefix='EASYBUILD')
self.assertEqual(generate_cmd_line(ebopts), ['--search=foobar'])
self.assertEqual(generate_cmd_line(ebopts), ["--search='foobar'"])

os.environ['EASYBUILD_DEBUG'] = '1'
ebopts = EasyBuildOptions(go_args=['--force'], envvar_prefix='EASYBUILD')
self.assertEqual(generate_cmd_line(ebopts), ['--debug', '--force'])

args = [
'--test-report-env-filter=(COOKIE|SESSION)',
'--suffix-modules-path=',
]
expected = [
'--debug',
"--suffix-modules-path=''",
"--test-report-env-filter='(COOKIE|SESSION)'",
]
ebopts = EasyBuildOptions(go_args=args, envvar_prefix='EASYBUILD')
self.assertEqual(generate_cmd_line(ebopts), expected)

def test_include_easyblocks(self):
"""Test --include-easyblocks."""
orig_local_sys_path = sys.path[:]
Expand Down

0 comments on commit 1a3bfab

Please sign in to comment.