-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
670 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
Get details for all scenarios. | ||
""" | ||
import json | ||
import logging | ||
from pathlib import Path | ||
from typing import cast | ||
|
||
from packse.error import FileNotFound, InvalidScenario | ||
from packse.scenario import ( | ||
Scenario, | ||
load_scenarios, | ||
scenario_prefix, | ||
) | ||
from packse.view import dependency_tree | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def inspect(targets: list[Path], skip_invalid: bool = False): | ||
scenarios_by_path: dict[Path, list[Scenario]] = {} | ||
|
||
# Validate and collect all targets first | ||
for target in sorted(targets): | ||
if not target.exists(): | ||
raise FileNotFound(target) | ||
|
||
try: | ||
logger.debug("Loading %s", target) | ||
scenarios_by_path[target] = load_scenarios(target) | ||
except Exception as exc: | ||
if not skip_invalid: | ||
raise InvalidScenario(target, reason=str(exc)) from exc | ||
|
||
# Collect a JSON-compatible representation for each scenario | ||
result = {"scenarios": []} | ||
for source, scenarios in scenarios_by_path.items(): | ||
for scenario in scenarios: | ||
scenario = cast(Scenario, scenario) | ||
|
||
raw = scenario.dict() | ||
raw["source"] = str(source) | ||
raw["prefix"] = scenario_prefix(scenario) | ||
raw["tree"] = dependency_tree(scenario) | ||
result["scenarios"].append(raw) | ||
|
||
print(json.dumps(result, indent=2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.