fmt/v2: extract metadata gathering into function
Extract the piece of code that gathers the metadata from the result struct into its own (nested) method. It is easier to read but also prepares for a future change where we read the metadata from the store instead of the result dict.
This commit is contained in:
parent
8f40faf3d5
commit
baa547b5e9
1 changed files with 13 additions and 10 deletions
|
|
@ -394,6 +394,18 @@ def load(description: Dict, index: Index) -> Manifest:
|
|||
def output(manifest: Manifest, res: Dict) -> Dict:
|
||||
"""Convert a result into the v2 format"""
|
||||
|
||||
def collect_metadata(p: Pipeline) -> Dict[str, Any]:
|
||||
data: Dict[str, Any] = {}
|
||||
r = res.get(p.id, {})
|
||||
for stage in r.get("stages", []):
|
||||
md = stage.metadata
|
||||
if not md:
|
||||
continue
|
||||
val = data.setdefault(stage.name, {})
|
||||
val.update(md)
|
||||
|
||||
return data
|
||||
|
||||
result: Dict[str, Any] = {}
|
||||
|
||||
if not res["success"]:
|
||||
|
|
@ -424,16 +436,7 @@ def output(manifest: Manifest, res: Dict) -> Dict:
|
|||
|
||||
# gather all the metadata
|
||||
for p in manifest.pipelines.values():
|
||||
data: Dict[str, Any] = {}
|
||||
r = res.get(p.id, {})
|
||||
for stage in r.get("stages", []):
|
||||
md = stage.metadata
|
||||
if not md:
|
||||
continue
|
||||
name = stage.name
|
||||
val = data.setdefault(name, {})
|
||||
val.update(md)
|
||||
|
||||
data: Dict[str, Any] = collect_metadata(p)
|
||||
if data:
|
||||
result["metadata"][p.name] = data
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue