From ac41ccfaa56d8d7169b05a1920eeeab2f1e6934f Mon Sep 17 00:00:00 2001 From: Andrii Khomiak Date: Tue, 18 Apr 2023 17:24:57 +0300 Subject: [PATCH 1/2] feat: Infer project id from current project if it is unset --- src/neuro_flow/ast.py | 3 +-- src/neuro_flow/context.py | 11 ++++++++++- src/neuro_flow/parser.py | 2 +- tests/unit/test_project_parser.py | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/neuro_flow/ast.py b/src/neuro_flow/ast.py index 716a2d91..1dc6319b 100644 --- a/src/neuro_flow/ast.py +++ b/src/neuro_flow/ast.py @@ -19,7 +19,6 @@ PrimitiveExpr, RemotePathExpr, SequenceT, - SimpleIdExpr, SimpleOptBoolExpr, SimpleOptIdExpr, SimpleOptPrimitiveExpr, @@ -59,7 +58,7 @@ class Cache(Base): @dataclass(frozen=True) class Project(Base): - id: SimpleIdExpr + id: SimpleOptIdExpr # inferred current project from neuro-sdk if not set owner: SimpleOptStrExpr # user name can contain "-" role: SimpleOptStrExpr diff --git a/src/neuro_flow/context.py b/src/neuro_flow/context.py index 562b9d07..25d0779f 100644 --- a/src/neuro_flow/context.py +++ b/src/neuro_flow/context.py @@ -744,6 +744,16 @@ async def setup_project_ctx( ) -> ProjectCtx: ast_project = await config_loader.fetch_project() project_id = await ast_project.id.eval(ctx) + if project_id is None: + if config_loader.client.config.project_name is not None: + # load current-project from client + project_id = config_loader.client.config.project_name + else: + # TODO (A.K.): raise proper error type + raise ValueError( + "Could not infer project id - set it " + "in project.yaml or via 'neuro switch-project'." + ) project_owner = await ast_project.owner.eval(ctx) project_role = await ast_project.role.eval(ctx) if project_role is None and project_owner is not None: @@ -1566,7 +1576,6 @@ async def create( ) -> "RunningLiveFlow": ast_flow = await config_loader.fetch_flow(config_name) ast_project = await config_loader.fetch_project() - assert isinstance(ast_flow, ast.LiveFlow) project_ctx = await setup_project_ctx(EMPTY_ROOT, config_loader) diff --git a/src/neuro_flow/parser.py b/src/neuro_flow/parser.py index f198583e..74f89a77 100644 --- a/src/neuro_flow/parser.py +++ b/src/neuro_flow/parser.py @@ -1497,7 +1497,7 @@ def __init__(self, stream: TextIO) -> None: PROJECT = { - "id": SimpleIdExpr, + "id": SimpleOptIdExpr, "owner": SimpleOptStrExpr, "role": SimpleOptStrExpr, "images": None, diff --git a/tests/unit/test_project_parser.py b/tests/unit/test_project_parser.py index a4fe7e13..b5f5c1f5 100644 --- a/tests/unit/test_project_parser.py +++ b/tests/unit/test_project_parser.py @@ -13,7 +13,7 @@ OptTimeDeltaExpr, RemotePathExpr, SequenceItemsExpr, - SimpleIdExpr, + SimpleOptIdExpr, SimpleOptStrExpr, StrExpr, URIExpr, @@ -29,7 +29,7 @@ def test_parse_full(assets: pathlib.Path) -> None: assert project == ast.Project( Pos(0, 0, config_file), Pos(58, 0, config_file), - id=SimpleIdExpr( + id=SimpleOptIdExpr( Pos(0, 0, config_file), Pos(0, 0, config_file), "test_project", From 61d3a6176838bec5cc83509f75c411d35f75de38 Mon Sep 17 00:00:00 2001 From: Andrii Khomiak Date: Thu, 20 Apr 2023 18:43:29 +0300 Subject: [PATCH 2/2] feat: Pass project to run commands in libe and batch runners --- src/neuro_flow/batch_runner.py | 1 + src/neuro_flow/live_runner.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/neuro_flow/batch_runner.py b/src/neuro_flow/batch_runner.py index a99bff38..28db416f 100644 --- a/src/neuro_flow/batch_runner.py +++ b/src/neuro_flow/batch_runner.py @@ -486,6 +486,7 @@ async def _run_bake( f"--tag=flow:{bake.batch}", f"--tag=bake_id:{bake.id}", f"--tag=remote_executor", + f"--project={self.project_id}", ] project_role = self.project_role if project_role is not None: diff --git a/src/neuro_flow/live_runner.py b/src/neuro_flow/live_runner.py index 2e3e4688..a7918f48 100644 --- a/src/neuro_flow/live_runner.py +++ b/src/neuro_flow/live_runner.py @@ -400,6 +400,7 @@ async def run( while "--" in name: name = name.replace("--", "-") run_args.append(f"--name={name}") + run_args.append(f"--project={self._flow.project.id}") if job.preset is not None: run_args.append(f"--preset={job.preset}") if job.schedule_timeout is not None: