Skip to content

Commit 8aec582

Browse files
committed
Switch to UV, fix tests and bugs in version retrieval
1 parent 947db70 commit 8aec582

File tree

15 files changed

+1223
-2381
lines changed

15 files changed

+1223
-2381
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,9 @@ poetry.toml
174174
pyrightconfig.json
175175

176176
# End of https://www.toptal.com/developers/gitignore/api/python
177+
178+
# Simvue
179+
simvue.ini
180+
simvue.toml
181+
182+
.sourcery.yaml

poetry.lock

Lines changed: 0 additions & 2341 deletions
This file was deleted.

pyproject.toml

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@ description = "Command Line Interface for interaction with a Simvue v3 server"
55
authors = [
66
{name = "Kristian Zarębski",email = "[email protected]"}
77
]
8-
license = {text = "Apache-v2"}
8+
license-files = ["LICENSE"]
99
readme = "README.md"
1010
requires-python = ">=3.10,<3.14"
1111
dependencies = [
12-
"click (>=8.1.8,<9.0.0)",
13-
"click-option-group (>=0.5.6,<0.6.0)",
14-
"click-log (>=0.4.0,<0.5.0)",
15-
"click-params (>=0.5.0,<0.6.0)",
16-
"click-man (>=0.5.0,<0.6.0)",
17-
"pytermgui (>=7.7.3,<8.0.0)",
18-
"tabulate (>=0.9.0,<0.10.0)",
19-
"toml (>=0.10.2,<0.11.0)",
20-
"regex (>=2024.11.6,<2025.0.0)",
21-
"requests (>=2.32.3,<3.0.0)",
22-
"simvue @ git+https://github.com/simvue-io/python-api@dev",
12+
"click-option-group>=0.5.7",
13+
"click>=8.1.8",
14+
"simvue>=2.1.0",
15+
"click-log>=0.4.0",
16+
"click-params>=0.5.0",
17+
"toml>=0.10.2",
18+
"tabulate>=0.9.0",
19+
"regex>=2024.11.6",
20+
"requests>=2.32.3",
2321
]
2422

2523
[project.scripts]
@@ -28,7 +26,7 @@ simvue = "simvue_cli.cli:simvue"
2826
[tool.ruff]
2927
lint.extend-select = ["C901", "T201"]
3028
lint.mccabe.max-complexity = 11
31-
extend-exclude = ["tests", "examples", "notebooks"]
29+
extend-exclude = ["tests"]
3230

3331
[tool.pytest.ini_options]
3432
addopts = "--no-cov"
@@ -37,16 +35,14 @@ testpaths = [
3735
]
3836

3937
[build-system]
40-
requires = ["poetry-core>=2.0.0,<3.0.0"]
41-
build-backend = "poetry.core.masonry.api"
42-
43-
[tool.poetry.group.testing.dependencies]
44-
pytest = "^8.3.4"
45-
pytest-cov = "^6.0.0"
46-
pytest-sugar = "^1.0.0"
47-
pytest-xdist = "^3.6.1"
48-
49-
50-
[tool.poetry.group.lint.dependencies]
51-
ruff = "^0.9.3"
38+
requires = ["hatchling"]
39+
build-backend = "hatchling.build"
5240

41+
[dependency-groups]
42+
dev = [
43+
"pytest-cov>=6.0.0",
44+
"pytest>=8.3.5",
45+
]
46+
lint = [
47+
"ruff>=0.11.2",
48+
]
File renamed without changes.

simvue_cli/actions.py renamed to src/simvue_cli/actions.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,14 @@ def _check_run_exists(run_id: str) -> tuple[pathlib.Path, Run]:
7777
# retrieve last time step, and the start time of the run
7878
if not run_shelf_file.exists():
7979
out_data = {"step": 0, "start_time": time.time()}
80-
if step := max(metric.get("step", 0) for _, metric in run.metrics or {}):
81-
out_data["step"] = step
82-
if time_now := min(metric.get("time", 0) for _, metric in run.metrics or {}):
83-
out_data["start_time"] = time_now
80+
_metric_steps: list[int] = [
81+
metric.get("step", 0) for _, metric in run.metrics or []
82+
]
83+
_times: list[int] = [metric.get("time", 0) for _, metric in run.metrics or []]
84+
if _metric_steps:
85+
out_data["step"] = max(_metric_steps)
86+
if _times:
87+
out_data["start_time"] = min(_times)
8488
with run_shelf_file.open("w") as out_f:
8589
json.dump(out_data, out_f)
8690

@@ -275,7 +279,7 @@ def get_server_version() -> typing.Union[str, int]:
275279
failed HTTP request
276280
"""
277281
_url, _headers = get_url_and_headers()
278-
response = sv_api.get(f"{_url}/api/version", headers=_headers)
282+
response = sv_api.get(f"{_url}/version", headers=_headers)
279283
if response.status_code != 200:
280284
return response.status_code
281285

simvue_cli/cli/__init__.py renamed to src/simvue_cli/cli/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -749,11 +749,11 @@ def monitor(ctx, tag: tuple[str, ...] | None, delimiter: str, **run_params) -> N
749749
metric_labels: list[str] = []
750750
run_params |= {"tags": list(tag) if tag else None}
751751

752-
run_id: str | None = simvue_cli.actions.create_simvue_run(
752+
run: Run | None = simvue_cli.actions.create_simvue_run(
753753
timeout=None, running=True, **run_params
754754
)
755755

756-
if not run_id:
756+
if not run:
757757
raise click.Abort("Failed to create run")
758758

759759
try:
@@ -764,19 +764,19 @@ def monitor(ctx, tag: tuple[str, ...] | None, delimiter: str, **run_params) -> N
764764
continue
765765
try:
766766
simvue_cli.actions.log_metrics(
767-
run_id, dict(zip(metric_labels, [float(i) for i in line]))
767+
run.id, dict(zip(metric_labels, [float(i) for i in line]))
768768
)
769769
except (RuntimeError, ValueError) as e:
770770
if ctx.obj["plain"]:
771771
click.echo(e)
772772
else:
773773
click.secho(e, fg="red", bold=True)
774774
sys.exit(1)
775-
click.echo(run_id)
775+
click.echo(run.id)
776776
except KeyboardInterrupt as e:
777-
simvue_cli.actions.set_run_status(run_id, "terminated")
777+
simvue_cli.actions.set_run_status(run.id, "terminated")
778778
raise click.Abort from e
779-
simvue_cli.actions.set_run_status(run_id, "completed")
779+
simvue_cli.actions.set_run_status(run.id, "completed")
780780

781781

782782
@simvue.group("folder")
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/simvue_cli/tree.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import json
2+
import typing
3+
import pydantic
4+
import simvue.api.objects as sv_obj
5+
from simvue.models import FOLDER_REGEX
6+
7+
8+
def hierarchy(path: typing.Annotated[str, pydantic.Field(pattern=FOLDER_REGEX)]) -> str:
9+
_hierarchical_structure = {}
10+
for _, folder in sv_obj.Folder.get(
11+
filters=json.dumps([f"path contains {path}"]),
12+
sorting=[{"column": "created", "descending": True}],
13+
):
14+
_components = folder.path.strip("/").split("/")
15+
_node = _hierarchical_structure
16+
for i, _component in enumerate(_components):
17+
if _component not in _node:
18+
_node[_component] = {}
19+
_node = _node[_component]
20+
21+
for entry
22+
return _hierarchical_structure
23+
24+
25+
if __name__ in "__main__":
26+
print(hierarchy("/simvue_unit_tests"))

0 commit comments

Comments
 (0)