Skip to content

Commit

Permalink
Add conftest.py with environment setup for otherwise non-existent env…
Browse files Browse the repository at this point in the history
…ironment variables on CI machine.
  • Loading branch information
xidus committed May 27, 2024
1 parent e4bb457 commit 0aa3185
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/ab/configuration/yaml_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def resolve_wildcards(path: Path | str) -> Iterable[Path]:
return Path(path.root).glob(str(Path(*parts)))


def path_constructor(loader: yaml.Loader, node: yaml.Node) -> Path | list[Path]:
def path_constructor(loader: yaml.Loader, node: yaml.Node) -> None | Path | list[Path]:
"""
The path constructor can work on two types of input:
Expand Down Expand Up @@ -84,17 +84,18 @@ def path_constructor(loader: yaml.Loader, node: yaml.Node) -> Path | list[Path]:
)

if isinstance(node, yaml.ScalarNode):
single: str = loader.construct_scalar(node)
resolved = list(resolve_wildcards(Path(single)))

path: Path = Path(loader.construct_scalar(node))
else:
# We use loader.construct_object, since there may be YAML aliases inside.
# Any YAML alias is assumed to resolve into to a string.
multiple: list[str | Path] = [loader.construct_object(v) for v in node.value]
resolved = list(resolve_wildcards(Path(*multiple)))
path = Path(*multiple)

resolved = list(resolve_wildcards(path))

if not resolved:
raise EnvironmentError(f"Path {path!r} could not be resolved.")
# EnvironmentError(f"Path {path} could not be resolved.")
return None

if len(resolved) > 1:
return resolved
Expand Down
19 changes: 19 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

LOADGPS_setvar = (
"C",
"DOC",
"PAN",
"MODEL",
"CONFIG",
"D",
"P",
"S",
"U",
"T",
)

root = "__ab__"

for env_var in LOADGPS_setvar:
os.environ[env_var] = os.path.join(root, env_var)

0 comments on commit 0aa3185

Please sign in to comment.