Skip to content

Commit 947db70

Browse files
committed
Added sorted response
1 parent 02d6d4e commit 947db70

File tree

7 files changed

+476
-229
lines changed

7 files changed

+476
-229
lines changed

poetry.lock

Lines changed: 215 additions & 172 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies = [
1919
"toml (>=0.10.2,<0.11.0)",
2020
"regex (>=2024.11.6,<2025.0.0)",
2121
"requests (>=2.32.3,<3.0.0)",
22-
"simvue (>=2.0.0)"
22+
"simvue @ git+https://github.com/simvue-io/python-api@dev",
2323
]
2424

2525
[project.scripts]
@@ -44,6 +44,7 @@ build-backend = "poetry.core.masonry.api"
4444
pytest = "^8.3.4"
4545
pytest-cov = "^6.0.0"
4646
pytest-sugar = "^1.0.0"
47+
pytest-xdist = "^3.6.1"
4748

4849

4950
[tool.poetry.group.lint.dependencies]

simvue_cli/actions.py

Lines changed: 57 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
import io
1212
import pathlib
1313
import json
14+
import sys
1415
import typing
1516
import time
17+
from simvue.exception import ObjectNotFoundError
1618
import toml
1719
import venv
1820
import shutil
@@ -61,7 +63,7 @@ def _check_run_exists(run_id: str) -> tuple[pathlib.Path, Run]:
6163

6264
try:
6365
run = Run(identifier=run_id)
64-
except StopIteration as e:
66+
except ObjectNotFoundError as e:
6567
if run_shelf_file.exists():
6668
run_shelf_file.unlink()
6769
raise ValueError(f"Run '{run_id}' does not exist.") from e
@@ -94,7 +96,7 @@ def create_simvue_run(
9496
timeout: int | None,
9597
retention: int | None,
9698
environment: bool,
97-
) -> str | None:
99+
) -> Run | None:
98100
"""Create and initialise a new Simvue run
99101
100102
Parameters
@@ -120,8 +122,8 @@ def create_simvue_run(
120122
Returns
121123
-------
122124
123-
str | None
124-
Simvue run ID if successful else None
125+
Run | None
126+
Simvue run if successful else None
125127
"""
126128
if folder != "/":
127129
try:
@@ -156,7 +158,7 @@ def create_simvue_run(
156158
indent=2,
157159
)
158160

159-
return _id
161+
return _run
160162

161163

162164
def log_metrics(run_id: str, metrics: dict[str, int | float]) -> None:
@@ -291,40 +293,51 @@ def user_info() -> dict:
291293
return Stats().whoami()
292294

293295

294-
def get_runs_list(**kwargs) -> typing.Generator[tuple[str, Run], None, None]:
296+
def get_runs_list(
297+
sort_by: list[str], reverse: bool, **kwargs
298+
) -> typing.Generator[tuple[str, Run], None, None]:
295299
"""Retrieve list of Simvue runs"""
296-
return Run.get(**kwargs)
300+
_sorting: list[dict[str, str]] = [
301+
{"column": c, "descending": not reverse} for c in sort_by
302+
]
303+
return Run.get(sorting=_sorting, **kwargs)
297304

298305

299306
def get_alerts_list(
300-
**kwargs,
307+
sort_by: list[str], reverse: bool, **kwargs
301308
) -> typing.Generator[
302309
tuple[str, MetricsRangeAlert | MetricsThresholdAlert | EventsAlert | UserAlert],
303310
None,
304311
None,
305312
]:
306313
"""Retrieve list of Simvue alerts"""
307-
return Alert.get(**kwargs)
314+
_sorting: list[dict[str, str]] = [
315+
{"column": c, "descending": not reverse} for c in sort_by
316+
]
317+
return Alert.get(sorting=_sorting, **kwargs)
308318

309319

310-
def get_tag_list(**kwargs) -> None:
320+
def get_tag_list(sort_by: list[str], reverse: bool, **kwargs) -> None:
311321
"""Retrieve list of Simvue tags"""
312-
return Tag.get(**kwargs)
322+
_sorting: list[dict[str, str]] = [
323+
{"column": c, "descending": not reverse} for c in sort_by
324+
]
325+
return Tag.get(sorting=_sorting, **kwargs)
313326

314327

315328
def get_storages_list(**kwargs) -> typing.Generator[tuple[str, Storage], None, None]:
316329
"""Retrieve list of Simvue storages"""
317330
return Storage.get(**kwargs)
318331

319332

320-
def get_storage_list(**kwargs) -> None:
321-
"""Retrieve list of Simvue storages"""
322-
return Storage.get(**kwargs)
323-
324-
325-
def get_folders_list(**kwargs) -> None:
326-
"""Retrieve list of Simvue runs"""
327-
return Folder.get(**kwargs)
333+
def get_folders_list(
334+
sort_by: list[str], reverse: bool, **kwargs
335+
) -> typing.Generator[tuple[str, Run], None, None]:
336+
"""Retrieve list of Simvue folders"""
337+
_sorting: list[dict[str, str]] = [
338+
{"column": c, "descending": not reverse} for c in sort_by
339+
]
340+
return Folder.get(sorting=_sorting, **kwargs)
328341

329342

330343
def get_tenants_list(**kwargs) -> typing.Generator[tuple[str, Tenant], None, None]:
@@ -337,9 +350,14 @@ def get_users_list(**kwargs) -> typing.Generator[tuple[str, User], None, None]:
337350
return User.get(**kwargs)
338351

339352

340-
def get_artifacts_list(**kwargs) -> typing.Generator[tuple[str, Artifact], None, None]:
353+
def get_artifacts_list(
354+
sort_by: list[str], reverse: bool, **kwargs
355+
) -> typing.Generator[tuple[str, Artifact], None, None]:
341356
"""Retrieve list of Simvye artifacts"""
342-
return Artifact.get(**kwargs)
357+
_sorting: list[dict[str, str]] = [
358+
{"column": c, "descending": not reverse} for c in sort_by
359+
]
360+
return Artifact.get(sorting=_sorting, **kwargs)
343361

344362

345363
def get_run(run_id: str) -> Run:
@@ -370,7 +388,7 @@ def create_simvue_s3_storage(
370388
access_key_file: io.BytesIO,
371389
block_tenant: bool,
372390
**kwargs,
373-
) -> str:
391+
) -> S3Storage:
374392
_secret_key: str = access_key_file.read()
375393
_storage = S3Storage.new(
376394
is_enabled=not disable,
@@ -380,7 +398,7 @@ def create_simvue_s3_storage(
380398
**kwargs,
381399
)
382400
_storage.commit()
383-
return _storage.id
401+
return _storage
384402

385403

386404
def create_user_alert(
@@ -424,7 +442,7 @@ def create_simvue_user(
424442
read_only: bool,
425443
tenant: str,
426444
welcome: bool,
427-
) -> str:
445+
) -> User:
428446
"""Create a new Simvue user on the server.
429447
430448
Parameters
@@ -451,8 +469,8 @@ def create_simvue_user(
451469
452470
Returns
453471
-------
454-
str
455-
the unique identifier for the user
472+
User
473+
the user object
456474
"""
457475
_user = User.new(
458476
username=username,
@@ -467,7 +485,7 @@ def create_simvue_user(
467485
)
468486
_user.commit()
469487

470-
return _user.id
488+
return _user
471489

472490

473491
def create_simvue_tenant(
@@ -476,7 +494,7 @@ def create_simvue_tenant(
476494
max_runs: int,
477495
max_request_rate: int,
478496
max_data_volume: int,
479-
) -> str:
497+
) -> Tenant:
480498
"""Create a Tenant on the simvue server.
481499
482500
Parameters
@@ -494,8 +512,8 @@ def create_simvue_tenant(
494512
495513
Returns
496514
-------
497-
str
498-
the unique identifer for the user
515+
Tenant
516+
the tenant object
499517
"""
500518
_tenant = Tenant.new(
501519
name=name,
@@ -505,7 +523,7 @@ def create_simvue_tenant(
505523
max_data_volume=max_data_volume or 0,
506524
)
507525
_tenant.commit()
508-
return _tenant.id
526+
return _tenant
509527

510528

511529
def get_tenant(tenant_id: str) -> Tenant:
@@ -617,4 +635,11 @@ def create_environment(
617635

618636
toml.dump(_toml_data, _toml_file.open("w"))
619637

620-
subprocess.run([_cargo_path, "build"], cwd=venv_directory)
638+
_process = subprocess.Popen(
639+
[_cargo_path, "build"],
640+
cwd=venv_directory,
641+
stdout=subprocess.PIPE,
642+
stderr=subprocess.STDOUT,
643+
)
644+
for c in iter(lambda: _process.stdout.read(1), b""):
645+
sys.stdout.buffer.write(c)

0 commit comments

Comments
 (0)