nextmv 1.0.0.dev5__py3-none-any.whl → 1.0.0.dev6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nextmv/__about__.py +1 -1
- nextmv/_serialization.py +1 -1
- nextmv/cli/cloud/acceptance/create.py +12 -12
- nextmv/cli/cloud/app/push.py +15 -15
- nextmv/cli/cloud/input_set/__init__.py +2 -0
- nextmv/cli/cloud/input_set/delete.py +67 -0
- nextmv/cli/cloud/run/create.py +4 -9
- nextmv/cli/cloud/shadow/stop.py +14 -2
- nextmv/cli/cloud/switchback/stop.py +14 -2
- nextmv/cli/community/clone.py +11 -197
- nextmv/cli/community/list.py +46 -116
- nextmv/cloud/__init__.py +4 -0
- nextmv/cloud/application/__init__.py +1 -200
- nextmv/cloud/application/_input_set.py +42 -6
- nextmv/cloud/application/_run.py +1 -8
- nextmv/cloud/application/_shadow.py +9 -3
- nextmv/cloud/application/_switchback.py +10 -1
- nextmv/cloud/batch_experiment.py +3 -1
- nextmv/cloud/client.py +1 -1
- nextmv/cloud/community.py +441 -0
- nextmv/cloud/shadow.py +25 -0
- nextmv/default_app/main.py +6 -4
- nextmv/local/executor.py +3 -83
- nextmv/local/geojson_handler.py +1 -1
- nextmv/manifest.py +7 -11
- nextmv/model.py +2 -2
- nextmv/options.py +1 -1
- nextmv/output.py +21 -57
- nextmv/run.py +3 -12
- {nextmv-1.0.0.dev5.dist-info → nextmv-1.0.0.dev6.dist-info}/METADATA +3 -1
- {nextmv-1.0.0.dev5.dist-info → nextmv-1.0.0.dev6.dist-info}/RECORD +34 -32
- {nextmv-1.0.0.dev5.dist-info → nextmv-1.0.0.dev6.dist-info}/WHEEL +0 -0
- {nextmv-1.0.0.dev5.dist-info → nextmv-1.0.0.dev6.dist-info}/entry_points.txt +0 -0
- {nextmv-1.0.0.dev5.dist-info → nextmv-1.0.0.dev6.dist-info}/licenses/LICENSE +0 -0
nextmv/__about__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "v1.0.0.
|
|
1
|
+
__version__ = "v1.0.0.dev6"
|
nextmv/_serialization.py
CHANGED
|
@@ -90,7 +90,7 @@ def _custom_serial(obj: Any) -> str:
|
|
|
90
90
|
If the object type is not supported for serialization.
|
|
91
91
|
"""
|
|
92
92
|
|
|
93
|
-
if isinstance(obj, datetime.datetime
|
|
93
|
+
if isinstance(obj, (datetime.datetime, datetime.date)):
|
|
94
94
|
return obj.isoformat()
|
|
95
95
|
|
|
96
96
|
raise TypeError(f"Type {type(obj)} not serializable")
|
|
@@ -45,7 +45,7 @@ app = typer.Typer()
|
|
|
45
45
|
- Multiple metrics as a [magenta]json[/magenta] array in a single --metrics flag.
|
|
46
46
|
|
|
47
47
|
Each metric must have the following fields:
|
|
48
|
-
- [magenta]field[/magenta]: Field of the metric to measure (e.g., "
|
|
48
|
+
- [magenta]field[/magenta]: Field of the metric to measure (e.g., "solution.objective").
|
|
49
49
|
- [magenta]metric_type[/magenta]: Type of metric comparison. Allowed values: {enum_values(MetricType)}.
|
|
50
50
|
- [magenta]params[/magenta]: Parameters of the metric comparison.
|
|
51
51
|
- [magenta]operator[/magenta]: Comparison operator. Allowed values: {enum_values(Comparison)}.
|
|
@@ -71,8 +71,8 @@ app = typer.Typer()
|
|
|
71
71
|
[bold][underline]Examples[/underline][/bold]
|
|
72
72
|
|
|
73
73
|
- Create an acceptance test with a single metric.
|
|
74
|
-
$ [
|
|
75
|
-
"field": "
|
|
74
|
+
$ [dim]METRIC='{{
|
|
75
|
+
"field": "solution.objective",
|
|
76
76
|
"metric_type": "direct-comparison",
|
|
77
77
|
"params": {{
|
|
78
78
|
"operator": "lt",
|
|
@@ -85,8 +85,8 @@ app = typer.Typer()
|
|
|
85
85
|
--metrics "$METRIC" --input-set-id input-set-123[/dim]
|
|
86
86
|
|
|
87
87
|
- Create with multiple metrics by repeating the flag.
|
|
88
|
-
$ [
|
|
89
|
-
"field": "
|
|
88
|
+
$ [dim]METRIC1='{{
|
|
89
|
+
"field": "solution.objective",
|
|
90
90
|
"metric_type": "direct-comparison",
|
|
91
91
|
"params": {{
|
|
92
92
|
"operator": "lt",
|
|
@@ -95,7 +95,7 @@ app = typer.Typer()
|
|
|
95
95
|
"statistic": "mean"
|
|
96
96
|
}}'
|
|
97
97
|
METRIC2='{{
|
|
98
|
-
"field": "run.duration",
|
|
98
|
+
"field": "statistics.run.duration",
|
|
99
99
|
"metric_type": "direct-comparison",
|
|
100
100
|
"params": {{
|
|
101
101
|
"operator": "le",
|
|
@@ -110,7 +110,7 @@ app = typer.Typer()
|
|
|
110
110
|
- Create with multiple metrics in a single [magenta]json[/magenta] array.
|
|
111
111
|
$ [dim]METRICS='[
|
|
112
112
|
{{
|
|
113
|
-
"field": "
|
|
113
|
+
"field": "solution.objective",
|
|
114
114
|
"metric_type": "direct-comparison",
|
|
115
115
|
"params": {{
|
|
116
116
|
"operator": "lt",
|
|
@@ -119,7 +119,7 @@ app = typer.Typer()
|
|
|
119
119
|
"statistic": "mean"
|
|
120
120
|
}},
|
|
121
121
|
{{
|
|
122
|
-
"field": "run.duration",
|
|
122
|
+
"field": "statistics.run.duration",
|
|
123
123
|
"metric_type": "direct-comparison",
|
|
124
124
|
"params": {{
|
|
125
125
|
"operator": "le",
|
|
@@ -133,8 +133,8 @@ app = typer.Typer()
|
|
|
133
133
|
--metrics "$METRICS" --input-set-id input-set-123[/dim]
|
|
134
134
|
|
|
135
135
|
- Create an acceptance test and wait for it to complete.
|
|
136
|
-
$ [
|
|
137
|
-
"field": "
|
|
136
|
+
$ [dim]METRIC='{{
|
|
137
|
+
"field": "solution.objective",
|
|
138
138
|
"metric_type": "direct-comparison",
|
|
139
139
|
"params": {{
|
|
140
140
|
"operator": "lt",
|
|
@@ -147,8 +147,8 @@ app = typer.Typer()
|
|
|
147
147
|
--metrics "$METRIC" --input-set-id input-set-123 --wait[/dim]
|
|
148
148
|
|
|
149
149
|
- Create an acceptance test and save the results to a file, waiting for completion.
|
|
150
|
-
$ [
|
|
151
|
-
"field": "
|
|
150
|
+
$ [dim]METRIC='{{
|
|
151
|
+
"field": "solution.objective",
|
|
152
152
|
"metric_type": "direct-comparison",
|
|
153
153
|
"params": {{
|
|
154
154
|
"operator": "lt",
|
nextmv/cli/cloud/app/push.py
CHANGED
|
@@ -129,26 +129,34 @@ def push(
|
|
|
129
129
|
$ [dim]nextmv cloud app push --app-id hare-app --version-yes --update-instance-id inst-1[/dim]
|
|
130
130
|
"""
|
|
131
131
|
|
|
132
|
+
cloud_app = build_app(app_id=app_id, profile=profile)
|
|
133
|
+
|
|
134
|
+
# If a version already exists, we cannot create it.
|
|
135
|
+
if version_id is not None and version_id != "":
|
|
136
|
+
exists = cloud_app.version_exists(version_id=version_id)
|
|
137
|
+
if exists:
|
|
138
|
+
error(
|
|
139
|
+
f"Version [magenta]{version_id}[/magenta] already exists for application [magenta]{app_id}[/magenta]."
|
|
140
|
+
)
|
|
141
|
+
|
|
132
142
|
# We cannot create and update an instance at the same time.
|
|
133
143
|
update_defined = update_instance_id is not None and update_instance_id != ""
|
|
134
144
|
create_defined = create_instance_id is not None and create_instance_id != ""
|
|
135
145
|
if update_defined and create_defined:
|
|
136
146
|
error("Cannot use --update-instance-id and --create-instance-id at the same time.")
|
|
137
147
|
|
|
138
|
-
cloud_app = build_app(app_id=app_id, profile=profile)
|
|
139
|
-
|
|
140
148
|
# We cannot update an instance that does not exist.
|
|
141
149
|
if update_defined and not cloud_app.instance_exists(instance_id=update_instance_id):
|
|
142
150
|
error(
|
|
143
|
-
f"Used option --update-instance-id but the instance {update_instance_id}
|
|
144
|
-
"Use --create-instance-id instead."
|
|
151
|
+
f"Used option --update-instance-id but the instance [magenta]{update_instance_id}[/magenta] "
|
|
152
|
+
"does not exist. Use --create-instance-id instead."
|
|
145
153
|
)
|
|
146
154
|
|
|
147
155
|
# We cannot create an instance that already exists.
|
|
148
156
|
if create_defined and cloud_app.instance_exists(instance_id=create_instance_id):
|
|
149
157
|
error(
|
|
150
|
-
f"Used option --create-instance-id but the instance {create_instance_id}
|
|
151
|
-
"Use --update-instance-id instead."
|
|
158
|
+
f"Used option --create-instance-id but the instance [magenta]{create_instance_id}[/magenta] "
|
|
159
|
+
"already exists. Use --update-instance-id instead."
|
|
152
160
|
)
|
|
153
161
|
|
|
154
162
|
# Do the normal push first.
|
|
@@ -243,14 +251,6 @@ def _handle_version_creation(
|
|
|
243
251
|
# If the user provides a version, and it exists, we use it directly and we
|
|
244
252
|
# are done.
|
|
245
253
|
if version_id is not None and version_id != "":
|
|
246
|
-
exists = cloud_app.version_exists(version_id=version_id)
|
|
247
|
-
if exists:
|
|
248
|
-
error(
|
|
249
|
-
f"Version [magenta]{version_id}[/magenta] already exists for application [magenta]{app_id}[/magenta]."
|
|
250
|
-
)
|
|
251
|
-
|
|
252
|
-
return "", False
|
|
253
|
-
|
|
254
254
|
info(
|
|
255
255
|
msg=f"Version [magenta]{version_id}[/magenta] does not exist. A new version will be created.",
|
|
256
256
|
emoji=":bulb:",
|
|
@@ -261,7 +261,7 @@ def _handle_version_creation(
|
|
|
261
261
|
# If we are not auto-confirming version creation, ask the user.
|
|
262
262
|
if not version_yes:
|
|
263
263
|
should_create = get_confirmation(
|
|
264
|
-
msg=f"Do you want to create a new version [magenta]{app_id}[/magenta] now?",
|
|
264
|
+
msg=f"Do you want to create a new version for application [magenta]{app_id}[/magenta] now?",
|
|
265
265
|
default=True,
|
|
266
266
|
)
|
|
267
267
|
|
|
@@ -5,6 +5,7 @@ This module defines the cloud input-set command tree for the Nextmv CLI.
|
|
|
5
5
|
import typer
|
|
6
6
|
|
|
7
7
|
from nextmv.cli.cloud.input_set.create import app as create_app
|
|
8
|
+
from nextmv.cli.cloud.input_set.delete import app as delete_app
|
|
8
9
|
from nextmv.cli.cloud.input_set.get import app as get_app
|
|
9
10
|
from nextmv.cli.cloud.input_set.list import app as list_app
|
|
10
11
|
from nextmv.cli.cloud.input_set.update import app as update_app
|
|
@@ -12,6 +13,7 @@ from nextmv.cli.cloud.input_set.update import app as update_app
|
|
|
12
13
|
# Set up subcommand application.
|
|
13
14
|
app = typer.Typer()
|
|
14
15
|
app.add_typer(create_app)
|
|
16
|
+
app.add_typer(delete_app)
|
|
15
17
|
app.add_typer(get_app)
|
|
16
18
|
app.add_typer(list_app)
|
|
17
19
|
app.add_typer(update_app)
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module defines the cloud input-set delete command for the Nextmv CLI.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import Annotated
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
|
|
9
|
+
from nextmv.cli.configuration.config import build_app
|
|
10
|
+
from nextmv.cli.confirm import get_confirmation
|
|
11
|
+
from nextmv.cli.message import info, success
|
|
12
|
+
from nextmv.cli.options import AppIDOption, InputSetIDOption, ProfileOption
|
|
13
|
+
|
|
14
|
+
# Set up subcommand application.
|
|
15
|
+
app = typer.Typer()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@app.command()
|
|
19
|
+
def delete(
|
|
20
|
+
app_id: AppIDOption,
|
|
21
|
+
input_set_id: InputSetIDOption,
|
|
22
|
+
yes: Annotated[
|
|
23
|
+
bool,
|
|
24
|
+
typer.Option(
|
|
25
|
+
"--yes",
|
|
26
|
+
"-y",
|
|
27
|
+
help="Agree to deletion confirmation prompt. Useful for non-interactive sessions.",
|
|
28
|
+
),
|
|
29
|
+
] = False,
|
|
30
|
+
profile: ProfileOption = None,
|
|
31
|
+
) -> None:
|
|
32
|
+
"""
|
|
33
|
+
Deletes a Nextmv Cloud input set.
|
|
34
|
+
|
|
35
|
+
This action is permanent and cannot be undone. The input set and all
|
|
36
|
+
associated data will be deleted. Use the --yes flag to skip the
|
|
37
|
+
confirmation prompt.
|
|
38
|
+
|
|
39
|
+
[bold][underline]Examples[/underline][/bold]
|
|
40
|
+
|
|
41
|
+
- Delete the input set with the ID [magenta]hop-analysis[/magenta] from application
|
|
42
|
+
[magenta]hare-app[/magenta].
|
|
43
|
+
$ [dim]nextmv cloud input-set delete --app-id hare-app --input-set-id hop-analysis[/dim]
|
|
44
|
+
|
|
45
|
+
- Delete the input set without confirmation prompt.
|
|
46
|
+
$ [dim]nextmv cloud input-set delete --app-id hare-app --input-set-id carrot-routes --yes[/dim]
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
if not yes:
|
|
50
|
+
confirm = get_confirmation(
|
|
51
|
+
f"Are you sure you want to delete input set [magenta]{input_set_id}[/magenta] "
|
|
52
|
+
f"from application [magenta]{app_id}[/magenta]? This action cannot be undone.",
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
if not confirm:
|
|
56
|
+
info(
|
|
57
|
+
msg=f"Input set [magenta]{input_set_id}[/magenta] will not be deleted.",
|
|
58
|
+
emoji=":bulb:",
|
|
59
|
+
)
|
|
60
|
+
return
|
|
61
|
+
|
|
62
|
+
cloud_app = build_app(app_id=app_id, profile=profile)
|
|
63
|
+
cloud_app.delete_input_set(input_set_id=input_set_id)
|
|
64
|
+
success(
|
|
65
|
+
f"Input set [magenta]{input_set_id}[/magenta] deleted successfully "
|
|
66
|
+
f"from application [magenta]{app_id}[/magenta]."
|
|
67
|
+
)
|
nextmv/cli/cloud/run/create.py
CHANGED
|
@@ -129,7 +129,7 @@ def create(
|
|
|
129
129
|
metavar="INSTANCE_ID",
|
|
130
130
|
rich_help_panel="Run configuration",
|
|
131
131
|
),
|
|
132
|
-
] =
|
|
132
|
+
] = None,
|
|
133
133
|
integration_id: Annotated[
|
|
134
134
|
str | None,
|
|
135
135
|
typer.Option(
|
|
@@ -240,12 +240,11 @@ def create(
|
|
|
240
240
|
specify the instance with the --instance-id flag. These are the possible
|
|
241
241
|
values for this flag:
|
|
242
242
|
|
|
243
|
+
- [yellow]unspecified[/yellow]: Run against the default instance of the
|
|
244
|
+
application. When an application is created, the default instance is [magenta]latest[/magenta].
|
|
243
245
|
- [yellow]latest[/yellow]: uses the special [magenta]latest[/magenta]
|
|
244
246
|
instance of the application. This corresponds to the latest pushed
|
|
245
|
-
executable.
|
|
246
|
-
- [yellow]default[/yellow]: if the application has a [italic]default[/italic]
|
|
247
|
-
instance configured, then it uses that instance. Setting the flag's value
|
|
248
|
-
to [magenta]''[/magenta] (empty string) has the same effect.
|
|
247
|
+
executable.
|
|
249
248
|
- [yellow]<INSTANCE_ID>[/yellow]: uses the instance with the given ID.
|
|
250
249
|
|
|
251
250
|
[bold][underline]Examples[/underline][/bold]
|
|
@@ -319,10 +318,6 @@ def create(
|
|
|
319
318
|
)
|
|
320
319
|
run_options = build_run_options(options)
|
|
321
320
|
|
|
322
|
-
# Handles the default instance.
|
|
323
|
-
if instance_id == "default":
|
|
324
|
-
instance_id = ""
|
|
325
|
-
|
|
326
321
|
# Start the run before deciding if we should poll or not.
|
|
327
322
|
input_kwarg = resolve_input_kwarg(
|
|
328
323
|
stdin=stdin,
|
nextmv/cli/cloud/shadow/stop.py
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
This module defines the cloud shadow stop command for the Nextmv CLI.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
+
from typing import Annotated
|
|
6
|
+
|
|
5
7
|
import typer
|
|
6
8
|
|
|
7
9
|
from nextmv.cli.configuration.config import build_app
|
|
8
|
-
from nextmv.cli.message import in_progress, success
|
|
10
|
+
from nextmv.cli.message import enum_values, in_progress, success
|
|
9
11
|
from nextmv.cli.options import AppIDOption, ProfileOption, ShadowTestIDOption
|
|
12
|
+
from nextmv.cloud.shadow import StopIntent
|
|
10
13
|
|
|
11
14
|
# Set up subcommand application.
|
|
12
15
|
app = typer.Typer()
|
|
@@ -15,6 +18,15 @@ app = typer.Typer()
|
|
|
15
18
|
@app.command()
|
|
16
19
|
def stop(
|
|
17
20
|
app_id: AppIDOption,
|
|
21
|
+
intent: Annotated[
|
|
22
|
+
StopIntent,
|
|
23
|
+
typer.Option(
|
|
24
|
+
"--intent",
|
|
25
|
+
"-i",
|
|
26
|
+
help=f"Intent for stopping the shadow test. Allowed values are: {enum_values(StopIntent)}.",
|
|
27
|
+
metavar="INTENT",
|
|
28
|
+
),
|
|
29
|
+
],
|
|
18
30
|
shadow_test_id: ShadowTestIDOption,
|
|
19
31
|
profile: ProfileOption = None,
|
|
20
32
|
) -> None:
|
|
@@ -34,7 +46,7 @@ def stop(
|
|
|
34
46
|
|
|
35
47
|
in_progress(msg="Stopping shadow test...")
|
|
36
48
|
cloud_app = build_app(app_id=app_id, profile=profile)
|
|
37
|
-
cloud_app.stop_shadow_test(shadow_test_id=shadow_test_id)
|
|
49
|
+
cloud_app.stop_shadow_test(shadow_test_id=shadow_test_id, intent=StopIntent(intent))
|
|
38
50
|
success(
|
|
39
51
|
f"Shadow test [magenta]{shadow_test_id}[/magenta] stopped successfully "
|
|
40
52
|
f"in application [magenta]{app_id}[/magenta]."
|
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
This module defines the cloud switchback stop command for the Nextmv CLI.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
+
from typing import Annotated
|
|
6
|
+
|
|
5
7
|
import typer
|
|
6
8
|
|
|
7
9
|
from nextmv.cli.configuration.config import build_app
|
|
8
|
-
from nextmv.cli.message import in_progress, success
|
|
10
|
+
from nextmv.cli.message import enum_values, in_progress, success
|
|
9
11
|
from nextmv.cli.options import AppIDOption, ProfileOption, SwitchbackTestIDOption
|
|
12
|
+
from nextmv.cloud.shadow import StopIntent
|
|
10
13
|
|
|
11
14
|
# Set up subcommand application.
|
|
12
15
|
app = typer.Typer()
|
|
@@ -15,6 +18,15 @@ app = typer.Typer()
|
|
|
15
18
|
@app.command()
|
|
16
19
|
def stop(
|
|
17
20
|
app_id: AppIDOption,
|
|
21
|
+
intent: Annotated[
|
|
22
|
+
StopIntent,
|
|
23
|
+
typer.Option(
|
|
24
|
+
"--intent",
|
|
25
|
+
"-i",
|
|
26
|
+
help=f"Intent for stopping the switchback test. Allowed values are: {enum_values(StopIntent)}.",
|
|
27
|
+
metavar="INTENT",
|
|
28
|
+
),
|
|
29
|
+
],
|
|
18
30
|
switchback_test_id: SwitchbackTestIDOption,
|
|
19
31
|
profile: ProfileOption = None,
|
|
20
32
|
) -> None:
|
|
@@ -34,7 +46,7 @@ def stop(
|
|
|
34
46
|
|
|
35
47
|
in_progress(msg="Stopping switchback test...")
|
|
36
48
|
cloud_app = build_app(app_id=app_id, profile=profile)
|
|
37
|
-
cloud_app.stop_switchback_test(switchback_test_id=switchback_test_id)
|
|
49
|
+
cloud_app.stop_switchback_test(switchback_test_id=switchback_test_id, intent=StopIntent(intent))
|
|
38
50
|
success(
|
|
39
51
|
f"Switchback test [magenta]{switchback_test_id}[/magenta] stopped successfully "
|
|
40
52
|
f"in application [magenta]{app_id}[/magenta]."
|
nextmv/cli/community/clone.py
CHANGED
|
@@ -2,19 +2,14 @@
|
|
|
2
2
|
This module defines the community clone command for the Nextmv CLI.
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
-
import os
|
|
6
|
-
import shutil
|
|
7
|
-
import tarfile
|
|
8
|
-
import tempfile
|
|
9
|
-
from collections.abc import Callable
|
|
10
5
|
from typing import Annotated
|
|
11
6
|
|
|
12
|
-
import rich
|
|
13
7
|
import typer
|
|
14
8
|
|
|
15
|
-
from nextmv.cli.
|
|
16
|
-
from nextmv.cli.message import error
|
|
9
|
+
from nextmv.cli.configuration.config import build_client
|
|
10
|
+
from nextmv.cli.message import error
|
|
17
11
|
from nextmv.cli.options import ProfileOption
|
|
12
|
+
from nextmv.cloud.community import clone_community_app
|
|
18
13
|
|
|
19
14
|
# Set up subcommand application.
|
|
20
15
|
app = typer.Typer()
|
|
@@ -77,196 +72,15 @@ def clone(
|
|
|
77
72
|
$ [dim]nextmv community clone --app go-nextroute --profile hare[/dim]
|
|
78
73
|
"""
|
|
79
74
|
|
|
80
|
-
manifest = download_manifest(profile=profile)
|
|
81
|
-
app_obj = find_app(manifest, app)
|
|
82
|
-
|
|
83
75
|
if version is not None and version == "":
|
|
84
76
|
error("The --version flag cannot be an empty string.")
|
|
85
77
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
raise typer.Exit(code=1)
|
|
95
|
-
|
|
96
|
-
original_version = version
|
|
97
|
-
if version == LATEST_VERSION:
|
|
98
|
-
version = app_obj.get("latest_app_version")
|
|
99
|
-
|
|
100
|
-
# Clean and normalize directory path in an OS-independent way
|
|
101
|
-
if directory is not None and directory != "":
|
|
102
|
-
destination = os.path.normpath(directory)
|
|
103
|
-
else:
|
|
104
|
-
destination = app
|
|
105
|
-
|
|
106
|
-
full_destination = get_valid_path(destination, os.stat)
|
|
107
|
-
os.makedirs(full_destination, exist_ok=True)
|
|
108
|
-
|
|
109
|
-
tarball = f"{app}_{version}.tar.gz"
|
|
110
|
-
s3_file_path = f"{app}/{version}/{tarball}"
|
|
111
|
-
downloaded_object = download_object(
|
|
112
|
-
file=s3_file_path,
|
|
113
|
-
path="community-apps",
|
|
114
|
-
output_dir=full_destination,
|
|
115
|
-
output_file=tarball,
|
|
116
|
-
profile=profile,
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
# Extract the tarball to a temporary directory to handle nested structure
|
|
120
|
-
with tempfile.TemporaryDirectory() as temp_dir:
|
|
121
|
-
with tarfile.open(downloaded_object, "r:gz") as tar:
|
|
122
|
-
tar.extractall(path=temp_dir)
|
|
123
|
-
|
|
124
|
-
# Find the extracted directory (typically the app name)
|
|
125
|
-
extracted_items = os.listdir(temp_dir)
|
|
126
|
-
if len(extracted_items) == 1 and os.path.isdir(os.path.join(temp_dir, extracted_items[0])):
|
|
127
|
-
# Move contents from the extracted directory to full_destination
|
|
128
|
-
extracted_dir = os.path.join(temp_dir, extracted_items[0])
|
|
129
|
-
for item in os.listdir(extracted_dir):
|
|
130
|
-
shutil.move(os.path.join(extracted_dir, item), full_destination)
|
|
131
|
-
else:
|
|
132
|
-
# If structure is unexpected, move everything directly
|
|
133
|
-
for item in extracted_items:
|
|
134
|
-
shutil.move(os.path.join(temp_dir, item), full_destination)
|
|
135
|
-
|
|
136
|
-
# Remove the tarball after extraction
|
|
137
|
-
os.remove(downloaded_object)
|
|
138
|
-
|
|
139
|
-
success(
|
|
140
|
-
f"Successfully cloned the [magenta]{app}[/magenta] community app, "
|
|
141
|
-
f"using version [magenta]{original_version}[/magenta] in path: [magenta]{full_destination}[/magenta]."
|
|
78
|
+
client = build_client(profile)
|
|
79
|
+
clone_community_app(
|
|
80
|
+
client=client,
|
|
81
|
+
app=app,
|
|
82
|
+
directory=directory,
|
|
83
|
+
version=version,
|
|
84
|
+
verbose=True,
|
|
85
|
+
rich_print=True,
|
|
142
86
|
)
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
def app_has_version(app_obj: dict, version: str) -> bool:
|
|
146
|
-
"""
|
|
147
|
-
Check if the given app object has the specified version.
|
|
148
|
-
|
|
149
|
-
Parameters
|
|
150
|
-
----------
|
|
151
|
-
app_obj : dict
|
|
152
|
-
The community app object.
|
|
153
|
-
version : str
|
|
154
|
-
The version to check.
|
|
155
|
-
|
|
156
|
-
Returns
|
|
157
|
-
-------
|
|
158
|
-
bool
|
|
159
|
-
True if the app has the specified version, False otherwise.
|
|
160
|
-
"""
|
|
161
|
-
|
|
162
|
-
if version == LATEST_VERSION:
|
|
163
|
-
version = app_obj.get("latest_app_version")
|
|
164
|
-
|
|
165
|
-
if version in app_obj.get("app_versions", []):
|
|
166
|
-
return True
|
|
167
|
-
|
|
168
|
-
return False
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
def get_valid_path(path: str, stat_fn: Callable[[str], os.stat_result], ending: str = "") -> str:
|
|
172
|
-
"""
|
|
173
|
-
Validates and returns a non-existing path. If the path exists,
|
|
174
|
-
it will append a number to the path and return it. If the path does not
|
|
175
|
-
exist, it will return the path as is.
|
|
176
|
-
|
|
177
|
-
The ending parameter is used to check if the path ends with a specific
|
|
178
|
-
string. This is useful to specify if it is a file (like foo.json, in which
|
|
179
|
-
case the next iteration is foo-1.json) or a directory (like foo, in which
|
|
180
|
-
case the next iteration is foo-1).
|
|
181
|
-
|
|
182
|
-
Parameters
|
|
183
|
-
----------
|
|
184
|
-
path : str
|
|
185
|
-
The initial path to validate.
|
|
186
|
-
stat_fn : Callable[[str], os.stat_result]
|
|
187
|
-
A function that takes a path and returns its stat result.
|
|
188
|
-
ending : str, optional
|
|
189
|
-
The expected ending of the path (e.g., file extension), by default "".
|
|
190
|
-
|
|
191
|
-
Returns
|
|
192
|
-
-------
|
|
193
|
-
str
|
|
194
|
-
A valid, non-existing path.
|
|
195
|
-
|
|
196
|
-
Raises
|
|
197
|
-
------
|
|
198
|
-
Exception
|
|
199
|
-
If an unexpected error occurs during path validation
|
|
200
|
-
"""
|
|
201
|
-
base_name = os.path.basename(path)
|
|
202
|
-
name_without_ending = base_name.removesuffix(ending) if ending else base_name
|
|
203
|
-
|
|
204
|
-
while True:
|
|
205
|
-
try:
|
|
206
|
-
stat_fn(path)
|
|
207
|
-
# If we get here, the path exists
|
|
208
|
-
# Get folder/file name number, increase it and create new path
|
|
209
|
-
name = os.path.basename(path)
|
|
210
|
-
|
|
211
|
-
# Get folder/file name number
|
|
212
|
-
parts = name.split("-")
|
|
213
|
-
last = parts[-1].removesuffix(ending) if ending else parts[-1]
|
|
214
|
-
|
|
215
|
-
# Save last folder name index to be changed
|
|
216
|
-
i = path.rfind(name)
|
|
217
|
-
|
|
218
|
-
try:
|
|
219
|
-
num = int(last)
|
|
220
|
-
# Increase number and create new path
|
|
221
|
-
if ending:
|
|
222
|
-
temp_path = path[:i] + f"{name_without_ending}-{num + 1}{ending}"
|
|
223
|
-
else:
|
|
224
|
-
temp_path = path[:i] + f"{base_name}-{num + 1}"
|
|
225
|
-
path = temp_path
|
|
226
|
-
except ValueError:
|
|
227
|
-
# If there is no number, add it
|
|
228
|
-
if ending:
|
|
229
|
-
temp_path = path[:i] + f"{name_without_ending}-1{ending}"
|
|
230
|
-
else:
|
|
231
|
-
temp_path = path[:i] + f"{name}-1"
|
|
232
|
-
path = temp_path
|
|
233
|
-
|
|
234
|
-
except FileNotFoundError:
|
|
235
|
-
# Path doesn't exist, we can use it
|
|
236
|
-
return path
|
|
237
|
-
except Exception:
|
|
238
|
-
# Re-raise unexpected errors
|
|
239
|
-
error(f"An unexpected error occurred while validating the path: {path}")
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
def download_object(file: str, path: str, output_dir: str, output_file: str, profile: str | None = None) -> str:
|
|
243
|
-
"""
|
|
244
|
-
Downloads an object from the internal bucket and saves it to the specified
|
|
245
|
-
output directory.
|
|
246
|
-
|
|
247
|
-
Parameters
|
|
248
|
-
----------
|
|
249
|
-
file : str
|
|
250
|
-
The name of the file to download.
|
|
251
|
-
path : str
|
|
252
|
-
The directory in the bucket where the file is located.
|
|
253
|
-
output_dir : str
|
|
254
|
-
The local directory where the file will be saved.
|
|
255
|
-
output_file : str
|
|
256
|
-
The name of the output file.
|
|
257
|
-
profile : str | None
|
|
258
|
-
The profile name to use. If None, the default profile is used.
|
|
259
|
-
|
|
260
|
-
Returns
|
|
261
|
-
-------
|
|
262
|
-
str
|
|
263
|
-
The path to the downloaded file.
|
|
264
|
-
"""
|
|
265
|
-
|
|
266
|
-
response = download_file(directory=path, file=file, profile=profile)
|
|
267
|
-
file_name = os.path.join(output_dir, output_file)
|
|
268
|
-
|
|
269
|
-
with open(file_name, "wb") as f:
|
|
270
|
-
f.write(response.content)
|
|
271
|
-
|
|
272
|
-
return file_name
|