diff --git a/buildingmotif/dataclasses/library.py b/buildingmotif/dataclasses/library.py index 0e7169b69..d12afa07b 100644 --- a/buildingmotif/dataclasses/library.py +++ b/buildingmotif/dataclasses/library.py @@ -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) diff --git a/buildingmotif/utils.py b/buildingmotif/utils.py index bc3da9904..fe8eb711f 100644 --- a/buildingmotif/utils.py +++ b/buildingmotif/utils.py @@ -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( diff --git a/tests/unit/dataclasses/test_library.py b/tests/unit/dataclasses/test_library.py index ffbd2a10f..6477b6638 100644 --- a/tests/unit/dataclasses/test_library.py +++ b/tests/unit/dataclasses/test_library.py @@ -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. diff --git a/tests/unit/fixtures/ipynb_checkpoint_test/.ipynb_checkpoints/templates.yml b/tests/unit/fixtures/ipynb_checkpoint_test/.ipynb_checkpoints/templates.yml new file mode 100644 index 000000000..c59d3a69b --- /dev/null +++ b/tests/unit/fixtures/ipynb_checkpoint_test/.ipynb_checkpoints/templates.yml @@ -0,0 +1,9 @@ +fan: + body: > + @prefix bmparam: . + @prefix 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 . diff --git a/tests/unit/fixtures/ipynb_checkpoint_test/templates.yml b/tests/unit/fixtures/ipynb_checkpoint_test/templates.yml new file mode 100644 index 000000000..c59d3a69b --- /dev/null +++ b/tests/unit/fixtures/ipynb_checkpoint_test/templates.yml @@ -0,0 +1,9 @@ +fan: + body: > + @prefix bmparam: . + @prefix 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 .