Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip ipynb checkpoint directory #330

Merged
merged 6 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions buildingmotif/dataclasses/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ def _load_from_directory(

# read all .yml files
for file in directory.rglob("*.yml"):
# if .ipynb_checkpoints, skip; these are cached files that Jupyter creates
if ".ipynb_checkpoints" in file.parts:
continue
lib._read_yml_file(file, template_id_lookup, dependency_cache)
# now that we have all the templates, we can populate the dependencies
lib._resolve_template_dependencies(template_id_lookup, dependency_cache)
Expand Down
7 changes: 6 additions & 1 deletion buildingmotif/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ def get_ontology_files(directory: Path, recursive: bool = True) -> List[Path]:
searches = (directory.rglob(f"{pat}") for pat in patterns)
else:
searches = (directory.glob(f"{pat}") for pat in patterns)
return list(chain.from_iterable(searches))
# filter out files in .ipynb_checkpoints
filtered_searches = (
filter(lambda x: ".ipynb_checkpoints" not in Path(x).parts, search)
for search in searches
)
return list(chain.from_iterable(filtered_searches))


def get_template_parts_from_shape(
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/dataclasses/test_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ def test_load_library_overwrite_directory(bm: BuildingMOTIF):
assert len(lib.get_templates()) == 2, "Library overwritten improperly"


def test_load_library_no_ipynb_checkpoints(bm: BuildingMOTIF):
lib = Library.load(directory="tests/unit/fixtures/ipynb_checkpoint_test")
assert lib is not None
assert len(lib.get_templates()) == 1
# if the checkpoint file was loaded, BuildingMOTIF would complain about
# duplicate templates


def test_libraries(monkeypatch, bm: BuildingMOTIF, library: str):
"""
Test that the libraries can be loaded and used.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fan:
body: >
@prefix bmparam: <urn:___param___#> .
@prefix brick: <https://brickschema.org/schema/Brick#> .
bmparam:name a brick:Fan ;
brick:hasPoint bmparam:spd, bmparam:st, bmparam:ss .
bmparam:spd a brick:Fan_Speed_Command .
bmparam:st a brick:Fan_Status .
bmparam:ss a brick:Start_Stop_Command .
9 changes: 9 additions & 0 deletions tests/unit/fixtures/ipynb_checkpoint_test/templates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fan:
body: >
@prefix bmparam: <urn:___param___#> .
@prefix brick: <https://brickschema.org/schema/Brick#> .
bmparam:name a brick:Fan ;
brick:hasPoint bmparam:spd, bmparam:st, bmparam:ss .
bmparam:spd a brick:Fan_Speed_Command .
bmparam:st a brick:Fan_Status .
bmparam:ss a brick:Start_Stop_Command .
Loading