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

🩹 & Escaping #25

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions mario/pipelines/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def start(self):
def run_pipeline(self):
"""Run the mmif through a CLAMS pipeline"""
mmif = self.input_mmif
print('starting pipeline')
print(self.pipeline)
for app in self.pipeline:
pipeline = self.clean_pipeline()
print('starting pipeline', pipeline)
for app in pipeline:
print(f'Running {app}')
mmif = self.app(app, mmif)
print(f'{app} done')
Expand Down
22 changes: 22 additions & 0 deletions mario/pipelines/trigger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from metaflow import FlowSpec, Parameter, step, trigger


@trigger(event='ampersand')
class TriggerPipeline(FlowSpec):
guid = Parameter('guid', help='GUID of the transcript to process')
pipeline = Parameter(
'pipeline', help='Testing "&" handling in flow parameters', separator=','
)

@step
def start(self):
print(f'Checking {self.pipeline} for "&" handling')
self.next(self.end)

@step
def end(self):
print('Done!')


if __name__ == '__main__':
TriggerPipeline()
21 changes: 21 additions & 0 deletions mario/pipelines/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,24 @@ def cleanup(self) -> None:
remove(f)
cleaned += 1
print(f'Cleaned up {cleaned} files')

def clean_pipeline(self) -> list:
"""Clean pipeline strings

This is needed to restore `&` characters replaced by `\u0026` in the pipeline Parameter,
which is a result of ArgoEvent's parsing of the pipeline URL string as a body payload parameter,
which is written to the Argo-workflow kubernetes resource using `| toJson`,
which wraps the GoLang `json.Marshal` function, which escapes `&`, `<`, and `>` characters to HTML safe unicode.
This shows up as "\\u0026" in the python string.

See https://github.com/WGBH-MLA/chowda/issues/204
"""

return [
app.replace('\\u0026', '&')
.replace('\\u0028', '(')
.replace('\\u0029', ')')
.replace('\\u003c', '<')
.replace('\\u003e', '>')
for app in self.pipeline
]