Skip to content

Commit

Permalink
[Workflows] Fix resolving source code target dir [1.7.x] (mlrun#6385)
Browse files Browse the repository at this point in the history
  • Loading branch information
alonmr authored Sep 23, 2024
1 parent 49930aa commit 1f9246f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
1 change: 1 addition & 0 deletions mlrun/common/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@
ProjectOwner,
ProjectsOutput,
ProjectSpec,
ProjectSpecOut,
ProjectState,
ProjectStatus,
ProjectSummariesOutput,
Expand Down
8 changes: 4 additions & 4 deletions server/api/api/endpoints/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def submit_workflow(
:returns: response that contains the project name, workflow name, name of the workflow,
status, run id (in case of a single run) and schedule (in case of scheduling)
"""
project = await run_in_threadpool(
project: mlrun.common.schemas.ProjectOut = await run_in_threadpool(
server.api.utils.singletons.project_member.get_project_member().get_project,
db_session=db_session,
name=project,
Expand Down Expand Up @@ -244,7 +244,7 @@ async def submit_workflow(
def _is_requested_schedule(
name: str,
workflow_spec: mlrun.common.schemas.WorkflowSpec,
project: mlrun.common.schemas.Project,
project: mlrun.common.schemas.ProjectOut,
) -> bool:
"""
Checks if the workflow needs to be scheduled, which can be decided either the request itself
Expand All @@ -264,7 +264,7 @@ def _is_requested_schedule(


def _get_workflow_by_name(
project: mlrun.common.schemas.Project, name: str
project: mlrun.common.schemas.ProjectOut, name: str
) -> typing.Optional[dict]:
"""
Getting workflow from project by name.
Expand All @@ -281,7 +281,7 @@ def _get_workflow_by_name(


def _fill_workflow_missing_fields_from_project(
project: mlrun.common.schemas.Project,
project: mlrun.common.schemas.ProjectOut,
workflow_name: str,
spec: mlrun.common.schemas.WorkflowSpec,
arguments: dict,
Expand Down
19 changes: 12 additions & 7 deletions server/api/crud/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def create_runner(
def schedule(
self,
runner: mlrun.run.KubejobRuntime,
project: mlrun.common.schemas.Project,
project: mlrun.common.schemas.ProjectOut,
workflow_request: mlrun.common.schemas.WorkflowRequest,
db_session: Session = None,
auth_info: mlrun.common.schemas.AuthInfo = None,
Expand Down Expand Up @@ -127,7 +127,7 @@ def schedule(

def _prepare_run_object_for_scheduling(
self,
project: mlrun.common.schemas.Project,
project: mlrun.common.schemas.ProjectOut,
workflow_request: mlrun.common.schemas.WorkflowRequest,
labels: dict[str, str],
) -> mlrun.run.RunObject:
Expand Down Expand Up @@ -200,7 +200,7 @@ def _prepare_run_object_for_scheduling(
def run(
self,
runner: mlrun.run.KubejobRuntime,
project: mlrun.common.schemas.Project,
project: mlrun.common.schemas.ProjectOut,
workflow_request: mlrun.common.schemas.WorkflowRequest = None,
load_only: bool = False,
auth_info: mlrun.common.schemas.AuthInfo = None,
Expand Down Expand Up @@ -306,7 +306,7 @@ def get_workflow_id(

def _prepare_run_object_for_single_run(
self,
project: mlrun.common.schemas.Project,
project: mlrun.common.schemas.ProjectOut,
labels: dict[str, str],
workflow_request: mlrun.common.schemas.WorkflowRequest = None,
run_name: str = None,
Expand Down Expand Up @@ -380,7 +380,7 @@ def _prepare_run_object_for_single_run(

@staticmethod
def _validate_source(
project: mlrun.common.schemas.Project, source: str, load_only: bool = False
project: mlrun.common.schemas.ProjectOut, source: str, load_only: bool = False
) -> tuple[str, bool, bool]:
"""
In case the user provided a source we want to load the project from the source
Expand Down Expand Up @@ -411,11 +411,16 @@ def _validate_source(
return source, save, True

if source.startswith("./") or source == ".":
build = project.spec.build
source_code_target_dir = (
build.get("source_code_target_dir") if build else ""
)

# When the source is relative, it is relative to the project's source_code_target_dir
# If the project's source_code_target_dir is not set, the source is relative to the cwd
if project.spec.build and project.spec.build.source_code_target_dir:
if source_code_target_dir:
source = os.path.normpath(
os.path.join(project.spec.build.source_code_target_dir, source)
os.path.join(source_code_target_dir, source)
)
return source, save, True

Expand Down
2 changes: 1 addition & 1 deletion server/api/utils/projects/follower.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def get_project(
leader_session: typing.Optional[str] = None,
from_leader: bool = False,
format_: mlrun.common.formatters.ProjectFormat = mlrun.common.formatters.ProjectFormat.full,
) -> mlrun.common.schemas.Project:
) -> mlrun.common.schemas.ProjectOutput:
# by default, get project will use mlrun db to get/list the project.
# from leader is relevant for cases where we want to get the project from the leader
if from_leader:
Expand Down
2 changes: 1 addition & 1 deletion server/api/utils/projects/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def get_project(
leader_session: typing.Optional[str] = None,
from_leader: bool = False,
format_: mlrun.common.formatters.ProjectFormat = mlrun.common.formatters.ProjectFormat.full,
) -> mlrun.common.schemas.Project:
) -> mlrun.common.schemas.ProjectOutput:
pass

@abc.abstractmethod
Expand Down
8 changes: 3 additions & 5 deletions tests/api/crud/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ def test_run_workflow_with_local_source(
source_code_target_dir: str,
source: str,
):
project = mlrun.common.schemas.Project(
project = mlrun.common.schemas.ProjectOut(
metadata=mlrun.common.schemas.ProjectMetadata(name="project-name"),
spec=mlrun.common.schemas.ProjectSpec(),
spec=mlrun.common.schemas.ProjectSpecOut(),
)
if source_code_target_dir:
project.spec.build = mlrun.common.schemas.common.ImageBuilder(
source_code_target_dir=source_code_target_dir
)
project.spec.build = {"source_code_target_dir": source_code_target_dir}

server.api.crud.Projects().create_project(db, project)

Expand Down
2 changes: 1 addition & 1 deletion tests/system/projects/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ def test_load_project_remotely_with_secrets_failed(self):
db.get_project(name)

def test_remote_workflow_source_on_image(self):
name = "source-project"
name = "pipe"
self.custom_project_names_to_delete.append(name)

project_dir = f"{projects_dir}/{name}"
Expand Down

0 comments on commit 1f9246f

Please sign in to comment.