Skip to content

Commit c4746e3

Browse files
arthurzamp1c2u
authored andcommitted
Use stdlib importlib.resources on python >= 3.9
Signed-off-by: Arthur Zamarin <[email protected]>
1 parent cab6dd4 commit c4746e3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

openapi_spec_validator/schemas/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
"""OpenAIP spec validator schemas utils module."""
2+
import sys
23
from os import path
34
from typing import Any
45
from typing import Hashable
56
from typing import Mapping
67
from typing import Tuple
78

8-
import importlib_resources
9+
if sys.version_info >= (3, 9):
10+
from importlib.resources import as_file, files
11+
else:
12+
from importlib_resources import as_file, files
913
from jsonschema_spec.readers import FilePathReader
1014

1115

1216
def get_schema(version: str) -> Tuple[Mapping[Hashable, Any], str]:
1317
schema_path = f"resources/schemas/v{version}/schema.json"
14-
ref = importlib_resources.files("openapi_spec_validator") / schema_path
15-
with importlib_resources.as_file(ref) as resource_path:
18+
ref = files("openapi_spec_validator") / schema_path
19+
with as_file(ref) as resource_path:
1620
schema_path_full = path.join(path.dirname(__file__), resource_path)
1721
return FilePathReader(schema_path_full).read()
1822

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ openapi-schema-validator = "^0.3.2"
4949
python = "^3.7.0"
5050
PyYAML = ">=5.1"
5151
requests = {version = "*", optional = true}
52-
importlib-resources = "^5.8.0"
52+
importlib-resources = {version = "^5.8.0", python = "<3.9" }
5353
jsonschema-spec = "^0.1.1"
5454
lazy-object-proxy = "^1.7.1"
5555

0 commit comments

Comments
 (0)