Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove shebang lines from pre/post scripts #895

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions beeflow/common/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ def _validate_prepost_shell_env(self, key, items, fname):
:type fname: str
"""
env_decl = items[key].splitlines()
# Need to remove whitespaces/newlines from list
env_decl = [x for x in env_decl if x.strip()]
# Check for shebang line in pre/post scripts
if not env_decl[0].startswith("#!"):
msg = f'No shebang line found in {fname}'
Expand All @@ -315,6 +317,11 @@ def _validate_prepost_shell_env(self, key, items, fname):
if shell_val != shebang_val:
msg = f'CWL file shell {shell_val} does not match {fname} shell {shebang_val}'
raise CwlParseError(msg) from None
# Remove shebang lines from scripts
rm_line = env_decl[1:]
# List to string format
rm_line = "\n".join(rm_line)
items.update({key: rm_line})

def parse_requirements(self, requirements, as_hints=False):
"""Parse CWL hints/requirements.
Expand Down
2 changes: 1 addition & 1 deletion beeflow/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_parse_workflow_missing_input(self):
name='clamr',
base_command='/CLAMR/clamr_cpuonly',
hints=[Hint(class_='DockerRequirement', params={'dockerFile': '# Dockerfile.clamr-ffmpeg\n# Developed on Chicoma @lanl\n# Patricia Grubel <pagrubel@lanl.gov>\n\nFROM debian:11\n\n\nRUN apt-get update && \\\n apt-get install -y wget gnupg git cmake ffmpeg g++ make openmpi-bin libopenmpi-dev libpng-dev libpng16-16 libpng-tools imagemagick libmagickwand-6.q16-6 libmagickwand-6.q16-dev\n\nRUN git clone https://github.com/lanl/CLAMR.git\nRUN cd CLAMR && cmake . && make clamr_cpuonly\n', 'beeflow:containerName': 'clamr-ffmpeg'}), #noqa
Hint(class_='beeflow:ScriptRequirement', params={'enabled': True, 'pre_script': '#!/bin/bash\n\necho "Before run"\n', 'post_script': '#!/bin/bash\n\necho "After run"\n', 'shell': '/bin/bash'})], #noqa
Hint(class_='beeflow:ScriptRequirement', params={'enabled': True, 'pre_script': 'echo "Before run"', 'post_script': 'echo "After run"', 'shell': '/bin/bash'})], #noqa
requirements=[],
inputs=[StepInput(id='graphic_steps', type='int', value=None, default=None,
source='steps_between_graphics', prefix='-g', position=None,
Expand Down