Skip to content

Commit

Permalink
update templates
Browse files Browse the repository at this point in the history
  • Loading branch information
m-alisafaee committed Jan 26, 2023
1 parent 3adfa69 commit c4cd1dc
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 52 deletions.
24 changes: 12 additions & 12 deletions renku/ui/cli/init.py
Expand Up @@ -69,9 +69,9 @@
... OK
INDEX ID DESCRIPTION PARAMETERS
----- -------------- -------------------------- ----------------------
1 python-minimal Basic Python Project:[...] description: proj[...]
2 R-minimal Basic R Project: The [...] description: proj[...]
----- ------ -------------------------- ----------------------
1 python Basic Python Project:[...] description: proj[...]
2 R Basic R Project: The [...] description: proj[...]
Please choose a template by typing the index:
Expand All @@ -86,7 +86,7 @@
.. code-block:: console
$ renku init --template-id python-minimal --parameter \
$ renku init --template-id python --parameter \
"description"="my new shiny project"
Initializing new Renku repository... OK
Expand All @@ -113,7 +113,7 @@
"@type": "https://schema.org/Organization", \
"https://schema.org/legalName": "ETHZ"}' > metadata.json
$ renku init --template-id python-minimal --parameter \
$ renku init --template-id python --parameter \
"description"="my new shiny project" --metadata metadata.json
Initializing new Renku repository... OK
Expand All @@ -136,13 +136,13 @@
$ echo "FROM python:3.7-alpine" > Dockerfile
$ renku init
INDEX ID PARAMETERS
------- -------------- ------------
1 python-minimal description
2 R-minimal description
3 bioc-minimal description
4 julia-minimal description
5 minimal
INDEX ID PARAMETERS
------- --------- ------------
1 python description
2 R description
3 bioc description
4 julia description
5 minimal
Please choose a template by typing the index: 1
The template requires a value for "description": Test Project
Initializing Git repository...
Expand Down
2 changes: 1 addition & 1 deletion renku/version.py
Expand Up @@ -25,7 +25,7 @@
from importlib_metadata import distribution, version # type: ignore

__version__ = version("renku")
__template_version__ = "0.3.5"
__template_version__ = "0.4.1"
__minimum_project_version__ = "1.7.0"


Expand Down
4 changes: 2 additions & 2 deletions tests/cli/test_init.py
Expand Up @@ -67,8 +67,8 @@ def test_template_selection_helpers(isolated_runner):

assert "Please choose a template by typing its index:" in stripped_output

assert "1 python-minimal" in stripped_output
assert "2 R-minimal" in stripped_output
assert "1 python" in stripped_output
assert "2 R" in stripped_output


def test_init(isolated_runner, project_init):
Expand Down
43 changes: 20 additions & 23 deletions tests/cli/test_template.py
Expand Up @@ -46,7 +46,7 @@ def test_template_list(isolated_runner):
result = isolated_runner.invoke(cli, command, replace_argv=False)

assert 0 == result.exit_code, format_result_exception(result)
assert "python-minimal" in result.output
assert "python" in result.output
finally:
sys.argv = argv

Expand All @@ -62,14 +62,14 @@ def test_template_list_from_source(isolated_runner):
result = isolated_runner.invoke(cli, command + ["--source", TEMPLATES_URL])

assert 0 == result.exit_code, format_result_exception(result)
assert "python-minimal" in result.output
assert "julia-minimal" in result.output
assert "python" in result.output
assert "julia" in result.output

result = isolated_runner.invoke(cli, command + ["-s", TEMPLATES_URL, "--reference", "0.3.2"])

assert 0 == result.exit_code, format_result_exception(result)
assert "python-minimal" in result.output
assert "julia-minimal" in result.output
assert "python" in result.output
assert "julia" in result.output
finally:
sys.argv = argv

Expand All @@ -81,7 +81,7 @@ def test_template_show(isolated_runner):
sys.argv = command

try:
result = isolated_runner.invoke(cli, command + ["R-minimal"])
result = isolated_runner.invoke(cli, command + ["R"])

assert 0 == result.exit_code, format_result_exception(result)
assert re.search("^Name: Basic R (.*) Project$", result.output, re.MULTILINE) is not None
Expand Down Expand Up @@ -135,18 +135,18 @@ def test_template_set_failure(runner, project, with_injection):
assert 1 == result.exit_code, format_result_exception(result)
assert "Project already has a template" in result.output
with with_injection():
assert "python-minimal" == project_context.project.template_metadata.template_id
assert "python" == project_context.project.template_metadata.template_id


def test_template_set(runner, project, with_injection):
"""Test setting a new template in a project."""
from renku.version import __template_version__

result = runner.invoke(cli, ["template", "set", "--force", "R-minimal"])
result = runner.invoke(cli, ["template", "set", "--force", "R"])

assert 0 == result.exit_code, format_result_exception(result)
with with_injection():
assert "R-minimal" == project_context.project.template_metadata.template_id
assert "R" == project_context.project.template_metadata.template_id
assert __template_version__ == project_context.project.template_metadata.template_version
assert __template_version__ == project_context.project.template_metadata.template_ref

Expand All @@ -158,11 +158,11 @@ def test_template_set_overwrites_modified(runner, project, with_injection):
"""Test setting a new template in a project overwrite modified files."""
write_and_commit_file(project.repository, "Dockerfile", "my-modifications")

result = runner.invoke(cli, ["template", "set", "--force", "R-minimal"])
result = runner.invoke(cli, ["template", "set", "--force", "R"])

assert 0 == result.exit_code, format_result_exception(result)
with with_injection():
assert "R-minimal" == project_context.project.template_metadata.template_id
assert "R" == project_context.project.template_metadata.template_id
assert "my-modifications" not in (project.path / "Dockerfile").read_text()
assert not project.repository.is_dirty(untracked_files=True)

Expand All @@ -172,11 +172,11 @@ def test_template_set_interactive(runner, project, with_injection, overwrite, fo
"""Test setting a template in interactive mode."""
write_and_commit_file(project.repository, "Dockerfile", "my-modifications")

result = runner.invoke(cli, ["template", "set", "-f", "R-minimal", "-i"], input=f"{overwrite}\n" * 420)
result = runner.invoke(cli, ["template", "set", "-f", "R", "-i"], input=f"{overwrite}\n" * 420)

assert 0 == result.exit_code, format_result_exception(result)
with with_injection():
assert "R-minimal" == project_context.project.template_metadata.template_id
assert "R" == project_context.project.template_metadata.template_id
assert ("my-modifications" in (project.path / "Dockerfile").read_text()) is found
assert not project.repository.is_dirty(untracked_files=True)

Expand All @@ -187,7 +187,7 @@ def test_template_set_preserve_renku_version(runner, project):
new_content = re.sub(r"^\s*ARG RENKU_VERSION=(.+)$", "ARG RENKU_VERSION=0.0.42", content, flags=re.MULTILINE)
write_and_commit_file(project.repository, "Dockerfile", new_content)

result = runner.invoke(cli, ["template", "set", "-f", "R-minimal", "--interactive"], input="y\n" * 420)
result = runner.invoke(cli, ["template", "set", "-f", "R", "--interactive"], input="y\n" * 420)

assert 0 == result.exit_code, format_result_exception(result)

Expand All @@ -212,7 +212,7 @@ def test_template_set_uses_renku_version_when_non_existing(tmpdir, runner):

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

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

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

Expand All @@ -221,7 +221,7 @@ 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

result = runner.invoke(cli, ["template", "set", "-f", "R-minimal", "--dry-run"])
result = runner.invoke(cli, ["template", "set", "-f", "R", "--dry-run"])

assert 0 == result.exit_code, format_result_exception(result)
assert not project.repository.is_dirty()
Expand All @@ -232,14 +232,12 @@ def test_template_set_dry_run(runner, project):
def test_template_update(runner, project, with_injection):
"""Test updating a template."""
result = runner.invoke(
cli,
["template", "set", "-f", "python-minimal", "-s", TEMPLATES_URL, "-r", "0.3.2"]
+ ["-p", "description=fixed-version"],
cli, ["template", "set", "-f", "python", "-s", TEMPLATES_URL, "-r", "0.3.2", "-p", "description=fixed-version"]
)

assert 0 == result.exit_code, format_result_exception(result)
with with_injection():
assert "python-minimal" == project_context.project.template_metadata.template_id
assert "python" == project_context.project.template_metadata.template_id
assert "0.3.2" == project_context.project.template_metadata.template_ref
assert "b9ab266fba136bdecfa91dc8d7b6d36b9d427012" == project_context.project.template_metadata.template_version

Expand All @@ -248,7 +246,7 @@ def test_template_update(runner, project, with_injection):
assert 0 == result.exit_code, format_result_exception(result)
assert "Template is up-to-date" not in result.output
with with_injection():
assert "python-minimal" == project_context.project.template_metadata.template_id
assert "python" == project_context.project.template_metadata.template_id
assert Version(project_context.project.template_metadata.template_ref) > Version("0.3.2")
assert "6c59d8863841baeca8f30062fd16c650cf67da3b" != project_context.project.template_metadata.template_version

Expand Down Expand Up @@ -284,8 +282,7 @@ def test_template_update_dry_run(runner, project):
"""Test update dry-run doesn't make any changes."""
result = runner.invoke(
cli,
["template", "set", "-f", "python-minimal", "-s", TEMPLATES_URL, "-r", "0.3.2"]
+ ["-p", "description=fixed-version"],
["template", "set", "-f", "python", "-s", TEMPLATES_URL, "-r", "0.3.2", "-p", "description=fixed-version"],
)

assert 0 == result.exit_code, format_result_exception(result)
Expand Down
18 changes: 9 additions & 9 deletions tests/core/commands/test_merge.py
Expand Up @@ -310,7 +310,7 @@ def test_merge_project_both_template_changed(mocker):
creator=Person.from_string("John Doe <jd@example.com>"),
name="my-project",
template_metadata=ProjectTemplateMetadata(
template_id="python-minimal",
template_id="python",
template_source="renku",
template_ref="master",
template_version="abcdef",
Expand All @@ -320,7 +320,7 @@ def test_merge_project_both_template_changed(mocker):
creator=Person.from_string("John Doe <jd@example.com>"),
name="my-project",
template_metadata=ProjectTemplateMetadata(
template_id="python-minimal1",
template_id="python1",
template_source="renku1",
template_ref="master1",
template_version="12345",
Expand All @@ -330,7 +330,7 @@ def test_merge_project_both_template_changed(mocker):
creator=Person.from_string("John Doe <jd@example.com>"),
name="my-project",
template_metadata=ProjectTemplateMetadata(
template_id="python-minimal2",
template_id="python2",
template_source="renku2",
template_ref="master2",
template_version="78910",
Expand All @@ -356,7 +356,7 @@ def test_merge_project_local_template_changed():
creator=Person.from_string("John Doe <jd@example.com>"),
name="my-project",
template_metadata=ProjectTemplateMetadata(
template_id="python-minimal",
template_id="python",
template_source="renku",
template_ref="master",
template_version="abcdef",
Expand All @@ -366,7 +366,7 @@ def test_merge_project_local_template_changed():
creator=Person.from_string("John Doe <jd@example.com>"),
name="my-project",
template_metadata=ProjectTemplateMetadata(
template_id="python-minimal1",
template_id="python1",
template_source="renku1",
template_ref="master1",
template_version="12345",
Expand All @@ -376,7 +376,7 @@ def test_merge_project_local_template_changed():
creator=Person.from_string("John Doe <jd@example.com>"),
name="my-project",
template_metadata=ProjectTemplateMetadata(
template_id="python-minimal",
template_id="python",
template_source="renku",
template_ref="master",
template_version="abcdef",
Expand All @@ -394,7 +394,7 @@ def test_merge_project_remote_template_changed():
creator=Person.from_string("John Doe <jd@example.com>"),
name="my-project",
template_metadata=ProjectTemplateMetadata(
template_id="python-minimal",
template_id="python",
template_source="renku",
template_ref="master",
template_version="abcdef",
Expand All @@ -404,7 +404,7 @@ def test_merge_project_remote_template_changed():
creator=Person.from_string("John Doe <jd@example.com>"),
name="my-project",
template_metadata=ProjectTemplateMetadata(
template_id="python-minimal",
template_id="python",
template_source="renku",
template_ref="master",
template_version="abcdef",
Expand All @@ -414,7 +414,7 @@ def test_merge_project_remote_template_changed():
creator=Person.from_string("John Doe <jd@example.com>"),
name="my-project",
template_metadata=ProjectTemplateMetadata(
template_id="python-minimal1",
template_id="python1",
template_source="renku1",
template_ref="master1",
template_version="12345",
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/repository.py
Expand Up @@ -104,7 +104,7 @@ def project(fake_home) -> Generator[RenkuProject, None, None]:
with isolated_filesystem(fake_home.parent, delete=True) as project_path:
with project_context.with_path(project_path):
communication.disable()
result = RenkuRunner().invoke(init, [".", "--template-id", "python-minimal"], "\n", catch_exceptions=False)
result = RenkuRunner().invoke(init, [".", "--template-id", "python"], "\n", catch_exceptions=False)
communication.enable()
assert 0 == result.exit_code, format_result_exception(result)

Expand Down
6 changes: 3 additions & 3 deletions tests/fixtures/templates.py
Expand Up @@ -35,7 +35,7 @@ def template_metadata():
yield {
"__template_source__": "renku",
"__template_ref__": renku_version,
"__template_id__": "python-minimal",
"__template_id__": "python",
"__namespace__": "",
"__repository__": "",
"__project_description__": "no description",
Expand All @@ -49,7 +49,7 @@ def template(template_metadata):
"""Yield template data."""
template = {
"url": "https://github.com/SwissDataScienceCenter/renku-project-template",
"id": "python-minimal",
"id": "python",
"index": 1,
"ref": "master",
# TODO: Add template parameters here once parameters are added to the template.
Expand Down Expand Up @@ -78,7 +78,7 @@ def project_init(template):
"--template-ref",
template["ref"],
"--template-id",
"python-minimal",
"python",
data["test_project"],
],
"init_custom_template": (
Expand Down
2 changes: 1 addition & 1 deletion tests/service/fixtures/service_integration.py
Expand Up @@ -239,7 +239,7 @@ def _mock_owner(self, data, **kwargs):
with chdir(remote_repo_checkout_path):

result = runner.invoke(
cli, ["init", ".", "--template-id", "python-minimal", "--force"], "\n", catch_exceptions=False
cli, ["init", ".", "--template-id", "python", "--force"], "\n", catch_exceptions=False
)
assert 0 == result.exit_code, format_result_exception(result)

Expand Down

0 comments on commit c4cd1dc

Please sign in to comment.