From c9d05996726844970ff2f52b77ff57bdcae1ba8d Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Thu, 10 Mar 2022 14:29:47 -0700 Subject: [PATCH 1/3] Cache parsed schema --- stac_validator/utilities.py | 6 ++++++ stac_validator/validate.py | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/stac_validator/utilities.py b/stac_validator/utilities.py index f40801a6..fb9c5f7c 100644 --- a/stac_validator/utilities.py +++ b/stac_validator/utilities.py @@ -1,3 +1,4 @@ +import functools import json from urllib.parse import urlparse from urllib.request import urlopen @@ -56,6 +57,11 @@ def fetch_and_parse_file(input_path) -> dict: return data +@functools.lru_cache(maxsize=48) +def fetch_and_parse_schema(input_path) -> dict: + return fetch_and_parse_file(input_path) + + # validate new versions at schemas.stacspec.org def set_schema_addr(version, stac_type: str): if version in NEW_VERSIONS: diff --git a/stac_validator/validate.py b/stac_validator/validate.py index 7467117f..7d0b8041 100644 --- a/stac_validator/validate.py +++ b/stac_validator/validate.py @@ -11,6 +11,7 @@ from .utilities import ( fetch_and_parse_file, + fetch_and_parse_schema, get_stac_type, link_request, set_schema_addr, @@ -150,7 +151,7 @@ def extensions_validator(self, stac_type: str) -> dict: def custom_validator(self): # in case the path to custom json schema is local # it may contain relative references - schema = fetch_and_parse_file(self.custom) + schema = fetch_and_parse_schema(self.custom) if os.path.exists(self.custom): custom_abspath = os.path.abspath(self.custom) custom_dir = os.path.dirname(custom_abspath).replace("\\", "/") @@ -158,7 +159,7 @@ def custom_validator(self): resolver = RefResolver(custom_uri, self.custom) jsonschema.validate(self.stac_content, schema, resolver=resolver) else: - schema = fetch_and_parse_file(self.custom) + schema = fetch_and_parse_schema(self.custom) jsonschema.validate(self.stac_content, schema) def core_validator(self, stac_type: str): @@ -233,7 +234,7 @@ def recursive_validator(self, stac_type: str): self.custom = set_schema_addr(self.version, stac_type.lower()) message = self.create_message(stac_type, "recursive") if self.version == "0.7.0": - schema = fetch_and_parse_file(self.custom) + schema = fetch_and_parse_schema(self.custom) # this next line prevents this: unknown url type: 'geojson.json' ?? schema["allOf"] = [{}] jsonschema.validate(self.stac_content, schema) From 79552e4bcac643d6ede261bec7b417f4105fe1bb Mon Sep 17 00:00:00 2001 From: Jonathan Healy Date: Thu, 10 Mar 2022 14:18:30 -0800 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a75463c..79cc4d0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [v2.4.3] - 2022-03-10 +### Changed + + - Add schema caching + ## [v2.4.2] - 2022-03-02 ### Changed From eea3253974cdfde8fe2e2b899761f962a7d2c8d9 Mon Sep 17 00:00:00 2001 From: Jonathan Healy Date: Thu, 10 Mar 2022 14:21:07 -0800 Subject: [PATCH 3/3] Update setup.py --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 0f96f429..aec9923c 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup -__version__ = "2.4.2" +__version__ = "2.4.3" with open("README.md", "r") as fh: long_description = fh.read() @@ -28,8 +28,8 @@ keywords="STAC validation raster", long_description=long_description, long_description_content_type="text/markdown", - url="https://github.com/sparkgeo/stac-validator", - download_url="https://github.com/sparkgeo/stac-validator/archive/v2.3.0.tar.gz", + url="https://github.com/stac-utils/stac-validator", + download_url="https://github.com/stac-utils/stac-validator/archive/v2.4.3.tar.gz", install_requires=[ "requests>=2.19.1", "jsonschema>=3.2.0",