Skip to content

Commit 544e0ff

Browse files
committed
Ignore dotfiles when collecting schemas.
Prevents errors if e.g. a user on macOS has opened the schema directory in Finder and thereby had a .DS_Store file created by the OS. Closes: #36
1 parent 13fd330 commit 544e0ff

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

jsonschema_specifications/_core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ def _schemas():
2727
# (only 2 levels of nesting, no directories within the second level).
2828

2929
for version in files(__package__).joinpath("schemas").iterdir():
30+
if version.name.startswith("."):
31+
continue
3032
for child in version.iterdir():
3133
children = [child] if child.is_file() else child.iterdir()
3234
for path in children:
35+
if path.name.startswith("."):
36+
continue
3337
contents = json.loads(path.read_text(encoding="utf-8"))
3438
yield Resource.from_contents(contents)

jsonschema_specifications/tests/test_jsonschema_specifications.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
from collections.abc import Mapping
2+
from pathlib import Path
3+
4+
import pytest
25

36
from jsonschema_specifications import REGISTRY
47

@@ -12,3 +15,27 @@ def test_it_contains_metaschemas():
1215

1316
def test_it_is_crawled():
1417
assert REGISTRY.crawl() == REGISTRY
18+
19+
20+
@pytest.mark.parametrize(
21+
"ignored_relative_path",
22+
["schemas/.DS_Store", "schemas/draft7/.DS_Store"],
23+
)
24+
def test_it_copes_with_dotfiles(ignored_relative_path):
25+
"""
26+
Ignore files like .DS_Store if someone has actually caused one to exist.
27+
28+
We test here through the private interface as of course the global has
29+
already loaded our schemas.
30+
"""
31+
32+
import jsonschema_specifications
33+
34+
package = Path(jsonschema_specifications.__file__).parent
35+
36+
ignored = package / ignored_relative_path
37+
ignored.touch()
38+
try:
39+
list(jsonschema_specifications._schemas())
40+
finally:
41+
ignored.unlink()

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def typing(session):
6666
"""
6767
Check static typing.
6868
"""
69-
session.install("mypy", ROOT)
69+
session.install("mypy", "pytest", ROOT)
7070
session.run("python", "-m", "mypy", PACKAGE)
7171

7272

0 commit comments

Comments
 (0)