Skip to content

Commit c85b0e0

Browse files
committed
Support parentId and creation configuration in output descriptors
Signed-off-by: Bernd Hufmann <[email protected]>
1 parent 8ba8f12 commit c85b0e0

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

tsp/output_descriptor.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
NA = "N/A"
2929
UNKOWN = "UNKNOWN"
30+
PARENT_ID_KEY = "parentId"
3031
ID_KEY = "id"
3132
NAME_KEY = "name"
3233
DESCRIPTION_KEY = "description"
@@ -36,6 +37,7 @@
3637
END_TIME_KEY = "end"
3738
IS_FINAL_KEY = "final"
3839
COMPATIBLE_PROVIDERS_KEY = "compatibleProviders"
40+
CONFIGURATION_KEY = "configuration"
3941

4042

4143
# pylint: disable=too-few-public-methods,too-many-instance-attributes
@@ -50,6 +52,14 @@ def __init__(self, params):
5052
Constructor
5153
'''
5254

55+
# Output provider's parent ID
56+
if PARENT_ID_KEY in params:
57+
# pylint: disable=invalid-name
58+
self.parent_id = params.get(PARENT_ID_KEY)
59+
del params[PARENT_ID_KEY]
60+
else: # pragma: no cover
61+
self.parent_id = None
62+
5363
# Output provider's ID
5464
if ID_KEY in params:
5565
# pylint: disable=invalid-name
@@ -117,6 +127,14 @@ def __init__(self, params):
117127
else:
118128
self.compatible_providers = []
119129

130+
# Configuration used to create this data provider.
131+
if CONFIGURATION_KEY in params:
132+
self.configuration = Configuration(params.get(CONFIGURATION_KEY))
133+
del params[CONFIGURATION_KEY]
134+
else:
135+
self.configuration = []
136+
137+
120138
def __repr__(self):
121139
return 'OutputDescriptor(id={}, name={}, description={}, type={})'.format(self.id, self.name, self.description, obj.type)
122140

@@ -126,16 +144,24 @@ def to_json(self):
126144
class OutputDescriptorEncoder(json.JSONEncoder):
127145
def default(self, obj):
128146
if isinstance(obj, OutputDescriptor):
129-
return {
130-
ID_KEY: obj.id,
131-
NAME_KEY: obj.name,
132-
DESCRIPTION_KEY: obj.description,
133-
TYPE_KEY: obj.type,
134-
# Hide non-TSP fields
135-
# QUERY_PARAMETERS_KEY: obj.query_parameters,
136-
# START_TIME_KEY: obj.start,
137-
# END_TIME_KEY: obj.end,
138-
# IS_FINAL_KEY: obj.final,
139-
# COMPATIBLE_PROVIDERS_KEY: obj.compatible_providers
140-
}
147+
result = {}
148+
# optinal parent_id
149+
if obj.parent_id is not None:
150+
result[PARENT_ID_KEY] = obj.parent_id
151+
152+
result[ID_KEY] = obj.id
153+
result[NAME_KEY] = obj.name
154+
result[DESCRIPTION_KEY] = obj.description
155+
result[TYPE_KEY] = obj.type
156+
# Hide non-TSP fields
157+
# result[QUERY_PARAMETERS_KEY] = obj.query_parameters
158+
# result[START_TIME_KEY] = obj.start
159+
# result[END_TIME_KEY] = obj.end
160+
# result[IS_FINAL_KEY] = obj.final
161+
# result[COMPATIBLE_PROVIDERS_KEY] = obj.compatible_providers
162+
163+
# optional configuration
164+
if isinstance(obj.configuration, Configuration):
165+
result[CONFIGURATION_KEY] = ConfigurationEncoder().default(obj.configuration)
166+
return result
141167
return super().default(obj)

tsp_cli_client

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ from tsp.tsp_client import TspClient
4141

4242
TRACE_MISSING = "Trace UUID is missing"
4343

44+
4445
def __get_descriptor(uuid, output_id):
4546
resp = tsp_client.fetch_experiment_output(uuid, output_id)
4647
if resp.status_code == 200:

0 commit comments

Comments
 (0)