Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial runner api #1732

Merged
merged 55 commits into from
May 23, 2024
Merged
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
90e1aea
initial runner map api
madhur-ob Feb 15, 2024
a8cd6ab
return Run objects
madhur-ob Feb 21, 2024
89cb6eb
WIP: click to method mapping
madhur-ob Mar 2, 2024
723e835
WIP: click to method, adding groups
madhur-ob Mar 2, 2024
1d429de
remove comment
madhur-ob Mar 2, 2024
ef279d1
pass in args and opts correctly
madhur-ob Mar 2, 2024
682f6a0
fix validation for top level params
madhur-ob Mar 2, 2024
37ba90d
restore metaflow_runner.py
madhur-ob Mar 2, 2024
d6fe8ac
handle list in options
madhur-ob Mar 3, 2024
37bb394
fix nargs
madhur-ob Mar 3, 2024
5c255ef
fix issue with validating missing args
madhur-ob Mar 3, 2024
d47cd75
inject flow parameters as well
madhur-ob Mar 3, 2024
7812e58
handle include file
madhur-ob Mar 3, 2024
f958c68
internal click to chaining methods functionality
madhur-ob Mar 4, 2024
86968e6
subprocess manager
madhur-ob Mar 12, 2024
1c3c5bd
simpler subprocess manager
madhur-ob Mar 28, 2024
61623cd
handle SIGINT
madhur-ob Mar 28, 2024
216c366
wait() handles timeout + logs both
madhur-ob Mar 28, 2024
847822d
improved log streaming with ability to resume + stream multiple times
madhur-ob Apr 9, 2024
be5512e
cleanup in context manager, otherwise user is responsible
madhur-ob Apr 9, 2024
4158db0
remove aiofiles
madhur-ob Apr 9, 2024
b7d1083
split into CommandManager and SubprocessManager
madhur-ob Apr 9, 2024
bf04383
return components array instead
madhur-ob Apr 9, 2024
efa8750
remove assert
madhur-ob Apr 9, 2024
cc6d602
add type hints
madhur-ob Apr 9, 2024
9766d0f
return ExecutingRun encapsulating CommandManager and metaflow.Run
madhur-ob Apr 9, 2024
080fbb2
print as string
madhur-ob Apr 16, 2024
8a5a14f
suggested improvements
madhur-ob Apr 16, 2024
04b8811
use correct variable name
madhur-ob Apr 16, 2024
0cfc979
update usage of subprocess manager
madhur-ob Apr 16, 2024
b8ed331
fix flags such as --pylint/--no-pylint
madhur-ob Apr 28, 2024
73935b1
cache loaded modules
madhur-ob Apr 28, 2024
d3f53aa
fix boolean flags
madhur-ob Apr 28, 2024
79aeb4e
remove aiofiles
madhur-ob Apr 28, 2024
b8a47ac
no f-strings
madhur-ob Apr 28, 2024
25f8ace
get run object explicitly
madhur-ob May 1, 2024
33c08c3
new higher level UX
madhur-ob May 2, 2024
bafd29b
typeguard warning for 3.5/3.6 + add profile argument
madhur-ob May 2, 2024
2128a22
default None for profile
madhur-ob May 2, 2024
95e7076
detect early issues
madhur-ob May 6, 2024
1f20019
fix user defined params not being recognised
madhur-ob May 6, 2024
6b67548
kill all descendants
madhur-ob May 6, 2024
a77ba01
do not use f-strings
madhur-ob May 6, 2024
5c8a9aa
suggested changes
madhur-ob May 13, 2024
9a43517
use pkill instead of psutil
madhur-ob May 13, 2024
93dcd5c
minor fix
madhur-ob May 15, 2024
fc0ee63
vendor typeguard
madhur-ob May 15, 2024
471c335
update error message
madhur-ob May 21, 2024
706c00c
remove comma and check in init
madhur-ob May 21, 2024
c387d84
Added docstrings; fixed stubs; moved stuff around
romain-intel May 23, 2024
737d2da
change dir name to runner
madhur-ob May 23, 2024
4363d8f
fix import in test
madhur-ob May 23, 2024
fc1d92e
fix import
madhur-ob May 23, 2024
790e270
add status property to ExecutingRun
madhur-ob May 23, 2024
d661bbc
add docstring for status property
madhur-ob May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add type hints
  • Loading branch information
madhur-ob committed May 21, 2024
commit cc6d602d25794f0df24319f165b9bde1221f025e
49 changes: 31 additions & 18 deletions metaflow/click_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
from collections import OrderedDict
from typeguard import check_type, TypeCheckError
import uuid, datetime
from typing import Optional, List
from typing import (
Optional,
List,
OrderedDict as TOrderedDict,
Any,
Union,
Dict,
Callable,
)
from metaflow import FlowSpec, Parameter
from metaflow.cli import start
from metaflow._vendor import click
from metaflow._vendor.click import Command, Group, Argument, Option
from metaflow.parameters import JSONTypeClass
from metaflow.includefile import FilePathClass
from metaflow._vendor.click.types import (
Expand Down Expand Up @@ -41,8 +48,12 @@


def _method_sanity_check(
possible_arg_params, possible_opt_params, annotations, defaults, **kwargs
):
possible_arg_params: TOrderedDict[str, click.Argument],
possible_opt_params: TOrderedDict[str, click.Option],
annotations: TOrderedDict[str, Any],
defaults: TOrderedDict[str, Any],
**kwargs
) -> Dict[str, Any]:
method_params = {"args": {}, "options": {}}

possible_params = OrderedDict()
Expand Down Expand Up @@ -85,7 +96,7 @@ def _method_sanity_check(
return method_params


def get_annotation(param):
def get_annotation(param: Union[click.Argument, click.Option]):
py_type = click_to_python_types[type(param.type)]
if not param.required:
if param.multiple or param.nargs == -1:
Expand All @@ -99,7 +110,7 @@ def get_annotation(param):
return py_type


def get_inspect_param_obj(p, kind):
def get_inspect_param_obj(p: Union[click.Argument, click.Option], kind: str):
return inspect.Parameter(
name=p.name,
kind=kind,
Expand All @@ -108,7 +119,7 @@ def get_inspect_param_obj(p, kind):
)


def extract_flowspec_params(flow_file):
def extract_flowspec_params(flow_file: str) -> List[Parameter]:
spec = importlib.util.spec_from_file_location("module", flow_file)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
Expand Down Expand Up @@ -140,16 +151,16 @@ def chain(self):
return self._chain

@classmethod
def from_cli(cls, flow_file, cli_collection):
def from_cli(cls, flow_file: str, cli_collection: Callable) -> Callable:
flow_parameters = extract_flowspec_params(flow_file)
class_dict = {"__module__": "metaflow", "_API_NAME": flow_file}
command_groups = cli_collection.sources
for each_group in command_groups:
for _, cmd_obj in each_group.commands.items():
if isinstance(cmd_obj, Group):
if isinstance(cmd_obj, click.Group):
# TODO: possibly check for fake groups with cmd_obj.name in ["cli", "main"]
class_dict[cmd_obj.name] = extract_group(cmd_obj, flow_parameters)
elif isinstance(cmd_obj, Command):
elif isinstance(cmd_obj, click.Command):
class_dict[cmd_obj.name] = extract_command(cmd_obj, flow_parameters)
else:
raise RuntimeError(
Expand Down Expand Up @@ -188,7 +199,7 @@ def _method(_self, **kwargs):

return m

def execute(self):
def execute(self) -> List[str]:
parents = []
current = self
while current.parent:
Expand Down Expand Up @@ -225,7 +236,7 @@ def execute(self):
return components


def extract_all_params(cmd_obj):
def extract_all_params(cmd_obj: Union[click.Command, click.Group]):
arg_params_sigs = OrderedDict()
opt_params_sigs = OrderedDict()
params_sigs = OrderedDict()
Expand All @@ -236,12 +247,12 @@ def extract_all_params(cmd_obj):
defaults = OrderedDict()

for each_param in cmd_obj.params:
if isinstance(each_param, Argument):
if isinstance(each_param, click.Argument):
arg_params_sigs[each_param.name] = get_inspect_param_obj(
each_param, inspect.Parameter.POSITIONAL_ONLY
)
arg_parameters[each_param.name] = each_param
elif isinstance(each_param, Option):
elif isinstance(each_param, click.Option):
opt_params_sigs[each_param.name] = get_inspect_param_obj(
each_param, inspect.Parameter.KEYWORD_ONLY
)
Expand All @@ -260,13 +271,13 @@ def extract_all_params(cmd_obj):
return params_sigs, arg_parameters, opt_parameters, annotations, defaults


def extract_group(cmd_obj, flow_parameters):
def extract_group(cmd_obj: click.Group, flow_parameters: List[Parameter]) -> Callable:
class_dict = {"__module__": "metaflow", "_API_NAME": cmd_obj.name}
for _, sub_cmd_obj in cmd_obj.commands.items():
if isinstance(sub_cmd_obj, Group):
if isinstance(sub_cmd_obj, click.Group):
# recursion
class_dict[sub_cmd_obj.name] = extract_group(sub_cmd_obj, flow_parameters)
elif isinstance(sub_cmd_obj, Command):
elif isinstance(sub_cmd_obj, click.Command):
class_dict[sub_cmd_obj.name] = extract_command(sub_cmd_obj, flow_parameters)
else:
raise RuntimeError(
Expand Down Expand Up @@ -302,7 +313,9 @@ def _method(_self, **kwargs):
return m


def extract_command(cmd_obj, flow_parameters):
def extract_command(
cmd_obj: click.Command, flow_parameters: List[Parameter]
) -> Callable:
if getattr(cmd_obj, "has_flow_params", False):
for p in flow_parameters[::-1]:
cmd_obj.params.insert(0, click.Option(("--" + p.name,), **p.kwargs))
Expand Down