Skip to content

Commit 951958f

Browse files
authored
Merge pull request #48 from simvue-io/support_nan
Support NaN & infinity in metadata & metrics
2 parents 4120d22 + 9440fdf commit 951958f

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change log
22

3+
## v0.7.2
4+
5+
* Pydantic model is used for input validation.
6+
* Support NaN, -inf and inf in metadata and metrics.
7+
38
## v0.7.0
49

510
* Collect CPU, GPU and memory resource metrics.

simvue/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from simvue.client import Client
33
from simvue.handler import Handler
44
from simvue.models import RunInput
5-
__version__ = '0.7.1'
5+
__version__ = '0.7.2'

simvue/api.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import copy
2+
import json
13
import requests
24
from tenacity import retry, wait_exponential, stop_after_attempt
35

@@ -7,16 +9,25 @@
79
RETRY_MAX = 10
810
RETRY_STOP = 5
911

12+
def set_json_header(headers):
13+
"""
14+
Return a copy of the headers with Content-Type set to
15+
application/json
16+
"""
17+
headers = copy.deepcopy(headers)
18+
headers['Content-Type'] = 'application/json'
19+
return headers
20+
1021
@retry(wait=wait_exponential(multiplier=RETRY_MULTIPLIER, min=RETRY_MIN, max=RETRY_MAX),
1122
stop=stop_after_attempt(RETRY_STOP))
1223
def post(url, headers, data, is_json=True):
1324
"""
1425
HTTP POST with retries
1526
"""
1627
if is_json:
17-
response = requests.post(url, headers=headers, json=data, timeout=DEFAULT_API_TIMEOUT)
18-
else:
19-
response = requests.post(url, headers=headers, data=data, timeout=DEFAULT_API_TIMEOUT)
28+
data = json.dumps(data)
29+
headers = set_json_header(headers)
30+
response = requests.post(url, headers=headers, data=data, timeout=DEFAULT_API_TIMEOUT)
2031

2132
return response
2233

@@ -27,8 +38,8 @@ def put(url, headers, data, is_json=True, timeout=DEFAULT_API_TIMEOUT):
2738
HTTP PUT with retries
2839
"""
2940
if is_json:
30-
response = requests.put(url, headers=headers, json=data, timeout=timeout)
31-
else:
32-
response = requests.put(url, headers=headers, data=data, timeout=timeout)
41+
data = json.dumps(data)
42+
headers = set_json_header(headers)
43+
response = requests.put(url, headers=headers, data=data, timeout=timeout)
3344

3445
return response

0 commit comments

Comments
 (0)