Skip to content

Commit 7f6bec0

Browse files
authored
Fix inline script parsing issues (#574)
Fixes #572 The fix makes the function parser a bit more robust by round-tripping through ast parse/unparse. This ensures we get consistently formatted code each time and removes any extraneous comments which were previously causing parsing issues. Signed-off-by: Sambhav Kothari <[email protected]>
1 parent 3fa4cc8 commit 7f6bec0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1195
-232
lines changed

docs/examples/workflows/coinflip.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,9 @@
7272

7373
import random
7474

75+
result = ''heads'' if random.randint(0, 1) == 0 else ''tails''
7576

76-
result = "heads" if random.randint(0, 1) == 0 else "tails"
77-
78-
print(result)
79-
80-
'
77+
print(result)'
8178
- name: heads
8279
script:
8380
command:
@@ -89,9 +86,7 @@
8986

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

92-
print("it was heads")
93-
94-
'
89+
print(''it was heads'')'
9590
- name: tails
9691
script:
9792
command:
@@ -103,8 +98,6 @@
10398

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

106-
print("it was tails")
107-
108-
'
101+
print(''it was tails'')'
109102
```
110103

docs/examples/workflows/complex_deps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@
7878
image: python:3.8
7979
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nimport json\n\
8080
try: p = json.loads(r'''{{inputs.parameters.p}}''')\nexcept: p = r'''{{inputs.parameters.p}}'''\n\
81-
\nif p < 0.5:\n raise Exception(p)\nprint(42)\n"
81+
\nif p < 0.5:\n raise Exception(p)\nprint(42)"
8282
```
8383

docs/examples/workflows/dag-with-script-output-param-passing.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
command:
6969
- python
7070
image: python:3.8
71-
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open(\"/test\"\
72-
, \"w\") as f_out:\n f_out.write(\"test\")\n"
71+
source: "import os\nimport sys\nsys.path.append(os.getcwd())\nwith open('/test',\
72+
\ 'w') as f_out:\n f_out.write('test')"
7373
- inputs:
7474
parameters:
7575
- name: a
@@ -91,8 +91,6 @@
9191
except: a = r''''''{{inputs.parameters.a}}''''''
9292

9393

94-
print(a)
95-
96-
'
94+
print(a)'
9795
```
9896

docs/examples/workflows/dag_conditional_parameters.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,18 @@
7979
image: python:alpine3.6
8080
source: 'import random
8181

82-
83-
print("heads" if random.randint(0, 1) == 0 else "tails")
84-
85-
'
82+
print(''heads'' if random.randint(0, 1) == 0 else ''tails'')'
8683
- name: heads
8784
script:
8885
command:
8986
- python
9087
image: python:alpine3.6
91-
source: 'print("heads")
92-
93-
'
88+
source: print('heads')
9489
- name: tails
9590
script:
9691
command:
9792
- python
9893
image: python:alpine3.6
99-
source: 'print("tails")
100-
101-
'
94+
source: print('tails')
10295
```
10396

docs/examples/workflows/dag_diamond_with_callable_decorators.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@
8484
except: message = r''''''{{inputs.parameters.message}}''''''
8585

8686

87-
print(message)
88-
89-
'
87+
print(message)'
9088
```
9189

docs/examples/workflows/dag_diamond_with_callable_script.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@
7070
except: message = r''''''{{inputs.parameters.message}}''''''
7171

7272

73-
print(message)
74-
75-
'
73+
print(message)'
7674
- dag:
7775
tasks:
7876
- arguments:

docs/examples/workflows/dag_with_script_param_passing.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@
6161

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

64-
print(42)
65-
66-
'
64+
print(42)'
6765
- inputs:
6866
parameters:
6967
- name: a
@@ -85,8 +83,6 @@
8583
except: a = r''''''{{inputs.parameters.a}}''''''
8684

8785

88-
print(a)
89-
90-
'
86+
print(a)'
9187
```
9288

docs/examples/workflows/dynamic_volumes.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@
5151

5252
import subprocess
5353

54-
55-
print(subprocess.run("cd && /mnt && df -h", shell=True, capture_output=True).stdout.decode())
56-
57-
'
54+
print(subprocess.run(''cd && /mnt && df -h'', shell=True, capture_output=True).stdout.decode())'
5855
volumeMounts:
5956
- mountPath: /mnt/vol
6057
name: v

docs/examples/workflows/global_config.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@
5757

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

60-
print("hello")
61-
62-
'
60+
print(''hello'')'
6361
```
6462

docs/examples/workflows/multi_env.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,10 @@
6161

6262
import os
6363

64+
assert os.environ[''a''] == ''1'', os.environ[''a'']
6465

65-
# note that env params come in as strings
66+
assert os.environ[''b''] == ''2'', os.environ[''b'']
6667

67-
assert os.environ["a"] == "1", os.environ["a"]
68-
69-
assert os.environ["b"] == "2", os.environ["b"]
70-
71-
assert os.environ["c"] == "3", os.environ["c"]
72-
73-
'
68+
assert os.environ[''c''] == ''3'', os.environ[''c'']'
7469
```
7570

0 commit comments

Comments
 (0)