From 174ed7800e32bb3c2d0bd2a42793fe42160f3ebe Mon Sep 17 00:00:00 2001 From: Vanessa Sochat Date: Mon, 17 Dec 2018 15:41:01 -0500 Subject: [PATCH 1/2] fixing bug to parse newlines --- CHANGELOG.md | 1 + spython/main/parse/docker.py | 27 ++++++--------------------- spython/version.py | 2 +- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 869061a8..0faa56f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The client here will eventually be released as "spython" (and eventually to singularity on pypi), and the versions here will coincide with these releases. ## [master](https://github.com/singularityhub/singularity-cli/tree/master) + - continued lines should not be split in docker.py recipe parser (_setup) (0.0.49) - COPY command should honor src src dest (and not reverse) (0.0.48) - adding support for instance list (0.0.47) - ENV variables in Dockerfile can be empty (like unsetting) (0.0.46) diff --git a/spython/main/parse/docker.py b/spython/main/parse/docker.py index 14904615..09d04a9d 100644 --- a/spython/main/parse/docker.py +++ b/spython/main/parse/docker.py @@ -48,7 +48,10 @@ def _setup(self, action, line): bot.debug('[in] %s' % line) # Replace ACTION at beginning - line = re.sub('^%s' %action, '', line) + line = re.sub('^%s' % action, '', line) + + # Handle continuation lines without ACTION by padding with leading space + line = " " + line # Split into components return [x for x in self._split_line(line) if x not in ['', None]] @@ -372,25 +375,7 @@ def _label(self, line): self.labels += [ label ] -# Main Parsing Functions - - - def _split_line(self, line): - '''clean a line to prepare it for parsing, meaning separation - of the Docker command (e.g., RUN) from the remainder. We remove - newlines (from ends) along with extra spaces. - - Parameters - ========== - line: the string to parse into parts - - Returns - ======= - parts: a list of line pieces, the command is likely first - - ''' - return [x.strip() for x in line.split(' ', 1)] - +# Main Parsing Functions def _get_mapping(self, line, parser=None, previous=None): @@ -443,7 +428,7 @@ def _get_mapping(self, line, parser=None, previous=None): previous = self._clean_line(previous) # if we are continuing from last - if cleaned.endswith('\\') and parser or previous.endswith('\\'): + if cleaned.endswith('\\') and parser or previous.endswith('\\'): #or previous.endswith('\\\n'): return parser return self._default diff --git a/spython/version.py b/spython/version.py index 81bc2ab3..b489aedb 100644 --- a/spython/version.py +++ b/spython/version.py @@ -16,7 +16,7 @@ -__version__ = "0.0.48" +__version__ = "0.0.49" AUTHOR = 'Vanessa Sochat' AUTHOR_EMAIL = 'vsochat@stanford.edu' NAME = 'spython' From caf30a81a3dbaf4d83bee597790881a3aac2cc86 Mon Sep 17 00:00:00 2001 From: Vanessa Sochat Date: Mon, 17 Dec 2018 15:43:19 -0500 Subject: [PATCH 2/2] removing extra comment --- spython/main/parse/docker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spython/main/parse/docker.py b/spython/main/parse/docker.py index 09d04a9d..e720e4ff 100644 --- a/spython/main/parse/docker.py +++ b/spython/main/parse/docker.py @@ -428,7 +428,7 @@ def _get_mapping(self, line, parser=None, previous=None): previous = self._clean_line(previous) # if we are continuing from last - if cleaned.endswith('\\') and parser or previous.endswith('\\'): #or previous.endswith('\\\n'): + if cleaned.endswith('\\') and parser or previous.endswith('\\'): return parser return self._default