blob: ac794b49cd9a4109abef9c35ade7e03ae41f24f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
From: Arthur Zamarin <arthurzam@gentoo.org>
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
|