Skip to content

Commit 8234493

Browse files
committed
Implement workflow_id configuration option
This commit implements the first in-notebook configuration option: adding xcengine_config = dict( workflow_id = "foo" ) will now set the specified string as the ID of the Workflow object within a generated CWL file.
1 parent 9af076c commit 8234493

File tree

6 files changed

+38
-21
lines changed

6 files changed

+38
-21
lines changed

test/data/paramtest.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@
151151
"outputs": [],
152152
"source": [
153153
"parameter_1 = my_constant * 2\n",
154-
"parameter_2 = \"default value\""
154+
"parameter_2 = \"default value\"\n",
155+
"xcengine_config = dict(workflow_id=\"my-workflow\")"
155156
]
156157
}
157158
],
@@ -171,7 +172,7 @@
171172
"name": "python",
172173
"nbconvert_exporter": "python",
173174
"pygments_lexer": "ipython3",
174-
"version": "3.12.8"
175+
"version": "3.13.3"
175176
}
176177
},
177178
"nbformat": 4,

test/test_core.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,10 @@ def test_script_creator_convert_notebook_to_script(tmp_path, clear):
165165
# TODO test execution as well?
166166

167167

168-
def test_script_creator_cwl(tmp_path):
169-
nb_path = pathlib.Path(__file__).parent / "data" / "noparamtest.ipynb"
170-
script_creator = ScriptCreator(
171-
nb_path
172-
)
168+
@pytest.mark.parametrize("nb_name", ["noparamtest", "paramtest"])
169+
def test_script_creator_cwl(tmp_path, nb_name):
170+
nb_path = pathlib.Path(__file__).parent / "data" / f"{nb_name}.ipynb"
171+
script_creator = ScriptCreator(nb_path)
173172
image_tag = "foo"
174173
cwl_path = tmp_path / "test.cwl"
175174
cwl = script_creator.create_cwl(image_tag)
@@ -188,10 +187,14 @@ def test_script_creator_cwl(tmp_path):
188187
cli_tools = [n for n in graph if n["class"] == "CommandLineTool"]
189188
assert len(cli_tools) == 1
190189
cli_tool = cli_tools[0]
191-
assert cli_tool["requirements"]["DockerRequirement"]["dockerPull"] == image_tag
190+
assert (
191+
cli_tool["requirements"]["DockerRequirement"]["dockerPull"]
192+
== image_tag
193+
)
192194
assert cli_tool["hints"]["DockerRequirement"]["dockerPull"] == image_tag
193195
workflows = [n for n in graph if n["class"] == "Workflow"]
194196
assert len(workflows) == 1
195197
workflow = workflows[0]
196-
assert workflow["id"] == nb_path.stem
197-
198+
assert workflow["id"] == (
199+
nb_path.stem if nb_name == "noparamtest" else "my-workflow"
200+
)

test/test_parameters.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,14 @@ def test_parameters_get_cwl_step_inputs(notebook_parameters):
143143

144144

145145
def test_parameters_from_code(expected_vars):
146-
parameters = xcengine.parameters.NotebookParameters.from_code("""
146+
parameters = xcengine.parameters.NotebookParameters.from_code(
147+
"""
147148
some_int = 42
148149
some_float = 3.14159
149150
some_string = "foo"
150151
some_bool = False
151-
""")
152+
"""
153+
)
152154
assert parameters.params == expected_vars
153155
assert parameters.config == {}
154156

xcengine/cli.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,18 @@ def build(
150150
)
151151
image = image_builder.build()
152152
if eoap:
153+
153154
class IndentDumper(yaml.Dumper):
154155
def increase_indent(self, flow=False, indentless=False):
155156
return super(IndentDumper, self).increase_indent(flow, False)
156157

157-
eoap.write_text(yaml.dump(image_builder.create_cwl(), sort_keys=False, Dumper=IndentDumper))
158+
eoap.write_text(
159+
yaml.dump(
160+
image_builder.create_cwl(),
161+
sort_keys=False,
162+
Dumper=IndentDumper,
163+
)
164+
)
158165
print(f"Built image with tags {image.tags}")
159166

160167

xcengine/core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ def create_cwl(self, image_tag: str) -> dict[str, Any]:
123123
"$graph": [
124124
{
125125
"class": "Workflow",
126-
"id": self.nb_path.stem,
126+
"id": self.nb_params.config.get(
127+
"workflow_id", self.nb_path.stem
128+
),
127129
"label": "xcengine notebook",
128130
"doc": "xcengine notebook",
129131
"requirements": [],
@@ -149,9 +151,7 @@ def create_cwl(self, image_tag: str) -> dict[str, Any]:
149151
"requirements": {
150152
"DockerRequirement": {"dockerPull": image_tag}
151153
},
152-
"hints": {
153-
"DockerRequirement": {"dockerPull": image_tag}
154-
},
154+
"hints": {"DockerRequirement": {"dockerPull": image_tag}},
155155
"baseCommand": [
156156
"/usr/local/bin/_entrypoint.sh",
157157
"python",

xcengine/parameters.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class NotebookParameters:
2222
config: dict[str, Any]
2323

2424
def __init__(
25-
self,
26-
params: dict[str, tuple[type, Any]],
27-
config: dict[str, Any] = None
25+
self,
26+
params: dict[str, tuple[type, Any]],
27+
config: dict[str, Any] = None,
2828
):
2929
self.params = params
3030
self.config = {} if config is None else config
@@ -86,7 +86,11 @@ def extract_variables(
8686
def make_param_tuple(cls, key: str, value: Any) -> tuple[type, Any]:
8787
return (
8888
t := type(value),
89-
value if t in {int, float, str, bool} or key == cls.config_var_name else None,
89+
(
90+
value
91+
if t in {int, float, str, bool} or key == cls.config_var_name
92+
else None
93+
),
9094
)
9195

9296
def get_cwl_workflow_inputs(self) -> dict[str, dict[str, Any]]:

0 commit comments

Comments
 (0)