Skip to content

Commit b5faa91

Browse files
committed
Further docs modifications
1 parent 3d430a7 commit b5faa91

File tree

7 files changed

+150
-8
lines changed

7 files changed

+150
-8
lines changed

simvue/api/objects/artifact/fetch.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
class Artifact:
1616
"""Generic Simvue artifact retrieval class"""
1717

18+
def __init__(self, identifier: str | None = None, *args, **kwargs) -> None:
19+
"""Initialise an instance of generic artifact retriever.
20+
21+
Parameters
22+
----------
23+
identifier : str
24+
identifier of artifact object to retrieve
25+
"""
26+
super().__init__(identifier=identifier, *args, **kwargs)
27+
1828
def __new__(cls, identifier: str | None = None, **kwargs):
1929
"""Retrieve an object representing an Artifact by id"""
2030
_artifact_pre = ArtifactBase(identifier=identifier, **kwargs)
@@ -86,6 +96,20 @@ def from_run(
8696
def from_name(
8797
cls, run_id: str, name: str, **kwargs
8898
) -> typing.Union[FileArtifact | ObjectArtifact, None]:
99+
"""Retrieve an artifact by name.
100+
101+
Parameters
102+
----------
103+
run_id : str
104+
the identifier of the run to retrieve from.
105+
name : str
106+
the name of the artifact to retrieve.
107+
108+
Returns
109+
-------
110+
FileArtifact | ObjectArtifact | None
111+
the artifact if found
112+
"""
89113
_temp = ArtifactBase(**kwargs)
90114
_url = URL(_temp._user_config.server.url) / f"runs/{run_id}/artifacts"
91115
_response = sv_get(url=f"{_url}", params={"name": name}, headers=_temp._headers)

simvue/api/objects/base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,13 @@ def _get_all_objects(
443443
)
444444

445445
def read_only(self, is_read_only: bool) -> None:
446+
"""Set whether this object is in read only state.
447+
448+
Parameters
449+
----------
450+
is_read_only : bool
451+
whether object is read only.
452+
"""
446453
self._read_only = is_read_only
447454

448455
# If using writable mode, clear the staging dictionary as
@@ -649,6 +656,10 @@ def to_dict(self) -> dict[str, typing.Any]:
649656
return self._get() | self._staging
650657

651658
def on_reconnect(self, id_mapping: dict[str, str]) -> None:
659+
"""Executed when a run switches from offline to online mode.
660+
661+
In this case no action is taken.
662+
"""
652663
pass
653664

654665
@property

simvue/api/objects/metrics.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,27 @@ def _post(self, **kwargs) -> dict[str, typing.Any]:
139139
return super()._post(is_json=False, **kwargs)
140140

141141
def delete(self, **kwargs) -> dict[str, typing.Any]:
142+
"""Metrics cannot be deleted"""
142143
raise NotImplementedError("Cannot delete metric set")
143144

144145
def on_reconnect(self, id_mapping: dict[str, str]):
146+
"""Action performed when mode switched from offline to online.
147+
148+
Parameters
149+
----------
150+
id_mapping : dict[str, str]
151+
mapping from offline to online identifier.
152+
153+
"""
145154
if online_run_id := id_mapping.get(self._staging["run"]):
146155
self._staging["run"] = online_run_id
147156

148157
def to_dict(self) -> dict[str, typing.Any]:
158+
"""Convert metrics object to dictionary.
159+
160+
Returns
161+
-------
162+
dict[str, Any]
163+
dictionary representation of metrics object.
164+
"""
149165
return self._staging

simvue/api/objects/stats.py

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Stats(SimvueObject):
2020
"""Class for accessing Server statistics."""
2121

2222
def __init__(self) -> None:
23+
"""Initialise a statistics query object."""
2324
self.runs = RunStatistics(self)
2425
self._label = "stat"
2526
super().__init__()
@@ -30,11 +31,76 @@ def __init__(self) -> None:
3031

3132
@classmethod
3233
def new(cls, **kwargs) -> None:
33-
"""Creation of multiple stats objects is not logical here"""
34+
"""Creation of multiple stats objects is not logical here.
35+
36+
Raises
37+
------
38+
AttributeError
39+
"""
3440
raise AttributeError("Creation of statistics objects is not supported")
3541

42+
@classmethod
43+
def delete(cls, **kwargs) -> None:
44+
"""Deletion of stats object is not logical here.
45+
46+
Raises
47+
------
48+
AttributeError
49+
"""
50+
raise AttributeError("Deletion of statistics is not supported")
51+
52+
def read_only(self) -> None:
53+
"""Statistics can only be read-only.
54+
55+
Raises
56+
------
57+
NotImplementedError
58+
"""
59+
raise NotImplementedError("Statistics are not modifiable.")
60+
61+
def id(self) -> None:
62+
"""No unique indentifier for statistics retrieval.
63+
64+
Returns
65+
-------
66+
None
67+
"""
68+
return None
69+
70+
def on_reconnect(self, **_) -> None:
71+
"""No offline to online reconnect functionality for statistics."""
72+
pass
73+
74+
@classmethod
75+
def get(cls, **kwargs) -> None:
76+
"""Retrieval of multiple stats object is not logical here.
77+
78+
Raises
79+
------
80+
AttributeError
81+
"""
82+
raise AttributeError(
83+
"Retrieval of multiple of statistics objects is not supported"
84+
)
85+
86+
@classmethod
87+
def ids(cls, **kwargs) -> None:
88+
"""Retrieval of identifiers is not logical here.
89+
90+
Raises
91+
------
92+
AttributeError
93+
"""
94+
raise AttributeError("Retrieval of ids for statistics objects is not supported")
95+
3696
def whoami(self) -> dict[str, str]:
37-
"""Return the current user"""
97+
"""Return the current user information.
98+
99+
Returns
100+
-------
101+
dict[str, str]
102+
server response for 'whomai' query.
103+
"""
38104
_url: URL = URL(self._user_config.server.url) / "whoami"
39105
_response = sv_get(url=f"{_url}", headers=self._headers)
40106
return get_json_from_response(
@@ -56,9 +122,19 @@ def _get_visibility(self) -> dict[str, bool | list[str]]:
56122
return {}
57123

58124
def to_dict(self) -> dict[str, typing.Any]:
59-
"""Returns dictionary form of statistics"""
125+
"""Dictionary form of statistics.
126+
127+
Returns
128+
-------
129+
doct[str, Any]
130+
statistics data as dictionary
131+
"""
60132
return {"runs": self._get_run_stats()}
61133

134+
def commit(self) -> None:
135+
"""Does nothing, no data sendable to server."""
136+
pass
137+
62138

63139
class RunStatistics:
64140
"""Interface to the run section of statistics output"""

simvue/api/objects/storage/fetch.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
class Storage:
2222
"""Generic Simvue storage retrieval class"""
2323

24+
def __init__(self, identifier: str | None = None, *args, **kwargs) -> None:
25+
"""Initialise an instance of generic storage retriever.
26+
27+
Parameters
28+
----------
29+
identifier : str
30+
identifier of storage object to retrieve
31+
"""
32+
super().__init__(identifier=identifier, *args, **kwargs)
33+
2434
def __new__(cls, identifier: str | None = None, **kwargs):
2535
"""Retrieve an object representing an storage either locally or on the server by id"""
2636
_storage_pre = StorageBase(identifier=identifier, **kwargs)

simvue/api/objects/storage/file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ def new(
4242
name to allocated to this storage system
4343
disable_check : bool
4444
whether to disable checks for this system
45-
tenant_usable : bool
45+
is_tenant_useable : bool
4646
whether this system is usable by the current tenant
4747
is_enabled : bool
4848
whether to enable this system
49-
default : bool
49+
is_default : bool
5050
if this storage system should become the new default
5151
offline : bool, optional
5252
if this instance should be created in offline mode, default False

simvue/api/objects/storage/s3.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def new(
6464
the secret access key, stored as a secret string
6565
bucket : str
6666
the bucket associated with this storage system
67-
tenant_usable : bool
67+
is_tenant_useable : bool
6868
whether this system is usable by the current tenant
6969
is_enabled : bool
7070
whether to enable this system
@@ -119,7 +119,13 @@ def __init__(self, storage: S3Storage) -> None:
119119
@property
120120
@staging_check
121121
def endpoint_url(self) -> str:
122-
"""Retrieve the endpoint URL for this storage"""
122+
"""Set/retrieve the endpoint URL for this storage.
123+
124+
Returns
125+
-------
126+
str
127+
the endpoint for this storage object
128+
"""
123129
try:
124130
return self._sv_obj.get_config()["endpoint_url"]
125131
except KeyError as e:
@@ -131,7 +137,6 @@ def endpoint_url(self) -> str:
131137
@write_only
132138
@pydantic.validate_call
133139
def endpoint_url(self, endpoint_url: pydantic.HttpUrl) -> None:
134-
"""Modify the endpoint URL for this storage"""
135140
_config = self._sv_obj.get_config() | {"endpoint_url": endpoint_url.__str__()}
136141
self._sv_obj._staging["config"] = _config
137142

0 commit comments

Comments
 (0)