diff --git a/gunicorn/app/base.py b/gunicorn/app/base.py index cb1bd973b..9b024f155 100644 --- a/gunicorn/app/base.py +++ b/gunicorn/app/base.py @@ -3,6 +3,7 @@ # This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. import importlib.util +import importlib.machinery import os import sys import traceback @@ -94,9 +95,17 @@ def get_config_from_filename(self, filename): if not os.path.exists(filename): raise RuntimeError("%r doesn't exist" % filename) + ext = os.path.splitext(filename)[1] + try: module_name = '__config__' - spec = importlib.util.spec_from_file_location(module_name, filename) + if ext in [".py", ".pyc"]: + spec = importlib.util.spec_from_file_location(module_name, filename) + else: + msg = "configuration file should have a valid Python extension.\n" + util.warn(msg) + loader_ = importlib.machinery.SourceFileLoader(module_name, filename) + spec = importlib.util.spec_from_file_location(module_name, filename, loader=loader_) mod = importlib.util.module_from_spec(spec) sys.modules[module_name] = mod spec.loader.exec_module(mod)