Skip to content

Commit 9251d7b

Browse files
committed
Add support for overriding parameters at command line
1 parent d744201 commit 9251d7b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

boston_housing/mlcube/mlcube_cli.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ def load_config(mlcube_config_path: str, user_config_path: str) -> typing.Dict:
3333
return mlcube_config_data
3434

3535

36+
def override_extra_parameters(ctx, mlcube_config_data, task):
37+
"""Get extra paramters from context and override them on mlcube config data dict"""
38+
for input_param in ctx.args:
39+
input_key, input_value = input_param.split("=")
40+
input_key = input_key.replace("--", "")
41+
# Replace main container parameters
42+
for key in mlcube_config_data["container"]:
43+
if key==input_key:
44+
mlcube_config_data["container"][key]=input_value
45+
# Replace io paths in current task
46+
for io in mlcube_config_data["tasks"][task]["io"]:
47+
if io["name"]==input_key:
48+
io["default"]=input_value
49+
50+
3651
@click.group(name='mlcube')
3752
def cli():
3853
pass
@@ -45,7 +60,8 @@ def cli():
4560
@click.option('--task', required=False, type=str, help='MLCube task name to run, default is `main`.')
4661
@click.option('--workspace', required=False, type=str, help='Workspace path, default is `workspace` within '
4762
'MLCube folder')
48-
def run(mlcube: str, platform: str, task: str, workspace: str):
63+
@click.pass_context
64+
def run(ctx, mlcube: str, platform: str, task: str, workspace: str):
4965
mlcube_root = os.path.abspath(mlcube or os.getcwd())
5066
if os.path.isfile(mlcube_root):
5167
mlcube_root = os.path.dirname(mlcube_root)
@@ -61,7 +77,7 @@ def run(mlcube: str, platform: str, task: str, workspace: str):
6177
os.path.join(str(mlcube_root), 'mlcube.yaml'),
6278
os.path.join(os.path.expanduser("~"), '.mlcube.yaml')
6379
)
64-
80+
override_extra_parameters(ctx, mlcube_config_data, task)
6581
docker_runner = DockerRun(mlcube_config_data, root=mlcube_root, workspace=workspace, task=task)
6682
docker_runner.run()
6783

0 commit comments

Comments
 (0)