Skip to content

Commit 643bf29

Browse files
committed
Ignore hidden files (really only parse JSON files).
1 parent 648bcae commit 643bf29

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

referencing_loaders/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ def from_path(root: Path) -> Iterable[tuple[URI, Resource[Any]]]:
2525
the root) -- though it still is often a good idea to explicitly indicate
2626
what specification every resource is written for internally.
2727
"""
28-
return _from_walked(_walk(root))
28+
return _from_walked(
29+
each for each in _walk(root) if each.name.endswith(".json")
30+
)
2931

3032

3133
def _walk(path: Path) -> Iterable[Path]:
@@ -61,9 +63,7 @@ def from_traversable(root: Traversable) -> Iterable[tuple[URI, Resource[Any]]]:
6163
(I.e. load schemas from data within a Python package.)
6264
"""
6365
return _from_walked(
64-
each
65-
for each in _walk_traversable(root)
66-
if not each.name.endswith((".py", ".pyc", ".pyo"))
66+
each for each in _walk_traversable(root) if each.name.endswith(".json")
6767
)
6868

6969

referencing_loaders/tests/test_loaders.py

+17
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,23 @@ def test_schema_is_inherited_downwards(tmp_path):
8787
assert registry.crawl() == expected.crawl()
8888

8989

90+
def test_hidden_files_are_ignored(tmp_path):
91+
schema_path, schema = tmp_path / "schema.json", {
92+
"$schema": "https://json-schema.org/draft/2020-12/schema",
93+
"$id": "http://example.com/",
94+
}
95+
hidden_path = tmp_path / ".hidden"
96+
97+
schema_path.write_text(json.dumps(schema))
98+
hidden_path.write_text("total nonsense")
99+
100+
expected = Registry().with_contents([(schema_path.as_uri(), schema)])
101+
102+
resources = loaders.from_path(tmp_path)
103+
registry = EMPTY_REGISTRY.with_resources(resources)
104+
assert registry.crawl() == expected.crawl()
105+
106+
90107
def test_empty(tmp_path):
91108
registry = EMPTY_REGISTRY.with_resources(loaders.from_path(tmp_path))
92109
assert registry == EMPTY_REGISTRY

0 commit comments

Comments
 (0)