Skip to content

Commit 945e27a

Browse files
feat(core): use current renku version when setting template for old projects (#3162)
1 parent cc7f90b commit 945e27a

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

renku/core/util/metadata.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,11 @@ def is_external_file(path: Union[Path, str], project_path: Path):
103103
return str(os.path.join(RENKU_HOME, POINTERS)) in pointer
104104

105105

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

110-
return read_renku_version_from_dockerfile(project_context.docker_path)
111-
112-
113-
def read_renku_version_from_dockerfile(path: Union[Path, str]) -> Optional[str]:
114-
"""Read RENKU_VERSION from the content of path if a valid version is available."""
115-
path = Path(path)
110+
path = Path(path) if path else project_context.docker_path
116111
if not path.exists():
117112
return None
118113

renku/domain_model/template.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ def from_dict(cls, metadata: Dict[str, Any]) -> "TemplateMetadata":
508508
@classmethod
509509
def from_project(cls, project: Optional["Project"]) -> "TemplateMetadata":
510510
"""Return an instance from reading template-related metadata from a project."""
511-
from renku.core.util.metadata import get_renku_version
511+
from renku.core.util.metadata import read_renku_version_from_dockerfile
512+
from renku.version import __version__
512513

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

533534
return cls(metadata=metadata, immutable_files=immutable_files)
534535

tests/cli/test_integration_datasets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,10 +1447,10 @@ def get_remote_file():
14471447
os.environ["GIT_LFS_SKIP_SMUDGE"] = "1"
14481448
Repository.clone_from(url=url, path=repo_path, recursive=True)
14491449

1450-
with chdir(repo_path):
1451-
runner.invoke(cli, ["migrate", "--strict"])
1452-
14531450
with project_context.with_path(repo_path):
1451+
with chdir(repo_path):
1452+
runner.invoke(cli, ["migrate", "--strict"])
1453+
14541454
dataset = get_dataset_with_injection("testing-create-04")
14551455
return dataset.find_file("data/testing-create-04/ie_data_with_TRCAPE.xls")
14561456

tests/cli/test_template.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,26 @@ def test_template_set_preserve_renku_version(runner, project):
197197
assert "ARG RENKU_VERSION=0.0.42" in content
198198

199199

200+
@pytest.mark.integration
201+
def test_template_set_uses_renku_version_when_non_existing(tmpdir, runner):
202+
"""Test setting a template on a project with no RENKU_VERSION in its Dockerfile, uses Renku CLI version instead."""
203+
from renku.domain_model.project_context import project_context
204+
from renku.version import __version__
205+
206+
url = "https://dev.renku.ch/gitlab/renku-testing/project-9.git"
207+
repo_path = tmpdir.mkdir("repo")
208+
Repository.clone_from(url=url, path=repo_path, env={"GIT_LFS_SKIP_SMUDGE": "1"})
209+
210+
with project_context.with_path(path=repo_path), chdir(repo_path):
211+
assert 0 == runner.invoke(cli, ["migrate", "--strict"]).exit_code
212+
213+
assert "RENKU_VERSION" not in project_context.docker_path.read_text()
214+
215+
assert 0 == runner.invoke(cli, ["template", "set", "python-minimal"]).exit_code
216+
217+
assert f"RENKU_VERSION={__version__}" in project_context.docker_path.read_text()
218+
219+
200220
def test_template_set_dry_run(runner, project):
201221
"""Test set dry-run doesn't make any changes."""
202222
commit_sha_before = project.repository.head.commit.hexsha
File renamed without changes.

0 commit comments

Comments
 (0)