feat: accept both .hokusai.yaml and .hokusai.yml config suffixes

This commit is contained in:
Konstantin Fickel 2026-02-20 20:33:10 +01:00
parent 1f75c72a96
commit d772f5dcc5
Signed by: kfickel
GPG key ID: A793722F9933C1A5
2 changed files with 13 additions and 8 deletions

View file

@ -32,7 +32,7 @@ app = typer.Typer(
name="hokusai", help="AI artifact build tool.", cls=_DefaultBuildGroup
)
_CONFIG_SUFFIX = ".hokusai.yaml"
_CONFIG_SUFFIXES = (".hokusai.yaml", ".hokusai.yml")
def _project_name(config_path: Path) -> str:
@ -41,16 +41,21 @@ def _project_name(config_path: Path) -> str:
``cards.hokusai.yaml`` ``cards``
"""
name = config_path.name
return name.removesuffix(_CONFIG_SUFFIX)
for suffix in _CONFIG_SUFFIXES:
if name.endswith(suffix):
return name.removesuffix(suffix)
return name
def _find_config(directory: Path) -> Path:
"""Find the single ``*.hokusai.yaml`` file in *directory*."""
candidates = list(directory.glob("*.hokusai.yaml"))
"""Find the single ``*.hokusai.{yaml,yml}`` file in *directory*."""
candidates: list[Path] = []
for suffix in _CONFIG_SUFFIXES:
candidates.extend(directory.glob(f"*{suffix}"))
if len(candidates) == 0:
click.echo(
click.style("Error: ", fg="red", bold=True)
+ "No .hokusai.yaml file found in current directory",
+ "No .hokusai.yaml/.yml file found in current directory",
err=True,
)
raise typer.Exit(code=1)
@ -58,7 +63,7 @@ def _find_config(directory: Path) -> Path:
names = ", ".join(str(c.name) for c in candidates)
click.echo(
click.style("Error: ", fg="red", bold=True)
+ f"Multiple .hokusai.yaml files found: {names}",
+ f"Multiple .hokusai.yaml/.yml files found: {names}",
err=True,
)
raise typer.Exit(code=1)

View file

@ -42,7 +42,7 @@ class TestFindConfig:
mock_path_cls.cwd.return_value = tmp_path
result = runner.invoke(app, ["build"])
assert result.exit_code != 0
assert "No .hokusai.yaml file found" in result.output
assert "No .hokusai.yaml/.yml file found" in result.output
def test_multiple_config_files(self, tmp_path: Path) -> None:
_ = (tmp_path / "a.hokusai.yaml").write_text(
@ -55,7 +55,7 @@ class TestFindConfig:
mock_path_cls.cwd.return_value = tmp_path
result = runner.invoke(app, ["build"])
assert result.exit_code != 0
assert "Multiple .hokusai.yaml files found" in result.output
assert "Multiple .hokusai.yaml/.yml files found" in result.output
class TestBuildCommand: