Skip to content

Fix missing docstrings due to decoration #359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pytest-cov = ">=4.1,<6.0"
pytest-mock = "^3.14.0"
pytest-sugar = "^1.0.0"
pytest-xdist = "^3.6.1"
jinja2 = "^3.1.4"

[build-system]
requires = ["poetry-core"]
Expand Down
6 changes: 3 additions & 3 deletions simvue/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def get_runs(
alerts : bool, optional
whether to include alert information in the response.
Default False.
format : str ('dict' | 'dataframe'), optional
format : Literal['dict', 'dataframe'], optional
the structure of the response, either a dictionary or a dataframe.
Default is 'dict'. Pandas must be installed for 'dataframe'.
count : int, optional
Expand Down Expand Up @@ -932,9 +932,9 @@ def get_metric_values(
----------
metric_names : list[str]
the names of metrics to return values for
xaxis : str ('step' | 'time' | 'timestamp')
xaxis : Literal['step', 'time', 'timestamp']
the xaxis type
output_format : str ('dataframe' | 'list')
output_format : Literal['dataframe', 'list']
the format of the output, either a list or a Pandas dataframe
run_ids : list[str], optional
list of runs by id to include within metric retrieval
Expand Down
29 changes: 15 additions & 14 deletions simvue/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import re
import sys
import time
import functools
import platform
import typing
import uuid
Expand Down Expand Up @@ -63,6 +64,7 @@
def check_run_initialised(
function: typing.Callable[..., typing.Any],
) -> typing.Callable[..., typing.Any]:
@functools.wraps(function)
def _wrapper(self: "Run", *args: typing.Any, **kwargs: typing.Any) -> typing.Any:
if not self._simvue:
raise RuntimeError(
Expand All @@ -71,8 +73,6 @@ def _wrapper(self: "Run", *args: typing.Any, **kwargs: typing.Any) -> typing.Any
)
return function(self, *args, **kwargs)

_wrapper.__name__ = f"{function.__name__}__init_locked"

return _wrapper


Expand Down Expand Up @@ -838,8 +838,8 @@ def config(

return True

@check_run_initialised
@skip_if_failed("_aborted", "_suppress_errors", False)
@check_run_initialised
@pydantic.validate_call
def update_metadata(self, metadata: dict[str, typing.Any]) -> bool:
"""
Expand All @@ -864,8 +864,8 @@ def update_metadata(self, metadata: dict[str, typing.Any]) -> bool:

return False

@check_run_initialised
@skip_if_failed("_aborted", "_suppress_errors", False)
@check_run_initialised
@pydantic.validate_call
def update_tags(self, tags: list[str]) -> bool:
"""
Expand All @@ -885,8 +885,8 @@ def update_tags(self, tags: list[str]) -> bool:

return False

@check_run_initialised
@skip_if_failed("_aborted", "_suppress_errors", False)
@check_run_initialised
@pydantic.validate_call
def log_event(self, message, timestamp: typing.Optional[str] = None) -> bool:
"""
Expand Down Expand Up @@ -960,8 +960,8 @@ def _add_metrics_to_dispatch(

return True

@check_run_initialised
@skip_if_failed("_aborted", "_suppress_errors", False)
@check_run_initialised
@pydantic.validate_call
def log_metrics(
self,
Expand All @@ -979,8 +979,8 @@ def log_metrics(
self._step += 1
return add_dispatch

@check_run_initialised
@skip_if_failed("_aborted", "_suppress_errors", False)
@check_run_initialised
@pydantic.validate_call
def save_object(
self,
Expand Down Expand Up @@ -1035,6 +1035,7 @@ def save_object(
return self._simvue is not None and self._simvue.save_file(data) is not None

@skip_if_failed("_aborted", "_suppress_errors", False)
@check_run_initialised
@pydantic.validate_call
def save_file(
self,
Expand Down Expand Up @@ -1118,8 +1119,8 @@ def save_file(
# Register file
return self._simvue.save_file(data) is not None

@check_run_initialised
@skip_if_failed("_aborted", "_suppress_errors", False)
@check_run_initialised
@pydantic.validate_call
def save_directory(
self,
Expand Down Expand Up @@ -1155,8 +1156,8 @@ def save_directory(

return True

@check_run_initialised
@skip_if_failed("_aborted", "_suppress_errors", False)
@check_run_initialised
@pydantic.validate_call
def save_all(
self,
Expand Down Expand Up @@ -1186,8 +1187,8 @@ def save_all(

return True

@check_run_initialised
@skip_if_failed("_aborted", "_suppress_errors", False)
@check_run_initialised
@pydantic.validate_call
def set_status(
self, status: typing.Literal["completed", "failed", "terminated"]
Expand Down Expand Up @@ -1256,8 +1257,8 @@ def close(self) -> bool:

return True

@check_run_initialised
@skip_if_failed("_aborted", "_suppress_errors", False)
@check_run_initialised
@pydantic.validate_call
def set_folder_details(
self,
Expand Down Expand Up @@ -1311,8 +1312,8 @@ def set_folder_details(

return False

@check_run_initialised
@skip_if_failed("_aborted", "_suppress_errors", False)
@check_run_initialised
@pydantic.validate_call
def add_alerts(
self,
Expand Down Expand Up @@ -1359,8 +1360,8 @@ def add_alerts(

return False

@check_run_initialised
@skip_if_failed("_aborted", "_suppress_errors", None)
@check_run_initialised
@pydantic.validate_call
def create_alert(
self,
Expand Down Expand Up @@ -1521,8 +1522,8 @@ def create_alert(

return alert_id

@check_run_initialised
@skip_if_failed("_aborted", "_suppress_errors", False)
@check_run_initialised
@pydantic.validate_call
def log_alert(
self, identifier: str, state: typing.Literal["ok", "critical"]
Expand Down
5 changes: 4 additions & 1 deletion simvue/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tabulate
import pydantic
import importlib.util
import functools
import contextlib
import os
import typing
Expand Down Expand Up @@ -77,6 +78,7 @@ def check_extra(extra_name: str) -> typing.Callable:
def decorator(
class_func: typing.Optional[typing.Callable] = None,
) -> typing.Optional[typing.Callable]:
@functools.wraps(class_func)
def wrapper(self, *args, **kwargs) -> typing.Any:
if extra_name == "plot" and not all(
[
Expand Down Expand Up @@ -129,6 +131,7 @@ def skip_if_failed(
"""

def decorator(class_func: typing.Callable) -> typing.Callable:
@functools.wraps(class_func)
def wrapper(self, *args, **kwargs) -> typing.Any:
if getattr(self, failure_attr, None) and getattr(
self, ignore_exc_attr, None
Expand Down Expand Up @@ -158,7 +161,7 @@ def wrapper(self, *args, **kwargs) -> typing.Any:
return on_failure_return
raise RuntimeError(err_str)

wrapper.__name__ = f"{class_func.__name__}__fail_safe"
setattr(wrapper, "__fail_safe", True)
return wrapper

return decorator
Expand Down
2 changes: 1 addition & 1 deletion tests/refactor/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_executor_add_process(
completion_trigger = multiprocessing.Event()
run.init(
f"test_executor_{'success' if successful else 'fail'}",
tags=["simvue_client_unit_tests", request.node.name],
tags=["simvue_client_unit_tests", request.node.name.replace("[", "_").replace("]", "_")],
folder="/simvue_unit_testing"
)

Expand Down
16 changes: 8 additions & 8 deletions tests/refactor/test_run_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_log_metrics(
with pytest.raises(RuntimeError):
run.init(
name=f"test_run_{str(uuid.uuid4()).split('-', 1)[0]}",
tags=["simvue_client_unit_tests", request.node.name],
tags=["simvue_client_unit_tests", request.node.name.replace("[", "_").replace("]", "_")],
folder="/simvue_unit_testing",
retention_period="1 hour",
visibility=visibility,
Expand All @@ -60,7 +60,7 @@ def test_log_metrics(

run.init(
name=f"test_run_{str(uuid.uuid4()).split('-', 1)[0]}",
tags=["simvue_client_unit_tests", request.node.name],
tags=["simvue_client_unit_tests", request.node.name.replace("[", "_").replace("]", "_")],
folder="/simvue_unit_testing",
visibility=visibility,
resources_metrics_interval=1,
Expand Down Expand Up @@ -155,7 +155,7 @@ def thread_func(index: int) -> tuple[int, list[dict[str, typing.Any]], str]:
run.config(suppress_errors=False)
run.init(
name=f"test_runs_multiple_{index + 1}",
tags=["simvue_client_unit_tests", request.node.name],
tags=["simvue_client_unit_tests", request.node.name.replace("[", "_").replace("]", "_")],
folder="/simvue_unit_testing",
retention_period="1 hour",
)
Expand Down Expand Up @@ -192,7 +192,7 @@ def thread_func(index: int) -> tuple[int, list[dict[str, typing.Any]], str]:
run_1.config(suppress_errors=False)
run_1.init(
name="test_runs_multiple_unthreaded_1",
tags=["simvue_client_unit_tests", request.node.name],
tags=["simvue_client_unit_tests", request.node.name.replace("[", "_").replace("]", "_")],
folder="/simvue_unit_testing",
retention_period="1 hour",
)
Expand Down Expand Up @@ -246,7 +246,7 @@ def test_runs_multiple_series(request: pytest.FixtureRequest) -> None:
run.config(suppress_errors=False)
run.init(
name=f"test_runs_multiple_series_{index}",
tags=["simvue_client_unit_tests", request.node.name],
tags=["simvue_client_unit_tests", request.node.name.replace("[", "_").replace("]", "_")],
folder="/simvue_unit_testing",
retention_period="1 hour",
)
Expand Down Expand Up @@ -288,15 +288,15 @@ def test_suppressed_errors(
decorated_funcs = [
name
for name, method in inspect.getmembers(run, inspect.ismethod)
if method.__name__.endswith("__fail_safe")
if hasattr(method, "__fail_safe")
]

if post_init:
decorated_funcs.remove("init")
run.init(
name="test_suppressed_errors",
folder="/simvue_unit_testing",
tags=["simvue_client_unit_tests", request.node.name],
tags=["simvue_client_unit_tests", request.node.name.replace("[", "_").replace("]", "_")],
retention_period="1 hour"
)

Expand All @@ -323,7 +323,7 @@ def test_set_folder_details(request: pytest.FixtureRequest) -> None:
with sv_run.Run() as run:
folder_name: str ="/simvue_unit_tests"
description: str = "test description"
tags: list[str] = ["simvue_client_unit_tests", request.node.name]
tags: list[str] = ["simvue_client_unit_tests", request.node.name.replace("[", "_").replace("]", "_")]
run.init(folder=folder_name)
run.set_folder_details(path=folder_name, tags=tags, description=description)

Expand Down
Loading