Skip to content

Commit 303f4ca

Browse files
committed
Merge branch 'dev' into 296-ensure-all-examples-are-up-to-date-and-verified
2 parents 598c9d6 + 13e35bf commit 303f4ca

File tree

7 files changed

+136
-100
lines changed

7 files changed

+136
-100
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ repos:
2323
args: [--branch, main, --branch, dev]
2424
- id: check-added-large-files
2525
- repo: https://github.com/astral-sh/ruff-pre-commit
26-
rev: v0.4.5
26+
rev: v0.4.7
2727
hooks:
2828
- id: ruff
2929
args: [ --fix, --exit-non-zero-on-fix, "--ignore=C901" ]

poetry.lock

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

simvue/api.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,22 @@ def post(
8383
if response.status_code == 422:
8484
_parsed_response = parse_validation_response(response.json())
8585
raise ValueError(
86-
f"Validation error [{response.status_code}]:\n{_parsed_response}"
86+
f"Validation error for '{url}' [{response.status_code}]:\n{_parsed_response}"
8787
)
8888

8989
if response.status_code not in (200, 201, 409):
90-
raise RuntimeError(f"HTTP error [{response.status_code}]: {response.text}")
90+
raise RuntimeError(
91+
f"HTTP error for '{url}' [{response.status_code}]: {response.text}"
92+
)
9193

9294
return response
9395

9496

9597
@retry(
9698
wait=wait_exponential(multiplier=RETRY_MULTIPLIER, min=RETRY_MIN, max=RETRY_MAX),
97-
# retry=retry_if_not_exception_message(match="Validation error"), # if validation failed no point in retrying
99+
retry=retry_if_exception_type(RuntimeError),
98100
stop=stop_after_attempt(RETRY_STOP),
101+
reraise=True,
99102
)
100103
def put(
101104
url: str,
@@ -104,7 +107,7 @@ def put(
104107
is_json: bool = True,
105108
timeout: int = DEFAULT_API_TIMEOUT,
106109
) -> requests.Response:
107-
"""HTTP POST with retries
110+
"""HTTP PUT with retries
108111
109112
Parameters
110113
----------

simvue/executor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def _execute_process(
4747
)
4848

4949
_status_code = _result.wait()
50-
5150
with open(f"{runner_name}_{proc_id}.err") as err:
5251
std_err[proc_id] = err.read()
5352

simvue/factory/proxy/offline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def send_heartbeat(self) -> typing.Optional[dict[str, typing.Any]]:
203203
logger.debug(
204204
f"Creating heartbeat file: {os.path.join(self._directory, 'heartbeat')}"
205205
)
206-
pathlib.Path(os.path.join(self._directory, "heartbeat"), "a").touch()
206+
pathlib.Path(os.path.join(self._directory, "heartbeat")).touch()
207207
return {"success": True}
208208

209209
@skip_if_failed("_aborted", "_suppress_errors", False)

simvue/serialization.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ def _serialize_plotly_figure(data: typing.Any) -> typing.Optional[tuple[str, str
9999
return None
100100
mimetype = "application/vnd.plotly.v1+json"
101101
data = plotly.io.to_json(data, engine="json")
102+
mfile = BytesIO()
103+
mfile.write(data.encode())
104+
mfile.seek(0)
105+
data = mfile.read()
102106
return data, mimetype
103107

104108

@@ -110,6 +114,10 @@ def _serialize_matplotlib(data: typing.Any) -> typing.Optional[tuple[str, str]]:
110114
return None
111115
mimetype = "application/vnd.plotly.v1+json"
112116
data = plotly.io.to_json(plotly.tools.mpl_to_plotly(data.gcf()), engine="json")
117+
mfile = BytesIO()
118+
mfile.write(data.encode())
119+
mfile.seek(0)
120+
data = mfile.read()
113121
return data, mimetype
114122

115123

@@ -121,6 +129,10 @@ def _serialize_matplotlib_figure(data: typing.Any) -> typing.Optional[tuple[str,
121129
return None
122130
mimetype = "application/vnd.plotly.v1+json"
123131
data = plotly.io.to_json(plotly.tools.mpl_to_plotly(data), engine="json")
132+
mfile = BytesIO()
133+
mfile.write(data.encode())
134+
mfile.seek(0)
135+
data = mfile.read()
124136
return data, mimetype
125137

126138

@@ -161,8 +173,11 @@ def _serialize_torch_tensor(data: typing.Any) -> typing.Optional[tuple[str, str]
161173
def _serialize_json(data: typing.Any) -> typing.Optional[tuple[str, str]]:
162174
mimetype = "application/json"
163175
try:
164-
data = json.dumps(data)
165-
except TypeError:
176+
mfile = BytesIO()
177+
mfile.write(json.dumps(data).encode())
178+
mfile.seek(0)
179+
data = mfile.read()
180+
except (TypeError, json.JSONDecodeError):
166181
return None
167182
return data, mimetype
168183

tests/refactor/test_executor.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
import tempfile
66
import pathlib
7+
import os
78
import multiprocessing
89

910

@@ -37,13 +38,31 @@ def test_executor_add_process(
3738
with pytest.raises(SystemExit):
3839
run.close()
3940

40-
time.sleep(1)
41-
client = simvue.Client()
42-
_events = client.get_events(
43-
run._id,
44-
message_contains="successfully" if successful else "non-zero exit",
45-
)
46-
assert len(_events) == 1
41+
42+
@pytest.mark.executor
43+
def test_executor_multiprocess(request: pytest.FixtureRequest) -> None:
44+
with tempfile.TemporaryDirectory() as tempd:
45+
with simvue.Run() as run:
46+
run.init(
47+
"test_executor_multiprocess",
48+
folder="/simvue_unit_testing",
49+
tags=["simvue_client_tests", request.node.name]
50+
)
51+
52+
for i in range(10):
53+
out_file = pathlib.Path(tempd).joinpath(f"out_file_{i}.dat")
54+
run.add_process(
55+
f"cmd_{i}",
56+
executable="bash",
57+
c="for i in {0..10}; do sleep 0.5; echo $i >> "+ f"{out_file}; done"
58+
)
59+
time.sleep(1)
60+
for i in range(10):
61+
out_file = pathlib.Path(tempd).joinpath(f"out_file_{i}.dat")
62+
assert out_file.exists()
63+
for i in range(10):
64+
os.remove(f"test_executor_multiprocess_cmd_{i}.err")
65+
os.remove(f"test_executor_multiprocess_cmd_{i}.out")
4766

4867

4968
@pytest.mark.executor

0 commit comments

Comments
 (0)