Skip to content

Commit

Permalink
bf: yaml should be optional
Browse files Browse the repository at this point in the history
Fixes: #245
  • Loading branch information
asmacdo committed Feb 21, 2025
1 parent b7daaec commit e2e5e29
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/con_duct/suite/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
import re
from typing import Any, Dict, List, Optional
from packaging.version import Version
from con_duct.__main__ import DUCT_OUTPUT_PREFIX, SummaryFormatter

try:
import pyout # type: ignore
except ImportError:
pyout = None
import yaml
from con_duct.__main__ import DUCT_OUTPUT_PREFIX, SummaryFormatter

try:
import yaml # type: ignore
except ImportError:
yaml = None

Check warning on line 19 in src/con_duct/suite/ls.py

View check run for this annotation

Codecov / codecov/patch

src/con_duct/suite/ls.py#L18-L19

Added lines #L18 - L19 were not covered by tests


lgr = logging.getLogger(__name__)

Expand Down Expand Up @@ -72,10 +77,14 @@ def load_duct_runs(
f"is below minimum schema version {MINIMUM_SCHEMA_VERSION}."
)
continue
if eval_filter is not None and not (eval_results := eval(
eval_filter, _flatten_dict(this), dict(re=re)
)):
lgr.debug("Filtering out %s due to filter results matching: %s", this, eval_results)
if eval_filter is not None and not (
eval_results := eval(eval_filter, _flatten_dict(this), dict(re=re))
):
lgr.debug(
"Filtering out %s due to filter results matching: %s",
this,
eval_results,
)
continue

loaded.append(this)
Expand Down Expand Up @@ -179,6 +188,8 @@ def ls(args: argparse.Namespace) -> int:
elif args.format == "json_pp":
print(json.dumps(output_rows, indent=2))
elif args.format == "yaml":
if yaml is None:
raise RuntimeError("Install PyYaml yaml output")

Check warning on line 192 in src/con_duct/suite/ls.py

View check run for this annotation

Codecov / codecov/patch

src/con_duct/suite/ls.py#L192

Added line #L192 was not covered by tests
plain_rows = [dict(row) for row in output_rows]
print(yaml.dump(plain_rows, default_flow_style=False))
else:
Expand Down

0 comments on commit e2e5e29

Please sign in to comment.