mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
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
This commit is contained in:
parent
441977f57c
commit
ad4ff8cb3c
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# This file is part of gunicorn released under the MIT license.
|
# This file is part of gunicorn released under the MIT license.
|
||||||
# See the NOTICE for more information.
|
# See the NOTICE for more information.
|
||||||
import importlib.machinery
|
import importlib.util
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
@ -97,9 +97,10 @@ class Application(BaseApplication):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
module_name = '__config__'
|
module_name = '__config__'
|
||||||
mod = types.ModuleType(module_name)
|
spec = importlib.util.spec_from_file_location(module_name, filename)
|
||||||
loader = importlib.machinery.SourceFileLoader(module_name, filename)
|
mod = importlib.util.module_from_spec(spec)
|
||||||
loader.exec_module(mod)
|
sys.modules[module_name] = mod
|
||||||
|
spec.loader.exec_module(mod)
|
||||||
except Exception:
|
except Exception:
|
||||||
print("Failed to read config file: %s" % filename, file=sys.stderr)
|
print("Failed to read config file: %s" % filename, file=sys.stderr)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user