Skip to content

Commit

Permalink
Filter KiCAD autosaved layouts from build list
Browse files Browse the repository at this point in the history
  • Loading branch information
mawildoer committed Jan 20, 2024
1 parent 16197cb commit 5b548fb
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/atopile/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Schema and utils for atopile config files."""

import collections.abc
import fnmatch
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -154,6 +155,21 @@ def from_path(cls, path: Path) -> "ProjectContext":
return cls.from_config(get_project_config_from_path(path))


def match_user_layout(path: Path) -> bool:
"""Check whether a given filename is a KiCAD autosaved layout."""
autosave_patterns = [
"_autosave-*",
"*-save.kicad_pcb",
]

name = path.name

for pattern in autosave_patterns:
if fnmatch.fnmatch(name, pattern):
return False
return True


@define
class BuildContext:
"""A class to hold the arguments to a build."""
Expand Down Expand Up @@ -191,9 +207,16 @@ def from_config(cls, config: UserConfig, build_name: str) -> "BuildContext":
if layout_base.with_suffix(".kicad_pcb").exists():
layout_path = layout_base.with_suffix(".kicad_pcb")
elif layout_base.is_dir():
layout_candidates = list(layout_base.glob("*.kicad_pcb"))
layout_candidates = list(
filter(
match_user_layout,
layout_base.glob("*.kicad_pcb")
)
)

if len(layout_candidates) == 1:
layout_path = layout_candidates[0]

else:
raise atopile.errors.AtoError(
"Layout directories must contain exactly 1 layout,"
Expand Down

0 comments on commit 5b548fb

Please sign in to comment.