Skip to content
New issue

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

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

Already on GitHub? # to your account

Refactor function parsing and enhance test validations. #83

Merged
merged 3 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ test:
check:
poetry run pre-commit run --all-files
mypy:
poetry run mypy . --config-file pyproject.toml
poetry run mypy ml_orchestrator --config-file pyproject.toml
2 changes: 2 additions & 0 deletions dummy_components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)

valid_classes_meta = [
dcomps.MetaComponentTest,
dcomps.ComponentTestB,
dcomps.ComponentTestA,
dcomps.ComponentTestC,
Expand All @@ -15,6 +16,7 @@
dcomps.ComponentTestD2,
]
valid_classes_meta_v2 = [
dv2comps.MetaComponentTest,
dv2comps.ComponentTestB,
dv2comps.ComponentTestA,
dv2comps.ComponentTestC,
Expand Down
5 changes: 0 additions & 5 deletions ml_orchestrator/comp_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import dataclasses
from typing import List

from ml_orchestrator.comp_protocol.comp_protocol import ComponentProtocol
from ml_orchestrator.comp_protocol.func_parser import FunctionParser
from ml_orchestrator.env_params import EnvironmentParams
from ml_orchestrator.meta_comp import MetaComponent, _MetaComponent
Expand Down Expand Up @@ -49,10 +48,6 @@ def create_kfp_str(self, component: _MetaComponent) -> str: # type: ignore
kfp_component_str = kfp_component_str.replace("\t", " ")
return kfp_component_str + "\n"

def parse_components_to_file(self, components: List[ComponentProtocol], filename: str) -> None:
kfp_str = self.create_kfp_file_str(components)
self.write_to_file(filename, kfp_str)

def write_to_file(self, filename: str, file_content: str) -> None:
for imp in self.add_imports:
file_content = f"{imp}\n{file_content}"
Expand Down
10 changes: 8 additions & 2 deletions ml_orchestrator/comp_protocol/func_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ def create_function(self, component: ComponentProtocol) -> str:
def get_function_parts(self, comp_class: Type[ComponentProtocol]) -> Tuple[str, str]:
component_variables = self.comp_vars(comp_class)
kfp_func_name = comp_class.__name__.lower()
func_scope = "(\n\t" + ",\n\t".join(self.get_func_params(component_variables)) + ",\n)"
comp_scope = "(\n\t\t" + ",\n\t\t".join(self.get_comp_params(component_variables)) + ",\n\t)"
func_params = self.get_func_params(component_variables)
comp_params = self.get_comp_params(component_variables)
func_scope = "(\n\t" + ",\n\t".join(func_params) + (",\n)" if func_params else ")")
comp_scope = "(\n\t\t" + ",\n\t\t".join(comp_params) + (",\n\t)" if comp_params else ")")
return_type = ""
if self.exe_return(comp_class) is not None:
return_type = f" -> {self.exe_return(comp_class).__name__}"
Expand Down Expand Up @@ -107,6 +109,10 @@ def create_kfp_file_str(
file_content = f"{IMPORT_COMPOUND}\n\n\n{kfp_str}"
return file_content

def parse_components_to_file(self, components: List[ComponentProtocol], filename: str) -> None:
kfp_str = self.create_kfp_file_str(components)
self.write_to_file(filename, kfp_str)

def write_to_file(self, filename: str, file_content: str) -> None:
file_content = f"# flake8: noqa: F403, F405, B006\n{file_content}"
with open(filename, "w", encoding="utf-8") as f:
Expand Down
8 changes: 6 additions & 2 deletions ml_orchestrator/comp_protocol/t_suites.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ def test_flows_protocol(self, comp_fixture: ComponentProtocol) -> None:
def test_comp_protocol_attrs(self, comp_fixture: ComponentProtocol) -> None:
fp = FunctionParser()
comp_vars = fp.comp_vars(comp_fixture) # type: ignore
assert comp_vars
assert fp.get_func_params(comp_vars)
num_init_params = len(comp_fixture.__init__.__code__.co_varnames) - 1 # type: ignore
func_params = fp.get_func_params(comp_vars)

assert comp_vars if num_init_params > 0 else not comp_vars
assert len(comp_vars) == num_init_params
assert len(func_params) == num_init_params

def test_comp_protocol_e2e(self, comp_fixture: ComponentProtocol) -> None:
fp = FunctionParser()
Expand Down
5 changes: 0 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,3 @@ check_untyped_defs = true
warn_redundant_casts = true
warn_unused_ignores = true
strict_optional = false


[[tool.mypy.overrides]]
module = "tests.*"
ignore_errors = true
Loading