Skip to content

Commit

Permalink
put back configuration file without py extension and deprecate it
Browse files Browse the repository at this point in the history
this change put back (and fix it) support of configuration files without
ython extension and warn about its usage.
  • Loading branch information
benoitc committed Nov 25, 2019
1 parent d31ac1d commit 0551587
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion gunicorn/app/base.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0551587

Please sign in to comment.