Skip to content

Commit

Permalink
Fix scenario discovery globs (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb authored Apr 17, 2024
1 parent 1ec9c59 commit 0256c65
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/packse/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
Package,
PackageMetadata,
Scenario,
find_scenario_files,
load_scenarios,
scenario_hash,
)
Expand Down Expand Up @@ -53,7 +54,7 @@ def build(
raise FileNotFound(target)

if target.is_dir():
for target in target.glob("*.(json|yaml|toml)"):
for target in find_scenario_files(target):
try:
logger.debug("Loading %s", target)
scenarios.extend(load_scenarios(target))
Expand Down
9 changes: 5 additions & 4 deletions src/packse/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from packse.inspect import inspect
from packse.list import list
from packse.publish import publish
from packse.scenario import find_scenario_files
from packse.serve import serve
from packse.view import view

Expand Down Expand Up @@ -160,13 +161,13 @@ def _call_list(args):
skip_invalid = args.skip_invalid
if not args.targets:
skip_invalid = True
targets = Path.cwd().glob("**/*.(json|yaml|toml)")
targets = find_scenario_files(Path.cwd())
else:
targets = []
for target in args.targets:
# Expand any directories to json files within
if target.is_dir():
targets.extend(target.glob("**/*.(json|yaml|toml)"))
targets.extend(find_scenario_files(target))
else:
targets.append(target)

Expand All @@ -183,13 +184,13 @@ def _call_inspect(args):
skip_invalid = args.skip_invalid
if not args.targets:
skip_invalid = True
targets = Path.cwd().glob("**/*.(json|yaml|toml)")
targets = find_scenario_files(Path.cwd())
else:
targets = []
for target in args.targets:
# Expand any directories to scenario files within
if target.is_dir():
targets.extend(target.glob("**/*.(json|yaml|toml)"))
targets.extend(find_scenario_files(target))
else:
targets.append(target)

Expand Down
3 changes: 2 additions & 1 deletion src/packse/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from packse.scenario import (
Requirement,
Scenario,
find_scenario_files,
load_scenarios,
scenario_hash,
)
Expand All @@ -31,7 +32,7 @@ def inspect(
raise FileNotFound(target)

if target.is_dir():
for target in target.glob("*.(json|yaml|toml)"):
for target in find_scenario_files(target):
try:
logger.debug("Loading %s", target)
scenarios_by_path[target] = load_scenarios(target)
Expand Down
9 changes: 8 additions & 1 deletion src/packse/scenario.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import hashlib
import itertools
import json
import os
from pathlib import Path
from typing import Any, Self, Type
from typing import Any, Iterator, Self, Type

import msgspec
import packaging.requirements
Expand Down Expand Up @@ -332,6 +333,12 @@ def load_scenarios(target: Path) -> list[Scenario]:
return [load_scenario(target)]


def find_scenario_files(target: Path) -> Iterator[Path]:
return itertools.chain(
target.glob("**/*.json"), target.glob("**/*.yaml"), target.glob("**/*.toml")
)


def scenario_hash(scenario: Scenario) -> str:
"""
Generate a unique version for a scenario based on its contents.
Expand Down

0 comments on commit 0256c65

Please sign in to comment.