From 95ba458d18eabe1ebc7f4832d8873d5b4321be21 Mon Sep 17 00:00:00 2001 From: Gabe Fierro Date: Tue, 2 Jul 2024 17:23:19 -0600 Subject: [PATCH 1/4] skip .ipynb_checkpoints when scanning for files --- buildingmotif/dataclasses/library.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/buildingmotif/dataclasses/library.py b/buildingmotif/dataclasses/library.py index 05858c972..a74c4ac6b 100644 --- a/buildingmotif/dataclasses/library.py +++ b/buildingmotif/dataclasses/library.py @@ -340,6 +340,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) From 513ea146d29592d8e7c9af7b3e5350fa1007c5e1 Mon Sep 17 00:00:00 2001 From: Gabe Fierro Date: Tue, 2 Jul 2024 17:25:40 -0600 Subject: [PATCH 2/4] do the same filter in utils --- buildingmotif/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/buildingmotif/utils.py b/buildingmotif/utils.py index 64573623b..8a1bdbccb 100644 --- a/buildingmotif/utils.py +++ b/buildingmotif/utils.py @@ -185,7 +185,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( From 118782e7e1c9cc18c961aa45075f5b97d78137c5 Mon Sep 17 00:00:00 2001 From: Gabe Fierro Date: Tue, 27 Aug 2024 14:50:07 -0600 Subject: [PATCH 3/4] add ipynb checkpoint test --- tests/unit/dataclasses/test_library.py | 8 ++++++++ .../fixtures/ipynb_checkpoint_test/templates.yml | 13 +++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/unit/fixtures/ipynb_checkpoint_test/templates.yml 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/templates.yml b/tests/unit/fixtures/ipynb_checkpoint_test/templates.yml new file mode 100644 index 000000000..7dfeb06ba --- /dev/null +++ b/tests/unit/fixtures/ipynb_checkpoint_test/templates.yml @@ -0,0 +1,13 @@ +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 . + dependencies: + - template: https://brickschema.org/schema/Brick#Fan + library: https://brickschema.org/schema/1.3/Brick + args: {"name": "spd"} From 0aab0331c48c079edf4d50ed3e356acf71339e70 Mon Sep 17 00:00:00 2001 From: Gabe Fierro Date: Tue, 27 Aug 2024 14:53:03 -0600 Subject: [PATCH 4/4] force-add the ipynb checkpoitn file --- .../.ipynb_checkpoints/templates.yml | 9 +++++++++ tests/unit/fixtures/ipynb_checkpoint_test/templates.yml | 4 ---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 tests/unit/fixtures/ipynb_checkpoint_test/.ipynb_checkpoints/templates.yml 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 index 7dfeb06ba..c59d3a69b 100644 --- a/tests/unit/fixtures/ipynb_checkpoint_test/templates.yml +++ b/tests/unit/fixtures/ipynb_checkpoint_test/templates.yml @@ -7,7 +7,3 @@ fan: bmparam:spd a brick:Fan_Speed_Command . bmparam:st a brick:Fan_Status . bmparam:ss a brick:Start_Stop_Command . - dependencies: - - template: https://brickschema.org/schema/Brick#Fan - library: https://brickschema.org/schema/1.3/Brick - args: {"name": "spd"}