nextmv 1.0.0.dev9__py3-none-any.whl → 1.0.0.dev10__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.
Files changed (45) hide show
  1. nextmv/__about__.py +1 -1
  2. nextmv/cli/CONTRIBUTING.md +31 -11
  3. nextmv/cli/cloud/acceptance/delete.py +1 -4
  4. nextmv/cli/cloud/account/delete.py +1 -1
  5. nextmv/cli/cloud/app/delete.py +1 -1
  6. nextmv/cli/cloud/app/push.py +23 -42
  7. nextmv/cli/cloud/batch/delete.py +1 -4
  8. nextmv/cli/cloud/ensemble/delete.py +1 -4
  9. nextmv/cli/cloud/input_set/__init__.py +2 -0
  10. nextmv/cli/cloud/input_set/delete.py +64 -0
  11. nextmv/cli/cloud/instance/delete.py +1 -1
  12. nextmv/cli/cloud/managed_input/delete.py +1 -1
  13. nextmv/cli/cloud/run/create.py +4 -9
  14. nextmv/cli/cloud/scenario/delete.py +1 -4
  15. nextmv/cli/cloud/secrets/delete.py +1 -4
  16. nextmv/cli/cloud/shadow/delete.py +1 -4
  17. nextmv/cli/cloud/shadow/stop.py +14 -2
  18. nextmv/cli/cloud/switchback/delete.py +1 -4
  19. nextmv/cli/cloud/switchback/stop.py +14 -2
  20. nextmv/cli/cloud/version/delete.py +1 -1
  21. nextmv/cli/community/clone.py +11 -198
  22. nextmv/cli/community/list.py +51 -116
  23. nextmv/cli/configuration/create.py +4 -4
  24. nextmv/cli/configuration/delete.py +1 -1
  25. nextmv/cli/main.py +2 -3
  26. nextmv/cli/message.py +71 -54
  27. nextmv/cloud/__init__.py +4 -0
  28. nextmv/cloud/application/__init__.py +1 -198
  29. nextmv/cloud/application/_acceptance.py +13 -8
  30. nextmv/cloud/application/_input_set.py +42 -6
  31. nextmv/cloud/application/_run.py +2 -2
  32. nextmv/cloud/application/_shadow.py +9 -3
  33. nextmv/cloud/application/_switchback.py +11 -2
  34. nextmv/cloud/batch_experiment.py +3 -1
  35. nextmv/cloud/community.py +446 -0
  36. nextmv/cloud/integration.py +7 -4
  37. nextmv/cloud/shadow.py +25 -0
  38. nextmv/cloud/switchback.py +2 -0
  39. nextmv/model.py +40 -4
  40. nextmv/options.py +1 -1
  41. {nextmv-1.0.0.dev9.dist-info → nextmv-1.0.0.dev10.dist-info}/METADATA +3 -1
  42. {nextmv-1.0.0.dev9.dist-info → nextmv-1.0.0.dev10.dist-info}/RECORD +45 -43
  43. {nextmv-1.0.0.dev9.dist-info → nextmv-1.0.0.dev10.dist-info}/WHEEL +0 -0
  44. {nextmv-1.0.0.dev9.dist-info → nextmv-1.0.0.dev10.dist-info}/entry_points.txt +0 -0
  45. {nextmv-1.0.0.dev9.dist-info → nextmv-1.0.0.dev10.dist-info}/licenses/LICENSE +0 -0
@@ -5,6 +5,7 @@ Application mixin for managing switchback tests.
5
5
  from datetime import datetime
6
6
  from typing import TYPE_CHECKING
7
7
 
8
+ from nextmv.cloud.shadow import StopIntent
8
9
  from nextmv.cloud.switchback import SwitchbackTest, SwitchbackTestMetadata, TestComparisonSingle
9
10
  from nextmv.run import Run
10
11
  from nextmv.safe import safe_id
@@ -216,7 +217,7 @@ class ApplicationSwitchbackMixin:
216
217
  payload = {
217
218
  "id": switchback_test_id,
218
219
  "name": name,
219
- "comparison": comparison,
220
+ "comparison": comparison.to_dict(),
220
221
  "generate_random_plan": {
221
222
  "unit_duration_minutes": unit_duration_minutes,
222
223
  "units": units,
@@ -257,7 +258,7 @@ class ApplicationSwitchbackMixin:
257
258
  endpoint=f"{self.experiments_endpoint}/switchback/{switchback_test_id}/start",
258
259
  )
259
260
 
260
- def stop_switchback_test(self: "Application", switchback_test_id: str) -> None:
261
+ def stop_switchback_test(self: "Application", switchback_test_id: str, intent: StopIntent) -> None:
261
262
  """
262
263
  Stop a switchback test. The test should already have started before using
263
264
  this method.
@@ -267,15 +268,23 @@ class ApplicationSwitchbackMixin:
267
268
  switchback_test_id : str
268
269
  ID of the switchback test to stop.
269
270
 
271
+ intent : StopIntent
272
+ Intent for stopping the switchback test.
273
+
270
274
  Raises
271
275
  ------
272
276
  requests.HTTPError
273
277
  If the response status code is not 2xx.
274
278
  """
275
279
 
280
+ payload = {
281
+ "intent": intent.value,
282
+ }
283
+
276
284
  _ = self.client.request(
277
285
  method="PUT",
278
286
  endpoint=f"{self.experiments_endpoint}/switchback/{switchback_test_id}/stop",
287
+ payload=payload,
279
288
  )
280
289
 
281
290
  def update_switchback_test(
@@ -30,7 +30,9 @@ class ExperimentStatus(str, Enum):
30
30
 
31
31
  You can import the `ExperimentStatus` class directly from `cloud`:
32
32
 
33
- ```python from nextmv.cloud import ExperimentStatus ```
33
+ ```python
34
+ from nextmv.cloud import ExperimentStatus
35
+ ```
34
36
 
35
37
  This enum represents the comprehensive set of possible states for an
36
38
  experiment in Nextmv Cloud.
@@ -0,0 +1,446 @@
1
+ """
2
+ This module contains functionality for working with Nextmv community apps.
3
+
4
+ Community apps are pre-built decision models. They are maintained in the
5
+ following GitHub repository: https://github.com/nextmv-io/community-apps
6
+
7
+ Classes
8
+ -------
9
+ CommunityApp
10
+ Representation of a Nextmv Cloud Community App.
11
+
12
+ Functions
13
+ ---------
14
+ list_community_apps
15
+ List the available Nextmv community apps.
16
+ clone_community_app
17
+ Clone a community app locally.
18
+ """
19
+
20
+ import os
21
+ import shutil
22
+ import sys
23
+ import tarfile
24
+ import tempfile
25
+ from collections.abc import Callable
26
+ from typing import Any
27
+
28
+ import requests
29
+ import rich
30
+ import yaml
31
+ from pydantic import AliasChoices, Field
32
+
33
+ from nextmv.base_model import BaseModel
34
+ from nextmv.cloud.client import Client
35
+ from nextmv.logger import log
36
+
37
+ # Helpful constants.
38
+ LATEST_VERSION = "latest"
39
+
40
+
41
+ class CommunityApp(BaseModel):
42
+ """
43
+ Information about a Nextmv community app.
44
+
45
+ You can import the `CommunityApp` class directly from `cloud`:
46
+
47
+ ```python
48
+ from nextmv.cloud import CommunityApp
49
+ ```
50
+
51
+ Parameters
52
+ ----------
53
+ app_versions : list[str]
54
+ Available versions of the community app.
55
+ description : str
56
+ Description of the community app.
57
+ latest_app_version : str
58
+ The latest version of the community app.
59
+ latest_marketplace_version : str
60
+ The latest version of the community app in the Nextmv Marketplace.
61
+ marketplace_versions : list[str]
62
+ Available versions of the community app in the Nextmv Marketplace.
63
+ name : str
64
+ Name of the community app.
65
+ app_type : str
66
+ Type of the community app.
67
+ """
68
+
69
+ description: str
70
+ """Description of the community app."""
71
+ name: str
72
+ """Name of the community app."""
73
+ app_type: str = Field(
74
+ serialization_alias="type",
75
+ validation_alias=AliasChoices("type", "app_type"),
76
+ )
77
+ """Type of the community app."""
78
+
79
+ app_versions: list[str] | None = None
80
+ """Available versions of the community app."""
81
+ latest_app_version: str | None = None
82
+ """The latest version of the community app."""
83
+ latest_marketplace_version: str | None = None
84
+ """The latest version of the community app in the Nextmv Marketplace."""
85
+ marketplace_versions: list[str] | None = None
86
+ """Available versions of the community app in the Nextmv Marketplace."""
87
+
88
+ def has_version(self, version: str) -> bool:
89
+ """
90
+ Check if the community app has the specified version.
91
+
92
+ Parameters
93
+ ----------
94
+ version : str
95
+ The version to check.
96
+
97
+ Returns
98
+ -------
99
+ bool
100
+ True if the app has the specified version, False otherwise.
101
+ """
102
+
103
+ if version == LATEST_VERSION:
104
+ version = self.latest_app_version
105
+
106
+ if self.app_versions is not None and version in self.app_versions:
107
+ return True
108
+
109
+ return False
110
+
111
+
112
+ def list_community_apps(client: Client) -> list[CommunityApp]:
113
+ """
114
+ List the available Nextmv community apps.
115
+
116
+ You can import the `list_community_apps` function directly from `cloud`:
117
+
118
+ ```python
119
+ from nextmv.cloud import list_community_apps
120
+ ```
121
+
122
+ Parameters
123
+ ----------
124
+ client : Client
125
+ The Nextmv Cloud client to use for the request.
126
+
127
+ Returns
128
+ -------
129
+ list[CommunityApp]
130
+ A list of available community apps.
131
+ """
132
+
133
+ manifest = _download_manifest(client)
134
+ dict_apps = manifest.get("apps", [])
135
+ apps = [CommunityApp.from_dict(app) for app in dict_apps]
136
+
137
+ return apps
138
+
139
+
140
+ def clone_community_app(
141
+ client: Client,
142
+ app: str,
143
+ directory: str | None = None,
144
+ version: str | None = LATEST_VERSION,
145
+ verbose: bool = False,
146
+ rich_print: bool = False,
147
+ ) -> None:
148
+ """
149
+ Clone a community app locally.
150
+
151
+ By default, the `latest` version will be used. You can
152
+ specify a version with the `version` parameter, and customize the output
153
+ directory with the `directory` parameter. If you want to list the available
154
+ apps, use the `list_community_apps` function.
155
+
156
+ You can import the `clone_community_app` function directly from `cloud`:
157
+
158
+ ```python
159
+ from nextmv.cloud import clone_community_app
160
+ ```
161
+
162
+ Parameters
163
+ ----------
164
+ client : Client
165
+ The Nextmv Cloud client to use for the request.
166
+ app : str
167
+ The name of the community app to clone.
168
+ directory : str | None, optional
169
+ The directory in which to clone the app. Default is the name of the app at current directory.
170
+ version : str | None, optional
171
+ The version of the community app to clone. Default is `latest`.
172
+ verbose : bool, optional
173
+ Whether to print verbose output.
174
+ rich_print : bool, optional
175
+ Whether to use rich printing for output messages.
176
+ """
177
+ comm_app = _find_app(client, app)
178
+
179
+ if version is not None and version == "":
180
+ raise ValueError("`version` cannot be an empty string.")
181
+
182
+ if not comm_app.has_version(version):
183
+ raise ValueError(f"Community app '{app}' does not have version '{version}'.")
184
+
185
+ original_version = version
186
+ if version == LATEST_VERSION:
187
+ version = comm_app.latest_app_version
188
+
189
+ # Clean and normalize directory path in an OS-independent way
190
+ if directory is not None and directory != "":
191
+ destination = os.path.normpath(directory)
192
+ else:
193
+ destination = app
194
+
195
+ full_destination = _get_valid_path(destination, os.stat)
196
+ os.makedirs(full_destination, exist_ok=True)
197
+
198
+ tarball = f"{app}_{version}.tar.gz"
199
+ s3_file_path = f"{app}/{version}/{tarball}"
200
+ downloaded_object = _download_object(
201
+ client=client,
202
+ file=s3_file_path,
203
+ path="community-apps",
204
+ output_dir=full_destination,
205
+ output_file=tarball,
206
+ )
207
+
208
+ # Extract the tarball to a temporary directory to handle nested structure
209
+ with tempfile.TemporaryDirectory() as temp_dir:
210
+ with tarfile.open(downloaded_object, "r:gz") as tar:
211
+ tar.extractall(path=temp_dir)
212
+
213
+ # Find the extracted directory (typically the app name)
214
+ extracted_items = os.listdir(temp_dir)
215
+ if len(extracted_items) == 1 and os.path.isdir(os.path.join(temp_dir, extracted_items[0])):
216
+ # Move contents from the extracted directory to full_destination
217
+ extracted_dir = os.path.join(temp_dir, extracted_items[0])
218
+ for item in os.listdir(extracted_dir):
219
+ shutil.move(os.path.join(extracted_dir, item), full_destination)
220
+ else:
221
+ # If structure is unexpected, move everything directly
222
+ for item in extracted_items:
223
+ shutil.move(os.path.join(temp_dir, item), full_destination)
224
+
225
+ # Remove the tarball after extraction
226
+ os.remove(downloaded_object)
227
+
228
+ if not verbose:
229
+ return
230
+
231
+ if rich_print:
232
+ rich.print(
233
+ f":white_check_mark: Successfully cloned the [magenta]{app}[/magenta] community app, "
234
+ f"using version [magenta]{original_version}[/magenta] in path: [magenta]{full_destination}[/magenta].",
235
+ file=sys.stderr,
236
+ )
237
+ return
238
+
239
+ log(
240
+ f"✅ Successfully cloned the {app} community app, using version {original_version} in path: {full_destination}."
241
+ )
242
+
243
+
244
+ def _download_manifest(client: Client) -> dict[str, Any]:
245
+ """
246
+ Downloads and returns the community apps manifest.
247
+
248
+ Parameters
249
+ ----------
250
+ client : Client
251
+ The Nextmv Cloud client to use for the request.
252
+
253
+ Returns
254
+ -------
255
+ dict[str, Any]
256
+ The community apps manifest as a dictionary.
257
+
258
+ Raises
259
+ requests.HTTPError
260
+ If the response status code is not 2xx.
261
+ """
262
+
263
+ response = _download_file(client=client, directory="community-apps", file="manifest.yml")
264
+ manifest = yaml.safe_load(response.text)
265
+
266
+ return manifest
267
+
268
+
269
+ def _download_file(
270
+ client: Client,
271
+ directory: str,
272
+ file: str,
273
+ ) -> requests.Response:
274
+ """
275
+ Gets a file from an internal bucket and return it.
276
+
277
+ Parameters
278
+ ----------
279
+ client : Client
280
+ The Nextmv Cloud client to use for the request.
281
+ directory : str
282
+ The directory in the bucket where the file is located.
283
+ file : str
284
+ The name of the file to download.
285
+
286
+ Returns
287
+ -------
288
+ requests.Response
289
+ The response object containing the file data.
290
+
291
+ Raises
292
+ requests.HTTPError
293
+ If the response status code is not 2xx.
294
+ """
295
+
296
+ # Request the download URL for the file.
297
+ response = client.request(
298
+ method="GET",
299
+ endpoint="v0/internal/tools",
300
+ headers=client.headers | {"request-source": "cli"}, # Pass `client.headers` to preserve auth.
301
+ query_params={"file": f"{directory}/{file}"},
302
+ )
303
+
304
+ # Use the URL obtained to download the file.
305
+ body = response.json()
306
+ download_response = client.request(
307
+ method="GET",
308
+ endpoint=body.get("url"),
309
+ headers={"Content-Type": "application/json"},
310
+ )
311
+
312
+ return download_response
313
+
314
+
315
+ def _download_object(client: Client, file: str, path: str, output_dir: str, output_file: str) -> str:
316
+ """
317
+ Downloads an object from the internal bucket and saves it to the specified
318
+ output directory.
319
+
320
+ Parameters
321
+ ----------
322
+ client : Client
323
+ The Nextmv Cloud client to use for the request.
324
+ file : str
325
+ The name of the file to download.
326
+ path : str
327
+ The directory in the bucket where the file is located.
328
+ output_dir : str
329
+ The local directory where the file will be saved.
330
+ output_file : str
331
+ The name of the output file.
332
+
333
+ Returns
334
+ -------
335
+ str
336
+ The path to the downloaded file.
337
+ """
338
+
339
+ response = _download_file(client=client, directory=path, file=file)
340
+ file_name = os.path.join(output_dir, output_file)
341
+
342
+ with open(file_name, "wb") as f:
343
+ f.write(response.content)
344
+
345
+ return file_name
346
+
347
+
348
+ def _get_valid_path(path: str, stat_fn: Callable[[str], os.stat_result], ending: str = "") -> str:
349
+ """
350
+ Validates and returns a non-existing path. If the path exists,
351
+ it will append a number to the path and return it. If the path does not
352
+ exist, it will return the path as is.
353
+
354
+ The ending parameter is used to check if the path ends with a specific
355
+ string. This is useful to specify if it is a file (like foo.json, in which
356
+ case the next iteration is foo-1.json) or a directory (like foo, in which
357
+ case the next iteration is foo-1).
358
+
359
+ Parameters
360
+ ----------
361
+ path : str
362
+ The initial path to validate.
363
+ stat_fn : Callable[[str], os.stat_result]
364
+ A function that takes a path and returns its stat result.
365
+ ending : str, optional
366
+ The expected ending of the path (e.g., file extension), by default "".
367
+
368
+ Returns
369
+ -------
370
+ str
371
+ A valid, non-existing path.
372
+
373
+ Raises
374
+ ------
375
+ RuntimeError
376
+ If an unexpected error occurs during path validation
377
+ """
378
+ base_name = os.path.basename(path)
379
+ name_without_ending = base_name.removesuffix(ending) if ending else base_name
380
+
381
+ while True:
382
+ try:
383
+ stat_fn(path)
384
+ # If we get here, the path exists
385
+ # Get folder/file name number, increase it and create new path
386
+ name = os.path.basename(path)
387
+
388
+ # Get folder/file name number
389
+ parts = name.split("-")
390
+ last = parts[-1].removesuffix(ending) if ending else parts[-1]
391
+
392
+ # Save last folder name index to be changed
393
+ i = path.rfind(name)
394
+
395
+ try:
396
+ num = int(last)
397
+ # Increase number and create new path
398
+ if ending:
399
+ temp_path = path[:i] + f"{name_without_ending}-{num + 1}{ending}"
400
+ else:
401
+ temp_path = path[:i] + f"{base_name}-{num + 1}"
402
+ path = temp_path
403
+ except ValueError:
404
+ # If there is no number, add it
405
+ if ending:
406
+ temp_path = path[:i] + f"{name_without_ending}-1{ending}"
407
+ else:
408
+ temp_path = path[:i] + f"{name}-1"
409
+ path = temp_path
410
+
411
+ except FileNotFoundError:
412
+ # Path doesn't exist, we can use it
413
+ return path
414
+ except Exception as e:
415
+ # Re-raise unexpected errors
416
+ raise RuntimeError(f"An unexpected error occurred while validating the path: {path} ") from e
417
+
418
+
419
+ def _find_app(client: Client, app: str) -> CommunityApp:
420
+ """
421
+ Finds and returns a community app from the manifest by its name.
422
+
423
+ Parameters
424
+ ----------
425
+ client : Client
426
+ The Nextmv Cloud client to use for the request.
427
+ app : str
428
+ The name of the community app to find.
429
+
430
+ Returns
431
+ -------
432
+ CommunityApp
433
+ The community app if found.
434
+
435
+ Raises
436
+ ------
437
+ ValueError
438
+ If the community app is not found.
439
+ """
440
+
441
+ comm_apps = list_community_apps(client)
442
+ for comm_app in comm_apps:
443
+ if comm_app.name == app:
444
+ return comm_app
445
+
446
+ raise ValueError(f"Community app '{app}' not found.")
@@ -225,12 +225,12 @@ class Integration(BaseModel):
225
225
  def new( # noqa: C901
226
226
  cls,
227
227
  client: Client,
228
- name: str,
229
228
  integration_type: IntegrationType | str,
230
229
  exec_types: list[ManifestType | str],
231
230
  provider: IntegrationProvider | str,
232
231
  provider_config: dict[str, Any],
233
232
  integration_id: str | None = None,
233
+ name: str | None = None,
234
234
  description: str | None = None,
235
235
  is_global: bool = False,
236
236
  application_ids: list[str] | None = None,
@@ -243,8 +243,6 @@ class Integration(BaseModel):
243
243
  ----------
244
244
  client : Client
245
245
  Client to use for interacting with the Nextmv Cloud API.
246
- name : str
247
- The name of the integration.
248
246
  integration_type : IntegrationType | str
249
247
  The type of the integration. Please refer to the `IntegrationType`
250
248
  enum for possible values.
@@ -259,6 +257,9 @@ class Integration(BaseModel):
259
257
  integration_id : str, optional
260
258
  The unique identifier of the integration. If not provided,
261
259
  it will be generated automatically.
260
+ name : str | None, optional
261
+ The name of the integration. If not provided, the integration ID
262
+ will be used as the name.
262
263
  description : str, optional
263
264
  An optional description of the integration.
264
265
  is_global : bool, optional, default=False
@@ -302,8 +303,10 @@ class Integration(BaseModel):
302
303
  elif not is_global and application_ids is None:
303
304
  raise ValueError("A non-global integration must have specific application IDs.")
304
305
 
305
- if integration_id is None:
306
+ if integration_id is None or integration_id == "":
306
307
  integration_id = safe_id("integration")
308
+ if name is None or name == "":
309
+ name = integration_id
307
310
 
308
311
  if exist_ok:
309
312
  try:
nextmv/cloud/shadow.py CHANGED
@@ -19,6 +19,7 @@ ShadowTest
19
19
  """
20
20
 
21
21
  from datetime import datetime
22
+ from enum import Enum
22
23
  from typing import Any
23
24
 
24
25
  from pydantic import AliasChoices, Field
@@ -227,3 +228,27 @@ class ShadowTest(BaseModel):
227
228
  """Grouped distributional summaries of the shadow test."""
228
229
  runs: list[Run] | None = None
229
230
  """List of runs in the shadow test."""
231
+
232
+
233
+ class StopIntent(str, Enum):
234
+ """
235
+ Intent for stopping a shadow test.
236
+
237
+ You can import the `StopIntent` class directly from `cloud`:
238
+
239
+ ```python
240
+ from nextmv.cloud import StopIntent
241
+ ```
242
+
243
+ Attributes
244
+ ----------
245
+ complete : str
246
+ The test is marked as complete.
247
+ cancel : str
248
+ The test is canceled.
249
+ """
250
+
251
+ complete = "complete"
252
+ """The test is marked as complete."""
253
+ cancel = "cancel"
254
+ """The test is canceled."""
@@ -45,6 +45,8 @@ class TestComparisonSingle(BaseModel):
45
45
  ID of the candidate instance for comparison.
46
46
  """
47
47
 
48
+ __test__ = False # Prevents pytest from collecting this class as a test case
49
+
48
50
  baseline_instance_id: str
49
51
  """ID of the baseline instance for comparison."""
50
52
  candidate_instance_id: str
nextmv/model.py CHANGED
@@ -18,6 +18,8 @@ deployed to Nextmv Cloud for execution.
18
18
  import logging
19
19
  import os
20
20
  import shutil
21
+ import sqlite3
22
+ import time
21
23
  import warnings
22
24
  from dataclasses import dataclass
23
25
  from typing import Any
@@ -344,6 +346,9 @@ class Model:
344
346
 
345
347
  _cleanup_python_model(model_dir, configuration, verbose=False)
346
348
 
349
+ # Removing this seems to make the "apps from models" experience once
350
+ # again. I am not removing it entirely because we might want to
351
+ # re-introduce it later on.
347
352
  # signature = None
348
353
  # if configuration.options is not None:
349
354
  # options_dict = configuration.options.to_dict()
@@ -359,7 +364,7 @@ class Model:
359
364
  path=model_path, # Customize the name of the model location.
360
365
  infer_code_paths=True, # Makes the imports portable.
361
366
  python_model=MLFlowModel(),
362
- # signature=signature, # Allows us to work with our own `Options` class.
367
+ # signature=signature, # Please see comment above about keeping this in case we need to go back.
363
368
  )
364
369
 
365
370
  # Create an auxiliary requirements file with the model dependencies.
@@ -418,9 +423,7 @@ def _cleanup_python_model(
418
423
  if os.path.exists(model_path):
419
424
  shutil.rmtree(model_path)
420
425
 
421
- mlflow_db_path = os.path.join(model_dir, "mlflow.db")
422
- if os.path.exists(mlflow_db_path):
423
- os.remove(mlflow_db_path)
426
+ _cleanup_mlflow_db(model_dir)
424
427
 
425
428
  requirements_file = os.path.join(model_dir, _REQUIREMENTS_FILE)
426
429
  if os.path.exists(requirements_file):
@@ -432,3 +435,36 @@ def _cleanup_python_model(
432
435
 
433
436
  if verbose:
434
437
  log("🧹 Cleaned up Python model artifacts.")
438
+
439
+
440
+ def _cleanup_mlflow_db(model_dir: str) -> None:
441
+ """
442
+ Clean up the mlflow.db file created during model packaging.
443
+
444
+ Parameters
445
+ ----------
446
+ model_dir : str
447
+ The directory where the model was saved.
448
+ """
449
+ mlflow_db_path = os.path.join(model_dir, "mlflow.db")
450
+ if not os.path.exists(mlflow_db_path):
451
+ return
452
+
453
+ # Try to close any open SQLite connections and retry deletion
454
+ max_retries = 5
455
+ for attempt in range(max_retries):
456
+ try:
457
+ # Attempt to connect and close to release any locks
458
+ try:
459
+ conn = sqlite3.connect(mlflow_db_path)
460
+ conn.close()
461
+ except Exception:
462
+ pass
463
+ os.remove(mlflow_db_path)
464
+ break
465
+ except PermissionError:
466
+ if attempt < max_retries - 1:
467
+ time.sleep(0.5)
468
+ else:
469
+ log(f"Could not delete {mlflow_db_path} after {max_retries} retries due to file lock.")
470
+ break
nextmv/options.py CHANGED
@@ -695,7 +695,7 @@ class Options:
695
695
  help=argparse.SUPPRESS,
696
696
  default="1",
697
697
  )
698
- args = parser.parse_args()
698
+ args, _ = parser.parse_known_args()
699
699
 
700
700
  for arg in vars(args):
701
701
  if arg == "fff" or arg == "f":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nextmv
3
- Version: 1.0.0.dev9
3
+ Version: 1.0.0.dev10
4
4
  Summary: The all-purpose Python SDK for Nextmv
5
5
  Project-URL: Homepage, https://www.nextmv.io
6
6
  Project-URL: Documentation, https://nextmv-py.docs.nextmv.io/en/latest/nextmv/
@@ -230,10 +230,12 @@ Provides-Extra: dev
230
230
  Requires-Dist: build>=1.0.3; extra == 'dev'
231
231
  Requires-Dist: folium>=0.20.0; extra == 'dev'
232
232
  Requires-Dist: mlflow>=3.9.0; extra == 'dev'
233
+ Requires-Dist: nextpipe>=0.6.0; extra == 'dev'
233
234
  Requires-Dist: openpyxl>=3.1.5; extra == 'dev'
234
235
  Requires-Dist: pandas>=2.2.3; extra == 'dev'
235
236
  Requires-Dist: plotly>=6.0.1; extra == 'dev'
236
237
  Requires-Dist: pydantic>=2.5.2; extra == 'dev'
238
+ Requires-Dist: pytest>=9.0.2; extra == 'dev'
237
239
  Requires-Dist: pyyaml>=6.0.1; extra == 'dev'
238
240
  Requires-Dist: requests>=2.31.0; extra == 'dev'
239
241
  Requires-Dist: ruff>=0.1.7; extra == 'dev'