Parse a `TensorBoardInfo` object from its string representation. Args: info_string: A string representation of a `TensorBoardInfo`, as produced by a previous call to `_info_to_string`. Returns: A `TensorBoardInfo` value. Raises: ValueError: If the provided st
(info_string)
| 128 | |
| 129 | |
| 130 | def _info_from_string(info_string): |
| 131 | """Parse a `TensorBoardInfo` object from its string representation. |
| 132 | |
| 133 | Args: |
| 134 | info_string: A string representation of a `TensorBoardInfo`, as |
| 135 | produced by a previous call to `_info_to_string`. |
| 136 | |
| 137 | Returns: |
| 138 | A `TensorBoardInfo` value. |
| 139 | |
| 140 | Raises: |
| 141 | ValueError: If the provided string is not valid JSON, or if it is |
| 142 | missing any required fields, or if any field is of incorrect type. |
| 143 | """ |
| 144 | field_name_to_type = typing.get_type_hints(TensorBoardInfo) |
| 145 | try: |
| 146 | json_value = json.loads(info_string) |
| 147 | except ValueError: |
| 148 | raise ValueError("invalid JSON: %r" % (info_string,)) |
| 149 | if not isinstance(json_value, dict): |
| 150 | raise ValueError("not a JSON object: %r" % (json_value,)) |
| 151 | expected_keys = frozenset(field_name_to_type.keys()) |
| 152 | actual_keys = frozenset(json_value) |
| 153 | missing_keys = expected_keys - actual_keys |
| 154 | if missing_keys: |
| 155 | raise ValueError( |
| 156 | "TensorBoardInfo missing keys: %r" % (sorted(missing_keys),) |
| 157 | ) |
| 158 | # For forward compatibility, silently ignore unknown keys. |
| 159 | |
| 160 | # Validate and deserialize fields. |
| 161 | fields = {} |
| 162 | for key, field_type in field_name_to_type.items(): |
| 163 | if not isinstance(json_value[key], field_type): |
| 164 | raise ValueError( |
| 165 | "expected %r of type %s, but found: %r" |
| 166 | % (key, field_type, json_value[key]) |
| 167 | ) |
| 168 | fields[key] = json_value[key] |
| 169 | |
| 170 | return TensorBoardInfo(**fields) |
| 171 | |
| 172 | |
| 173 | def cache_key(working_directory, arguments, configure_kwargs): |
no test coverage detected
searching dependent graphs…