-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issues with configs and Runner (#2234)
- Rename config_file to config to make it consistent with the Click API - Allow CustomFlowDecorators to work with Runner (currently, it was not finding the FlowSpec) - Remove hidden options from Click API - Small other fixes to get Runner to work with various combinations of CustomFlowDecorators and CustomStepDecorators
- Loading branch information
1 parent
afd0910
commit 85da991
Showing
22 changed files
with
209 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
baz:amazing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import time | ||
from metaflow import FlowSpec, step, Config, card | ||
|
||
|
||
class CardConfigFlow(FlowSpec): | ||
|
||
config = Config("config", default_value="") | ||
|
||
@card(type=config.type) | ||
@step | ||
def start(self): | ||
print("card type", self.config.type) | ||
self.next(self.end) | ||
|
||
@step | ||
def end(self): | ||
print("full config", self.config) | ||
|
||
|
||
if __name__ == "__main__": | ||
CardConfigFlow() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import time | ||
from metaflow import FlowSpec, step, card, current, Config, Parameter, config_expr | ||
from metaflow.cards import Image | ||
|
||
BASE = "https://picsum.photos/id" | ||
|
||
|
||
class ConfigurablePhotoFlow(FlowSpec): | ||
cfg = Config("config", default="photo_config.json") | ||
id = Parameter("id", default=cfg.id, type=int) | ||
size = Parameter("size", default=cfg.size, type=int) | ||
|
||
@card | ||
@step | ||
def start(self): | ||
import requests | ||
|
||
params = {k: v for k, v in self.cfg.style.items() if v} | ||
self.url = f"{BASE}/{self.id}/{self.size}/{self.size}" | ||
img = requests.get(self.url, params) | ||
current.card.append(Image(img.content)) | ||
self.next(self.end) | ||
|
||
@step | ||
def end(self): | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
ConfigurablePhotoFlow() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import json | ||
import os | ||
|
||
from metaflow import ( | ||
Config, | ||
FlowSpec, | ||
Parameter, | ||
config_expr, | ||
current, | ||
environment, | ||
project, | ||
step, | ||
timeout, | ||
) | ||
|
||
default_config = {"blur": 123, "timeout": 10} | ||
|
||
|
||
def myparser(s: str): | ||
return {"hi": "you"} | ||
|
||
|
||
class ConfigSimple(FlowSpec): | ||
|
||
cfg = Config("cfg", default_value=default_config) | ||
cfg_req = Config("cfg_req2", required=True) | ||
blur = Parameter("blur", default=cfg.blur) | ||
blur2 = Parameter("blur2", default=cfg_req.blur) | ||
cfg_non_req = Config("cfg_non_req") | ||
cfg_empty_default = Config("cfg_empty_default", default_value={}) | ||
cfg_empty_default_parser = Config( | ||
"cfg_empty_default_parser", default_value="", parser=myparser | ||
) | ||
cfg_non_req_parser = Config("cfg_non_req_parser", parser=myparser) | ||
|
||
@timeout(seconds=cfg["timeout"]) | ||
@step | ||
def start(self): | ||
print( | ||
"Non req: %s; emtpy_default %s; empty_default_parser: %s, non_req_parser: %s" | ||
% ( | ||
self.cfg_non_req, | ||
self.cfg_empty_default, | ||
self.cfg_empty_default_parser, | ||
self.cfg_non_req_parser, | ||
) | ||
) | ||
print("Blur is %s" % self.blur) | ||
print("Blur2 is %s" % self.blur2) | ||
print("Config is of type %s" % type(self.cfg)) | ||
self.next(self.end) | ||
|
||
@step | ||
def end(self): | ||
print("Blur is %s" % self.blur) | ||
print("Blur2 is %s" % self.blur2) | ||
|
||
|
||
if __name__ == "__main__": | ||
ConfigSimple() |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from metaflow import Config, FlowSpec, card, step | ||
|
||
|
||
class Sample(FlowSpec): | ||
config = Config("config", default=None) | ||
|
||
@card | ||
@step | ||
def start(self): | ||
self.next(self.end) | ||
|
||
@step | ||
def end(self): | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
Sample() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"id": 1084, | ||
"size": 400, | ||
"style": { | ||
"grayscale": true, | ||
"blur": 5 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from metaflow import FlowSpec, Runner, step | ||
|
||
|
||
class RunnerFlow(FlowSpec): | ||
@step | ||
def start(self): | ||
with Runner("./mutable_flow.py") as r: | ||
r.run() | ||
self.next(self.end) | ||
|
||
@step | ||
def end(self): | ||
print("Done") | ||
|
||
|
||
if __name__ == "__main__": | ||
RunnerFlow() |
File renamed without changes.