Skip to content

Commit c24ff2f

Browse files
committed
use higher level API
1 parent 0defaa8 commit c24ff2f

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

metaflow/metaflow_runner.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def __init__(
105105
from metaflow.click_api import MetaflowAPI
106106

107107
self.flow_file = flow_file
108-
self.env_vars = os.environ.copy().update(env)
108+
self.env_vars = os.environ.copy()
109+
self.env_vars.update(env)
109110
if profile:
110111
self.env_vars["METAFLOW_PROFILE"] = profile
111112
self.spm = SubprocessManager()

test/core/run_tests.py

+15-21
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from metaflow.cli import start, run
1313
from metaflow._vendor import click
14+
from metaflow import Runner
1415

1516
skip_api_executor = False
1617

@@ -23,18 +24,6 @@
2324
except RuntimeError:
2425
skip_api_executor = True
2526

26-
skip_api_executor = False
27-
28-
try:
29-
from metaflow.click_api import (
30-
MetaflowAPI,
31-
extract_all_params,
32-
click_to_python_types,
33-
)
34-
from metaflow.cli import start, run
35-
except RuntimeError:
36-
skip_api_executor = True
37-
3827
from metaflow_test import MetaflowTest
3928
from metaflow_test.formatter import FlowFormatter
4029

@@ -135,8 +124,7 @@ def construct_arg_dict(params_opts, cli_options):
135124

136125
return result_dict
137126

138-
def construct_cmd_from_click_api(mode):
139-
api = MetaflowAPI.from_cli("test_flow.py", start)
127+
def construct_arg_dicts_from_click_api():
140128
_, _, param_opts, _, _ = extract_all_params(start)
141129
top_level_options = context["top_options"]
142130
top_level_dict = construct_arg_dict(param_opts, top_level_options)
@@ -146,10 +134,7 @@ def construct_cmd_from_click_api(mode):
146134
run_level_dict = construct_arg_dict(param_opts, run_level_options)
147135
run_level_dict["run_id_file"] = "run-id"
148136

149-
cmd = getattr(api(**top_level_dict), mode)(**run_level_dict)
150-
command = [context["python"], "-B"]
151-
command.extend(cmd)
152-
return command
137+
return top_level_dict, run_level_dict
153138

154139
cwd = os.getcwd()
155140
tempdir = tempfile.mkdtemp("_metaflow_test")
@@ -208,7 +193,11 @@ def construct_cmd_from_click_api(mode):
208193
if executor == "cli":
209194
flow_ret = subprocess.call(run_cmd("run"), env=env)
210195
elif executor == "api":
211-
flow_ret = subprocess.call(construct_cmd_from_click_api("run"), env=env)
196+
top_level_dict, run_level_dict = construct_arg_dicts_from_click_api()
197+
result = Runner("test_flow.py", env=env, **top_level_dict).run(
198+
**run_level_dict
199+
)
200+
flow_ret = result.command_obj.process.returncode
212201

213202
if flow_ret:
214203
if formatter.should_fail:
@@ -218,9 +207,14 @@ def construct_cmd_from_click_api(mode):
218207
if executor == "cli":
219208
flow_ret = subprocess.call(run_cmd("resume"), env=env)
220209
elif executor == "api":
221-
flow_ret = subprocess.call(
222-
construct_cmd_from_click_api("resume"), env=env
210+
(
211+
top_level_dict,
212+
resume_level_dict,
213+
) = construct_arg_dicts_from_click_api()
214+
result = Runner("test_flow.py", env=env, **top_level_dict).resume(
215+
**resume_level_dict
223216
)
217+
flow_ret = result.command_obj.process.returncode
224218
else:
225219
log("flow failed", formatter, context)
226220
return flow_ret, path

0 commit comments

Comments
 (0)