Skip to content

Commit 0869dac

Browse files
authored
Merge pull request #2 from pycontribs/registry
Expose SchemaStore as a referencing.Registry.
2 parents 7f0a276 + dd4c588 commit 0869dac

File tree

7 files changed

+37
-12
lines changed

7 files changed

+37
-12
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ repos:
4141
types: [file, yaml]
4242
entry: yamllint --strict
4343
- repo: https://github.com/PyCQA/isort
44-
rev: 5.10.1
44+
rev: 5.12.0
4545
hooks:
4646
- id: isort
4747
args:
@@ -71,6 +71,7 @@ repos:
7171
- packaging
7272
- pytest
7373
- pytest-mock
74+
- referencing
7475
- types-PyYAML
7576
- types-pkg_resources
7677
- types-requests

constraints.txt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#
2-
# This file is autogenerated by pip-compile with python 3.9
3-
# To update, run:
2+
# This file is autogenerated by pip-compile with Python 3.9
3+
# by the following command:
44
#
55
# pip-compile --extra=retry --extra=test --output-file=constraints.txt setup.cfg
66
#
77
attrs==21.4.0
88
# via
99
# cattrs
1010
# pytest
11+
# referencing
1112
# requests-cache
1213
cattrs==22.1.0
1314
# via requests-cache
@@ -20,9 +21,13 @@ coverage==6.3.3
2021
exceptiongroup==1.0.0rc5
2122
# via cattrs
2223
idna==3.3
23-
# via requests
24+
# via
25+
# requests
26+
# yarl
2427
iniconfig==1.1.1
2528
# via pytest
29+
multidict==6.0.4
30+
# via yarl
2631
packaging==21.3
2732
# via pytest
2833
platformdirs==2.5.2
@@ -33,8 +38,12 @@ py==1.11.0
3338
# via pytest
3439
pyparsing==3.0.9
3540
# via packaging
41+
pyrsistent==0.19.3
42+
# via referencing
3643
pytest==7.1.2
3744
# via schemastore (setup.cfg)
45+
referencing==0.8.11
46+
# via schemastore (setup.cfg)
3847
requests==2.27.1
3948
# via requests-cache
4049
requests-cache==1.0.0a0
@@ -49,3 +58,5 @@ urllib3==1.26.9
4958
# via
5059
# requests
5160
# requests-cache
61+
yarl==1.9.2
62+
# via referencing

setup.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ long_description_content_type = text/markdown
1111
author = Sorin Sbarnea
1212
author_email = [email protected]
1313
license = Apache-2.0
14-
license_file = LICENSE
14+
license_files = LICENSE
1515
classifiers =
1616
Development Status :: 5 - Production/Stable
1717

@@ -56,6 +56,7 @@ zip_safe = False
5656

5757
# These are required in actual runtime:
5858
install_requires =
59+
referencing
5960
requests-cache>=1.0.0a0
6061

6162
[options.entry_points]

src/schemastore/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
from typing import Any
66

77
import requests_cache
8+
from referencing import Registry, Resource
9+
from referencing.jsonschema import Schema, SchemaRegistry
810
from requests import HTTPError
911

1012
CATALOG_URL = "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/api/json/catalog.json"
1113

1214

13-
class Store:
15+
class _Store:
1416
"""Store class for interacting with the store."""
1517

1618
def __init__(self, days: int = 30) -> None:
@@ -39,4 +41,14 @@ def refresh(self) -> None:
3941
print(f"Failed to decode {schema['url']}: {type(exc)}")
4042

4143

42-
__all__ = ["Store"]
44+
def registry(**kwargs: Any) -> SchemaRegistry:
45+
"""Create a registry."""
46+
store = _Store(**kwargs)
47+
48+
def retrieve(uri: str) -> Resource[Schema]:
49+
return Resource.from_contents(store.get_schema(uri))
50+
51+
return Registry(retrieve=retrieve) # type: ignore
52+
53+
54+
__all__ = ["registry"]

src/schemastore/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""Main entry point module."""
2-
from schemastore import Store
2+
from schemastore import _Store
33

44

55
def main() -> None:
66
"""Refresh the cache if needed."""
7-
store = Store()
7+
store = _Store()
88
print(f"Catalog has {len(store.catalog['schemas'])} schemas")
99
store.refresh()
1010
print(f"Catalog now has {len(store.catalog['schemas'])} schemas")

src/schemastore/cache.sqlite

76 KB
Binary file not shown.

test/test_jsonschema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""Test module."""
2-
from schemastore import Store
2+
import schemastore
33

44

55
def test_one() -> None:
66
"""Test one."""
7-
store = Store()
8-
assert store.catalog is not None
7+
registry = schemastore.registry()
8+
assert registry is not None

0 commit comments

Comments
 (0)