Skip to content

Commit 236e342

Browse files
authored
Implement new step.inputs[].download configuration (#157)
1 parent 43a1a53 commit 236e342

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

examples/input-extras.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
keep-directories: suffix
1515
default:
1616
- s3://secret-bucket/bars/**.quux
17+
- name: larges
18+
download: on-demand
19+
default:
20+
- s3://foo/bigdata.tar

tests/test_step_parsing.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from valohai_yaml.objs import Config
4-
from valohai_yaml.objs.input import Input, KeepDirectories
4+
from valohai_yaml.objs.input import DownloadIntent, Input, KeepDirectories
55

66

77
def test_parse_inputs(example2_config):
@@ -140,8 +140,10 @@ def test_input_extras(input_extras_config):
140140
step = config.steps["example"]
141141
assert step.inputs["model"].keep_directories == KeepDirectories.NONE
142142
assert step.inputs["model"].filename == "model.pb"
143+
assert step.inputs["model"].download == DownloadIntent.ALWAYS
143144
assert step.inputs["foos"].keep_directories == KeepDirectories.FULL
144145
assert step.inputs["bars"].keep_directories == KeepDirectories.SUFFIX
146+
assert step.inputs["larges"].download == DownloadIntent.ON_DEMAND
145147

146148

147149
@pytest.mark.parametrize(
@@ -179,3 +181,16 @@ def test_widget(example1_config: Config) -> None:
179181
assert widget and widget.type == "datumalias"
180182
assert widget and widget.settings and widget.settings["width"] == 123
181183
assert parameters["decoder-spec"].widget is None
184+
185+
186+
@pytest.mark.parametrize(
187+
"value, expected",
188+
[
189+
*[(dp, dp) for dp in DownloadIntent],
190+
("always", DownloadIntent.ALWAYS),
191+
("on-demand", DownloadIntent.ON_DEMAND),
192+
(None, DownloadIntent.ALWAYS),
193+
],
194+
)
195+
def test_download_policy(value, expected):
196+
assert Input(name="foo", download=value).download == expected

valohai_yaml/objs/input.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ def cast(cls, value: KeepDirectoriesValue) -> "KeepDirectories":
2525
return KeepDirectories(str(value).lower())
2626

2727

28+
class DownloadIntent(Enum):
29+
"""Specify input download intention."""
30+
31+
ALWAYS = "always"
32+
ON_DEMAND = "on-demand"
33+
34+
@classmethod
35+
def cast(cls, value: Union[None, str, "DownloadIntent"]) -> "DownloadIntent":
36+
if isinstance(value, DownloadIntent):
37+
return value
38+
if value is None:
39+
return DownloadIntent.ALWAYS
40+
return DownloadIntent(str(value).lower())
41+
42+
2843
class Input(Item):
2944
"""Represents an input definition within a step definition."""
3045

@@ -37,18 +52,24 @@ def __init__(
3752
description: Optional[str] = None,
3853
keep_directories: KeepDirectoriesValue = False,
3954
filename: Optional[str] = None,
55+
download: Optional[str] = None,
4056
) -> None:
4157
self.name = name
4258
self.default = default # may be None, a string or a list of strings
4359
self.optional = bool(optional)
4460
self.description = description
4561
self.keep_directories = KeepDirectories.cast(keep_directories)
4662
self.filename = filename
63+
self.download = DownloadIntent.cast(download)
4764

4865
def get_data(self) -> SerializedDict:
4966
data = super().get_data()
5067
if self.keep_directories is not KeepDirectories.NONE:
5168
data["keep_directories"] = data["keep_directories"].value
5269
else:
5370
data.pop("keep_directories", None)
71+
if self.download is not DownloadIntent.ALWAYS:
72+
data["download"] = data["download"].value
73+
else:
74+
data.pop("download", None)
5475
return data

valohai_yaml/schema/input-item.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,12 @@ properties:
3838
- "suffix"
3939
default: false
4040
description: Whether to retain directories when using wildcards for this input.
41+
download:
42+
type: string
43+
enum:
44+
- "always"
45+
- "on-demand"
46+
default: "always"
47+
description: |
48+
Select downloading intention for this input. On-demand inputs are not downloaded before
49+
the step can run, instead are available to download using an authenticated download URL.

0 commit comments

Comments
 (0)