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

feat(core): use current renku version when setting template for old projects #3162

Merged
merged 1 commit into from
Oct 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 3 additions & 8 deletions renku/core/util/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,11 @@ def is_external_file(path: Union[Path, str], project_path: Path):
return str(os.path.join(RENKU_HOME, POINTERS)) in pointer


def get_renku_version() -> Optional[str]:
"""Return project's Renku version from its Dockerfile."""
def read_renku_version_from_dockerfile(path: Optional[Union[Path, str]] = None) -> Optional[str]:
"""Read RENKU_VERSION from the content of path if a valid version is available."""
from renku.domain_model.project_context import project_context

return read_renku_version_from_dockerfile(project_context.docker_path)


def read_renku_version_from_dockerfile(path: Union[Path, str]) -> Optional[str]:
"""Read RENKU_VERSION from the content of path if a valid version is available."""
path = Path(path)
path = Path(path) if path else project_context.docker_path
if not path.exists():
return None

Expand Down
5 changes: 3 additions & 2 deletions renku/domain_model/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ def from_dict(cls, metadata: Dict[str, Any]) -> "TemplateMetadata":
@classmethod
def from_project(cls, project: Optional["Project"]) -> "TemplateMetadata":
"""Return an instance from reading template-related metadata from a project."""
from renku.core.util.metadata import get_renku_version
from renku.core.util.metadata import read_renku_version_from_dockerfile
from renku.version import __version__

if not project:
metadata = {}
Expand All @@ -528,7 +529,7 @@ def from_project(cls, project: Optional["Project"]) -> "TemplateMetadata":
# NOTE: Always set __renku_version__ to the value read from the Dockerfile (if available) since setting/updating
# the template doesn't change project's metadata version and shouldn't update the Renku version either
renku_version = metadata.get("__renku_version__")
metadata["__renku_version__"] = get_renku_version() or renku_version or ""
metadata["__renku_version__"] = read_renku_version_from_dockerfile() or renku_version or __version__

return cls(metadata=metadata, immutable_files=immutable_files)

Expand Down
6 changes: 3 additions & 3 deletions tests/cli/test_integration_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,10 +1447,10 @@ def get_remote_file():
os.environ["GIT_LFS_SKIP_SMUDGE"] = "1"
Repository.clone_from(url=url, path=repo_path, recursive=True)

with chdir(repo_path):
runner.invoke(cli, ["migrate", "--strict"])

with project_context.with_path(repo_path):
with chdir(repo_path):
runner.invoke(cli, ["migrate", "--strict"])

dataset = get_dataset_with_injection("testing-create-04")
return dataset.find_file("data/testing-create-04/ie_data_with_TRCAPE.xls")

Expand Down
20 changes: 20 additions & 0 deletions tests/cli/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,26 @@ def test_template_set_preserve_renku_version(runner, project):
assert "ARG RENKU_VERSION=0.0.42" in content


@pytest.mark.integration
def test_template_set_uses_renku_version_when_non_existing(tmpdir, runner):
"""Test setting a template on a project with no RENKU_VERSION in its Dockerfile, uses Renku CLI version instead."""
from renku.domain_model.project_context import project_context
from renku.version import __version__

url = "https://dev.renku.ch/gitlab/renku-testing/project-9.git"
repo_path = tmpdir.mkdir("repo")
Repository.clone_from(url=url, path=repo_path, env={"GIT_LFS_SKIP_SMUDGE": "1"})

with project_context.with_path(path=repo_path), chdir(repo_path):
assert 0 == runner.invoke(cli, ["migrate", "--strict"]).exit_code

assert "RENKU_VERSION" not in project_context.docker_path.read_text()

assert 0 == runner.invoke(cli, ["template", "set", "python-minimal"]).exit_code

assert f"RENKU_VERSION={__version__}" in project_context.docker_path.read_text()


def test_template_set_dry_run(runner, project):
"""Test set dry-run doesn't make any changes."""
commit_sha_before = project.repository.head.commit.hexsha
Expand Down
File renamed without changes.