From: Arthur Zamarin Date: Fri, 2 Sep 2022 18:11:35 +0300 Subject: [PATCH] Use stdlib importlib.resources on python >= 3.9 https://github.com/p1c2u/openapi-spec-validator/pull/174 --- a/openapi_spec_validator/schemas/utils.py +++ b/openapi_spec_validator/schemas/utils.py @@ -5,14 +5,17 @@ from typing import Hashable from typing import Mapping from typing import Tuple -import importlib_resources +try: + from importlib.resources import as_file, files +except ImportError: + from importlib_resources import as_file, files from jsonschema_spec.readers import FilePathReader def get_schema(version: str) -> Tuple[Mapping[Hashable, Any], str]: schema_path = f"resources/schemas/v{version}/schema.json" - ref = importlib_resources.files("openapi_spec_validator") / schema_path - with importlib_resources.as_file(ref) as resource_path: + ref = files("openapi_spec_validator") / schema_path + with as_file(ref) as resource_path: schema_path_full = path.join(path.dirname(__file__), resource_path) return FilePathReader(schema_path_full).read() --- a/pyproject.toml +++ b/pyproject.toml @@ -49,7 +49,7 @@ openapi-schema-validator = "^0.3.2" python = "^3.7.0" PyYAML = ">=5.1" requests = {version = "*", optional = true} -importlib-resources = "^5.8.0" +importlib-resources = {version = "^5.8.0", python = "<3.9" } jsonschema-spec = "^0.1.1" lazy-object-proxy = "^1.7.1" -- 2.37.3