Skip to content

use importlib_resources instead of pkg_resources #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions openapi_spec_validator/schemas.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
"""OpenAIP spec validator schemas module."""
import os

from pkg_resources import resource_filename
import urllib.parse
import urllib.request
from yaml import load

import importlib_resources
from openapi_spec_validator.loaders import ExtendedSafeLoader


def get_openapi_schema(version):
path = 'resources/schemas/v{0}/schema.json'.format(version)
path_resource = resource_filename('openapi_spec_validator', path)
path_full = os.path.join(os.path.dirname(__file__), path_resource)
ref = importlib_resources.files('openapi_spec_validator') / path
with importlib_resources.as_file(ref) as path_resource:
path_full = os.path.join(os.path.dirname(__file__), path_resource)
schema = read_yaml_file(path_full)
schema_url = urllib.parse.urljoin('file:', urllib.request.pathname2url(path_full))
return schema, schema_url
Expand Down
103 changes: 50 additions & 53 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ openapi-schema-validator = {version = "^0.3.0a1", allow-prereleases = true}
python = "^3.7.0"
PyYAML = ">=5.1"
requests = {version = "*", optional = true}
setuptools = "^60.9.3"
importlib-resources = "^5.8.0"

[tool.poetry.extras]
dev = ["pre-commit"]
Expand Down