Skip to content

Commit 3634319

Browse files
committed
feat: plugin update command
1 parent d01b5f1 commit 3634319

File tree

2 files changed

+74
-4
lines changed

2 files changed

+74
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ default = "kiara:find_renderer_classes"
204204

205205
[project.optional-dependencies]
206206
dev_utils = [
207-
"kiara_plugin.core_types",
208-
"kiara_plugin.develop",
207+
"kiara_plugin.dev",
209208
"build",
210209
"ipython",
211210
"just-bin; sys_platform != 'win32'",

src/kiara/interfaces/cli/plugin/commands.py

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44
# Mozilla Public License, version 2.0 (see LICENSE or https://www.mozilla.org/en-US/MPL/2.0/)
55
import os
6+
import sys
67
from pathlib import Path
78
from typing import Union
89

@@ -27,8 +28,21 @@ def plugin_group(ctx):
2728
required=False,
2829
)
2930
@click.option("--template", "-t", help="The template to use.", required=False)
31+
@click.option(
32+
"--vcs-ref",
33+
"-r",
34+
help="The VCS ref to use, use 'HEAD' for latest dev template.",
35+
required=False,
36+
hidden=True,
37+
)
3038
@click.pass_context
31-
def create_plugin(ctx, name: str, path: Union[None, str], template: Union[None, str]):
39+
def create_plugin(
40+
ctx,
41+
name: str,
42+
path: Union[None, str],
43+
template: Union[None, str],
44+
vcs_ref: Union[None, str] = None,
45+
):
3246
"""Create a new kiara plugin."""
3347

3448
import sys
@@ -67,6 +81,63 @@ def create_plugin(ctx, name: str, path: Union[None, str], template: Union[None,
6781

6882
if not template:
6983
template = "gh:DHARPA-Project/kiara_plugin_template.git"
70-
run_copy(template, full_path, data=data, unsafe=True)
84+
run_copy(template, full_path, data=data, unsafe=True, vcs_ref=vcs_ref)
7185

7286
terminal_print(f"Created new plugin '{name}' in: {full_path}")
87+
88+
89+
@plugin_group.command(name="update")
90+
@click.argument("path", nargs=1, required=False)
91+
@click.option(
92+
"--template", "-t", help="The template to use.", required=False, hidden=True
93+
)
94+
@click.option(
95+
"--vcs-ref",
96+
"-r",
97+
help="The VCS ref to use, use 'HEAD' for latest dev template.",
98+
required=False,
99+
hidden=True,
100+
)
101+
@click.pass_context
102+
def update_plugin(
103+
ctx: click.Context,
104+
path: Union[str, None],
105+
template: Union[str, None],
106+
vcs_ref: Union[str, None],
107+
):
108+
"""Update a kiara plugin."""
109+
110+
from copier import run_update
111+
112+
if not path:
113+
_path = Path.cwd()
114+
else:
115+
_path = Path(path)
116+
117+
if not _path.exists():
118+
terminal_print(f"Path '{path}' does not exist.")
119+
sys.exit(1)
120+
121+
if not _path.is_dir():
122+
terminal_print(f"Path '{path}' is not a directory.")
123+
sys.exit(1)
124+
125+
copier_choice_file = _path / ".copier-answers.yml"
126+
if not copier_choice_file.exists():
127+
terminal_print(f"No .copier-answers.yml file found in '{path}'.")
128+
sys.exit(1)
129+
130+
if not copier_choice_file.is_file():
131+
terminal_print(f"Copier answers file '{path}' is not a file.")
132+
sys.exit(1)
133+
134+
run_update(
135+
src_path=template,
136+
dst_path=_path,
137+
vcs_ref=vcs_ref,
138+
unsafe=True,
139+
skip_answered=True,
140+
overwrite=True,
141+
)
142+
143+
terminal_print(f"Updating plugin in: {_path}")

0 commit comments

Comments
 (0)