From ad4ff8cb3cfff95e9eda3d58bab97b875b565151 Mon Sep 17 00:00:00 2001 From: benoitc Date: Fri, 22 Nov 2019 11:07:25 +0100 Subject: [PATCH] modernize the way the config module is loaded This change load the module as suggested in the Python docs : https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly which add the `__file__` attribute back and others possibly missing. This change remove the support of python 3.4 --- gunicorn/app/base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gunicorn/app/base.py b/gunicorn/app/base.py index 470b40ab..59d07060 100644 --- a/gunicorn/app/base.py +++ b/gunicorn/app/base.py @@ -2,7 +2,7 @@ # # This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. -import importlib.machinery +import importlib.util import os import sys import traceback @@ -97,9 +97,10 @@ class Application(BaseApplication): try: module_name = '__config__' - mod = types.ModuleType(module_name) - loader = importlib.machinery.SourceFileLoader(module_name, filename) - loader.exec_module(mod) + spec = importlib.util.spec_from_file_location(module_name, filename) + mod = importlib.util.module_from_spec(spec) + sys.modules[module_name] = mod + spec.loader.exec_module(mod) except Exception: print("Failed to read config file: %s" % filename, file=sys.stderr) traceback.print_exc()