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

fix: Handle multiline strings in yaml serialization. #935

Merged
merged 4 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 12 additions & 4 deletions docs/examples/workflows/artifacts/artifact.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ task, consumer, takes this artifact, places it at its own `/file` path, and prin
command:
- python
image: python:3.8
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('/tmp/file',\
\ 'w+') as f:\n f.write('Hello, world!')"
source: |-
import os
import sys
sys.path.append(os.getcwd())
with open('/tmp/file', 'w+') as f:
f.write('Hello, world!')
- inputs:
artifacts:
- name: in-art
Expand All @@ -76,7 +80,11 @@ task, consumer, takes this artifact, places it at its own `/file` path, and prin
command:
- python
image: python:3.8
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('/tmp/file',\
\ 'r') as f:\n print(f.readlines())"
source: |-
import os
import sys
sys.path.append(os.getcwd())
with open('/tmp/file', 'r') as f:
print(f.readlines())
```

41 changes: 24 additions & 17 deletions docs/examples/workflows/artifacts/artifact_with_fanout.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,14 @@
command:
- python
image: python:3.8
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nimport json\n\
with open('/tmp/file', 'w+') as f:\n for i in range(10):\n f.write(json.dumps(i)\
\ + '\\n')"
source: |-
import os
import sys
sys.path.append(os.getcwd())
import json
with open('/tmp/file', 'w+') as f:
for i in range(10):
f.write(json.dumps(i) + '\n')
- inputs:
artifacts:
- name: in-art
Expand All @@ -98,10 +103,17 @@
command:
- python
image: python:3.8
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nimport json\n\
import sys\nindices = []\nwith open('/tmp/file', 'r') as f:\n for line\
\ in f.readlines():\n indices.append(line.strip())\njson.dump(indices,\
\ sys.stdout)"
source: |-
import os
import sys
sys.path.append(os.getcwd())
import json
import sys
indices = []
with open('/tmp/file', 'r') as f:
for line in f.readlines():
indices.append(line.strip())
json.dump(indices, sys.stdout)
- inputs:
parameters:
- name: i
Expand All @@ -110,19 +122,14 @@
command:
- python
image: python:3.8
source: 'import os

source: |-
import os
import sys

sys.path.append(os.getcwd())

import json
try: i = json.loads(r'''{{inputs.parameters.i}}''')
except: i = r'''{{inputs.parameters.i}}'''

try: i = json.loads(r''''''{{inputs.parameters.i}}'''''')

except: i = r''''''{{inputs.parameters.i}}''''''


print(i)'
print(i)
```

49 changes: 23 additions & 26 deletions docs/examples/workflows/daemon.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,21 @@ http requests to the server.
command:
- python
image: python:3.8
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nfrom http.server\
\ import BaseHTTPRequestHandler, HTTPServer\n\nclass MyServer(BaseHTTPRequestHandler):\n\
\n def do_GET(self):\n self.send_response(200)\n self.send_header('Content-type',\
\ 'application/json')\n self.end_headers()\n self.wfile.write(bytes(\"\
{'name':'John'}\", 'utf-8'))\nwebServer = HTTPServer(('0.0.0.0', 8080), MyServer)\n\
webServer.serve_forever()"
source: |-
import os
import sys
sys.path.append(os.getcwd())
from http.server import BaseHTTPRequestHandler, HTTPServer

class MyServer(BaseHTTPRequestHandler):

def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(bytes("{'name':'John'}", 'utf-8'))
webServer = HTTPServer(('0.0.0.0', 8080), MyServer)
webServer.serve_forever()
- inputs:
parameters:
- name: ip
Expand All @@ -91,33 +100,21 @@ http requests to the server.
command:
- python
image: python:3.8
source: 'import os

source: |-
import os
import sys

sys.path.append(os.getcwd())

import json

try: ip = json.loads(r''''''{{inputs.parameters.ip}}'''''')

except: ip = r''''''{{inputs.parameters.ip}}''''''

try: ip = json.loads(r'''{{inputs.parameters.ip}}''')
except: ip = r'''{{inputs.parameters.ip}}'''

import http.client

import os

print(os.environ)

server_ip = ip.replace(''"'', '''')

connection = http.client.HTTPConnection(''{server_ip}:8080''.format(server_ip=server_ip))

connection.request(''GET'', ''/'')

server_ip = ip.replace('"', '')
connection = http.client.HTTPConnection('{server_ip}:8080'.format(server_ip=server_ip))
connection.request('GET', '/')
response = connection.getresponse()

print(response.read())'
print(response.read())
```

46 changes: 22 additions & 24 deletions docs/examples/workflows/dags/any_success_all_fail.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,18 @@
command:
- python
image: python:3.8
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nimport json\n\
try: a = json.loads(r'''{{inputs.parameters.a}}''')\nexcept: a = r'''{{inputs.parameters.a}}'''\n\
\nimport random\nrandom.seed(a)\nif random.random() < 0.5:\n raise Exception('Oh,\
\ no!')"
source: |-
import os
import sys
sys.path.append(os.getcwd())
import json
try: a = json.loads(r'''{{inputs.parameters.a}}''')
except: a = r'''{{inputs.parameters.a}}'''

import random
random.seed(a)
if random.random() < 0.5:
raise Exception('Oh, no!')
- inputs:
parameters:
- name: a
Expand All @@ -96,20 +104,15 @@
command:
- python
image: python:3.8
source: 'import os

source: |-
import os
import sys

sys.path.append(os.getcwd())

import json
try: a = json.loads(r'''{{inputs.parameters.a}}''')
except: a = r'''{{inputs.parameters.a}}'''

try: a = json.loads(r''''''{{inputs.parameters.a}}'''''')

except: a = r''''''{{inputs.parameters.a}}''''''


raise Exception(a)'
raise Exception(a)
- inputs:
parameters:
- name: a
Expand All @@ -118,19 +121,14 @@
command:
- python
image: python:3.8
source: 'import os

source: |-
import os
import sys

sys.path.append(os.getcwd())

import json
try: a = json.loads(r'''{{inputs.parameters.a}}''')
except: a = r'''{{inputs.parameters.a}}'''

try: a = json.loads(r''''''{{inputs.parameters.a}}'''''')

except: a = r''''''{{inputs.parameters.a}}''''''


print(a)'
print(a)
```

15 changes: 5 additions & 10 deletions docs/examples/workflows/dags/callable_dag.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,15 @@
command:
- python
image: python:3.8
source: 'import os

source: |-
import os
import sys

sys.path.append(os.getcwd())

import json
try: name = json.loads(r'''{{inputs.parameters.name}}''')
except: name = r'''{{inputs.parameters.name}}'''

try: name = json.loads(r''''''{{inputs.parameters.name}}'''''')

except: name = r''''''{{inputs.parameters.name}}''''''


print(''Hello, {name}!''.format(name=name))'
print('Hello, {name}!'.format(name=name))
- dag:
tasks:
- arguments:
Expand Down
14 changes: 11 additions & 3 deletions docs/examples/workflows/dags/complex_deps.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,16 @@
command:
- python
image: python:3.8
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nimport json\n\
try: p = json.loads(r'''{{inputs.parameters.p}}''')\nexcept: p = r'''{{inputs.parameters.p}}'''\n\
\nif p < 0.5:\n raise Exception(p)\nprint(42)"
source: |-
import os
import sys
sys.path.append(os.getcwd())
import json
try: p = json.loads(r'''{{inputs.parameters.p}}''')
except: p = r'''{{inputs.parameters.p}}'''

if p < 0.5:
raise Exception(p)
print(42)
```

27 changes: 15 additions & 12 deletions docs/examples/workflows/dags/conditional.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,34 @@ This example showcases conditional execution on success, failure, and error
command:
- python
image: python:3.8
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nimport random\n\
p = random.random()\nif p <= 0.5:\n raise Exception('failure')\nprint('success')"
source: |-
import os
import sys
sys.path.append(os.getcwd())
import random
p = random.random()
if p <= 0.5:
raise Exception('failure')
print('success')
- name: success
script:
command:
- python
image: python:3.8
source: 'import os

source: |-
import os
import sys

sys.path.append(os.getcwd())

print(''success'')'
print('success')
- name: failure
script:
command:
- python
image: python:3.8
source: 'import os

source: |-
import os
import sys

sys.path.append(os.getcwd())

print(''failure'')'
print('failure')
```

25 changes: 13 additions & 12 deletions docs/examples/workflows/dags/dag_conditional_on_task_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,32 @@
command:
- python
image: python:3.8
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nimport random\n\
if random.randint(0, 1) == 0:\n raise ValueError"
source: |-
import os
import sys
sys.path.append(os.getcwd())
import random
if random.randint(0, 1) == 0:
raise ValueError
- name: when-failed
script:
command:
- python
image: python:3.8
source: 'import os

source: |-
import os
import sys

sys.path.append(os.getcwd())

print(''It was a failure'')'
print('It was a failure')
- name: when-succeeded
script:
command:
- python
image: python:3.8
source: 'import os

source: |-
import os
import sys

sys.path.append(os.getcwd())

print(''It was a success'')'
print('It was a success')
```

6 changes: 3 additions & 3 deletions docs/examples/workflows/dags/dag_conditional_parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
command:
- python
image: python:alpine3.6
source: 'import random

print(''heads'' if random.randint(0, 1) == 0 else ''tails'')'
source: |-
import random
print('heads' if random.randint(0, 1) == 0 else 'tails')
- name: heads
script:
command:
Expand Down
Loading
Loading