Skip to content

Commit

Permalink
Drop pkg_resources (#1499)
Browse files Browse the repository at this point in the history
* Use pkgutil instead of pkg_resources

* Use importlib.metadata and packaging for getting and parsing version number
  • Loading branch information
Ruwann committed Mar 22, 2022
1 parent 85058ed commit f236c68
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
11 changes: 7 additions & 4 deletions connexion/decorators/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
import logging
from typing import AnyStr, Union

import pkg_resources
try:
from importlib.metadata import version
except ImportError:
from importlib_metadata import version

from jsonschema import Draft4Validator, ValidationError, draft4_format_checker
from jsonschema.validators import extend
from packaging.version import Version
from werkzeug.datastructures import FileStorage

from ..exceptions import (BadRequestProblem, ExtraParameterProblem,
Expand All @@ -20,9 +25,7 @@
from ..lifecycle import ConnexionResponse
from ..utils import all_json, boolean, is_json_mimetype, is_null, is_nullable

_jsonschema_3_or_newer = pkg_resources.parse_version(
pkg_resources.get_distribution("jsonschema").version) >= \
pkg_resources.parse_version("3.0.0")
_jsonschema_3_or_newer = Version(version("jsonschema")) >= Version("3.0.0")

logger = logging.getLogger('connexion.decorators.validation')

Expand Down
14 changes: 7 additions & 7 deletions connexion/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import copy
import json
import pathlib
import pkgutil
from collections.abc import Mapping
from urllib.parse import urlsplit

import jinja2
import jsonschema
import pkg_resources
import yaml
from jsonschema import Draft4Validator
from jsonschema.validators import extend as extend_validator
Expand Down Expand Up @@ -206,9 +206,9 @@ class Swagger2Specification(Specification):
yaml_name = 'swagger.yaml'
operation_cls = Swagger2Operation

schema_string = pkg_resources.resource_string('connexion', 'resources/schemas/v2.0/schema.json')
openapi_schema = json.loads(schema_string.decode('utf-8'))
del schema_string
openapi_schema = json.loads(
pkgutil.get_data('connexion', 'resources/schemas/v2.0/schema.json')
)

@classmethod
def _set_defaults(cls, spec):
Expand Down Expand Up @@ -259,9 +259,9 @@ class OpenAPISpecification(Specification):
yaml_name = 'openapi.yaml'
operation_cls = OpenAPIOperation

schema_string = pkg_resources.resource_string('connexion', 'resources/schemas/v3.0/schema.json')
openapi_schema = json.loads(schema_string.decode('utf-8'))
del schema_string
openapi_schema = json.loads(
pkgutil.get_data('connexion', 'resources/schemas/v3.0/schema.json')
)

@classmethod
def _set_defaults(cls, spec):
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def read_version(package):
'requests>=2.9.1,<3',
'inflection>=0.3.1,<0.6',
'werkzeug>=1.0,<3',
'importlib-metadata>=1 ; python_version<"3.8"',
'packaging>=20',
]

swagger_ui_require = 'swagger-ui-bundle>=0.0.2,<0.1'
Expand Down

0 comments on commit f236c68

Please sign in to comment.