Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ repos:
types: [file, yaml]
entry: yamllint --strict
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
args:
Expand Down Expand Up @@ -71,6 +71,7 @@ repos:
- packaging
- pytest
- pytest-mock
- referencing
- types-PyYAML
- types-pkg_resources
- types-requests
Expand Down
17 changes: 14 additions & 3 deletions constraints.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#
# This file is autogenerated by pip-compile with python 3.9
# To update, run:
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --extra=retry --extra=test --output-file=constraints.txt setup.cfg
#
attrs==21.4.0
# via
# cattrs
# pytest
# referencing
# requests-cache
cattrs==22.1.0
# via requests-cache
Expand All @@ -20,9 +21,13 @@ coverage==6.3.3
exceptiongroup==1.0.0rc5
# via cattrs
idna==3.3
# via requests
# via
# requests
# yarl
iniconfig==1.1.1
# via pytest
multidict==6.0.4
# via yarl
packaging==21.3
# via pytest
platformdirs==2.5.2
Expand All @@ -33,8 +38,12 @@ py==1.11.0
# via pytest
pyparsing==3.0.9
# via packaging
pyrsistent==0.19.3
# via referencing
pytest==7.1.2
# via schemastore (setup.cfg)
referencing==0.8.11
# via schemastore (setup.cfg)
requests==2.27.1
# via requests-cache
requests-cache==1.0.0a0
Expand All @@ -49,3 +58,5 @@ urllib3==1.26.9
# via
# requests
# requests-cache
yarl==1.9.2
# via referencing
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ long_description_content_type = text/markdown
author = Sorin Sbarnea
author_email = sorin.sbarnea@gmail.com
license = Apache-2.0
license_file = LICENSE
license_files = LICENSE
classifiers =
Development Status :: 5 - Production/Stable

Expand Down Expand Up @@ -56,6 +56,7 @@ zip_safe = False

# These are required in actual runtime:
install_requires =
referencing
requests-cache>=1.0.0a0

[options.entry_points]
Expand Down
16 changes: 14 additions & 2 deletions src/schemastore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from typing import Any

import requests_cache
from referencing import Registry, Resource
from referencing.jsonschema import Schema, SchemaRegistry
from requests import HTTPError

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


class Store:
class _Store:
"""Store class for interacting with the store."""

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


__all__ = ["Store"]
def registry(**kwargs: Any) -> SchemaRegistry:
"""Create a registry."""
store = _Store(**kwargs)

def retrieve(uri: str) -> Resource[Schema]:
return Resource.from_contents(store.get_schema(uri))

return Registry(retrieve=retrieve) # type: ignore


__all__ = ["registry"]
4 changes: 2 additions & 2 deletions src/schemastore/__main__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Main entry point module."""
from schemastore import Store
from schemastore import _Store


def main() -> None:
"""Refresh the cache if needed."""
store = Store()
store = _Store()
print(f"Catalog has {len(store.catalog['schemas'])} schemas")
store.refresh()
print(f"Catalog now has {len(store.catalog['schemas'])} schemas")
Binary file modified src/schemastore/cache.sqlite
Binary file not shown.
6 changes: 3 additions & 3 deletions test/test_jsonschema.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Test module."""
from schemastore import Store
import schemastore


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