Skip to content

Commit

Permalink
use importlib_resources since we need stuff introduced in python 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
benbariteau committed Jun 24, 2024
1 parent abe8cc7 commit 5609ddf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"jsonschema",
"pyyaml",
"typing-extensions",
"importlib-resources >= 1.3",
]


Expand Down
6 changes: 3 additions & 3 deletions swagger_spec_validator/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from urllib.request import pathname2url
from urllib.request import urlopen

import importlib_resources
import yaml
import importlib.resources
from typing_extensions import ParamSpec

try:
Expand Down Expand Up @@ -55,8 +55,8 @@ def read_file(file_path: str) -> dict[str, Any]:

@lru_cache()
def read_resource_file(resource_path: str) -> tuple[dict[str, Any], str]:
ref = importlib.resources.files('swagger_spec_validator') / resource_path
with importlib.resources.as_file(ref) as path:
ref = importlib_resources.files("swagger_spec_validator") / resource_path
with importlib_resources.as_file(ref) as path:
return read_file(path), path


Expand Down
4 changes: 2 additions & 2 deletions tests/common_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid
from unittest import mock

import importlib.resources
import importlib_resources

from swagger_spec_validator.common import read_file
from swagger_spec_validator.common import read_resource_file
Expand All @@ -19,5 +19,5 @@ def test_read_resource_file(monkeypatch):
read_resource_file(resource_path)

m.assert_called_once_with(
importlib.resources.files("swagger_spec_validator")
importlib_resources.files("swagger_spec_validator") / resource_path
)

0 comments on commit 5609ddf

Please sign in to comment.