-
Notifications
You must be signed in to change notification settings - Fork 26
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
Create local artifact directory if it does not exist #847
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,6 +1,7 @@ | ||||
import datetime | ||||
import json | ||||
import os | ||||
import re | ||||
import subprocess | ||||
import sys | ||||
import tempfile | ||||
|
@@ -168,6 +169,7 @@ def test_docker_compiler(setup_pipeline, tmp_path_factory): | |||
example_dir, pipeline, _ = setup_pipeline | ||||
compiler = DockerCompiler() | ||||
with tmp_path_factory.mktemp("temp") as fn: | ||||
pipeline.base_path = str(fn) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a big fan of this. Can we turn the fixture into a factory function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's fine for you I would exclude it here and keep the test as it is. I'll create an separat issue for this. I took a look into the test and I think it would result in a bigger refactoring. It would make indeed sense to have a pipeline factory cause it is needed in several test cases. Not only here in this file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have code like this that we could reuse more. eg: fondant/tests/pipeline/test_compiler.py Line 132 in 7ec04dc
This is one is even parameterized so you can easily run the same test on multiple pipelines. |
||||
output_path = str(fn / "docker-compose.yml") | ||||
compiler.compile(pipeline=pipeline, output_path=output_path, build_args=[]) | ||||
pipeline_configs = DockerComposeConfigs.from_spec(output_path) | ||||
|
@@ -336,6 +338,7 @@ def test_docker_configuration(tmp_path_factory): | |||
|
||||
compiler = DockerCompiler() | ||||
with tmp_path_factory.mktemp("temp") as fn: | ||||
pipeline.base_path = str(fn) | ||||
output_path = str(fn / "docker-compose.yaml") | ||||
compiler.compile(pipeline=pipeline, output_path=output_path) | ||||
pipeline_configs = DockerComposeConfigs.from_spec(output_path) | ||||
|
@@ -363,7 +366,10 @@ def test_invalid_docker_configuration(tmp_path_factory): | |||
) | ||||
|
||||
compiler = DockerCompiler() | ||||
with pytest.raises(InvalidPipelineDefinition): | ||||
with tmp_path_factory.mktemp("temp") as fn, pytest.raises( # noqa PT012 | ||||
InvalidPipelineDefinition, | ||||
): | ||||
pipeline.base_path = str(fn) | ||||
compiler.compile(pipeline=pipeline, output_path="kubeflow_pipeline.yml") | ||||
|
||||
|
||||
|
@@ -663,6 +669,7 @@ def test_caching_dependency_docker(tmp_path_factory): | |||
) | ||||
|
||||
with tmp_path_factory.mktemp("temp") as fn: | ||||
pipeline.base_path = str(fn) | ||||
output_path = str(fn / "docker-compose.yml") | ||||
compiler.compile(pipeline=pipeline, output_path=output_path, build_args=[]) | ||||
pipeline_configs = DockerComposeConfigs.from_spec(output_path) | ||||
|
@@ -844,3 +851,36 @@ def test_sagemaker_base_path_validator(): | |||
|
||||
# valid | ||||
compiler.validate_base_path("s3://foo/bar") | ||||
|
||||
|
||||
@pytest.mark.usefixtures("_freeze_time") | ||||
def test_docker_compiler_create_local_base_path(setup_pipeline, tmp_path_factory): | ||||
"""Test compiling a pipeline to docker-compose.""" | ||||
example_dir, pipeline, _ = setup_pipeline | ||||
compiler = DockerCompiler() | ||||
with tmp_path_factory.mktemp("temp") as fn: | ||||
pipeline.base_path = str(fn) + "/my-artifacts" | ||||
output_path = str(fn / "docker-compose.yml") | ||||
compiler.compile(pipeline=pipeline, output_path=output_path, build_args=[]) | ||||
assert Path(pipeline.base_path).exists() | ||||
|
||||
|
||||
@pytest.mark.usefixtures("_freeze_time") | ||||
def test_docker_compiler_create_local_base_path_propagate_exception( | ||||
setup_pipeline, | ||||
tmp_path_factory, | ||||
): | ||||
"""Test compiling a pipeline to docker-compose.""" | ||||
example_dir, pipeline, _ = setup_pipeline | ||||
compiler = DockerCompiler() | ||||
msg = re.escape( | ||||
"Unable to create and mount local base path. ", | ||||
) | ||||
|
||||
with tmp_path_factory.mktemp("temp") as fn, pytest.raises( # noqa PT012 | ||||
ValueError, | ||||
match=msg, | ||||
): | ||||
pipeline.base_path = "/my-artifacts" | ||||
output_path = str(fn / "docker-compose.yml") | ||||
compiler.compile(pipeline=pipeline, output_path=output_path, build_args=[]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -270,7 +270,7 @@ def test_local_run(mock_docker_installation): | |
"""Test that the run command works with different arguments.""" | ||
args = argparse.Namespace( | ||
local=True, | ||
ref="some/path", | ||
ref=__name__, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand completely why the tests have worked before. The actual module contains a test pipeline which is used as reference for the test cases. |
||
output_path=None, | ||
auth_provider=None, | ||
credentials=None, | ||
|
@@ -284,7 +284,7 @@ def test_local_run(mock_docker_installation): | |
"docker", | ||
"compose", | ||
"-f", | ||
"some/path", | ||
".fondant/compose.yaml", | ||
"up", | ||
"--build", | ||
"--pull", | ||
|
@@ -372,7 +372,7 @@ def test_kfp_run(tmp_path_factory): | |
local=False, | ||
vertex=False, | ||
output_path=None, | ||
ref="some/path", | ||
ref=__name__, | ||
host=None, | ||
) | ||
with pytest.raises( | ||
|
@@ -386,7 +386,7 @@ def test_kfp_run(tmp_path_factory): | |
local=False, | ||
output_path=None, | ||
host="localhost", | ||
ref="some/path", | ||
ref=__name__, | ||
) | ||
run_kfp(args) | ||
mock_runner.assert_called_once_with(host="localhost") | ||
|
@@ -419,7 +419,7 @@ def test_vertex_run(tmp_path_factory): | |
project_id="project-123", | ||
service_account=None, | ||
network=None, | ||
ref="some/path", | ||
ref=__name__, | ||
) | ||
run_vertex(args) | ||
mock_runner.assert_called_once_with( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be easier to swap this check and check if it's local instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. The remote prefixes are well defined by the
known_implementations
. The local paths can be more complex (start with prefix, without prefix, absolute path, relative path, ...). Thought a check for a remote path is easier.