Skip to content
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

Fixed deprecated: importlib for module search. Backward compatibility… #435

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions flasgger/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import codecs
import copy
import imp
import inspect
import os
import re
Expand All @@ -24,6 +23,11 @@
from .marshmallow_apispec import SwaggerView
from .marshmallow_apispec import convert_schemas

if sys.version_info.major < 3:
import imp
else:
import importlib


def merge_specs(target, source):
"""
Expand Down Expand Up @@ -565,7 +569,12 @@ def load_from_file(swag_path, swag_type='yml', root_path=None):
path = swag_path.replace(
(root_path or os.path.dirname(__file__)), ''
).split(os.sep)[1:]
site_package = imp.find_module(path[0])[1]
if sys.version_info.major < 3:
site_package = imp.find_module(path[0])[1]
else:
site_package = importlib.util.find_spec(
path[0]
).submodule_search_locations[0]
swag_path = os.path.join(site_package, os.sep.join(path[1:]))
with open(swag_path) as yaml_file:
return yaml_file.read()
Expand Down