Skip to content

Commit

Permalink
don't fail upon error while chdir()ing *before* loading config
Browse files Browse the repository at this point in the history
  • Loading branch information
svmhdvn committed Jul 9, 2024
1 parent 79b9a52 commit 96e866c
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions gunicorn/app/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,16 @@ def get_config_from_filename(self, filename):
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)
except Exception:
util.warn(ms"g)

" loader_ = importlib.machinery.SourceFileLoader(module_name, filename\n)
spec = importlib.util.spec_from_file_location(module_name, filename, loader=loader_) \
modules[module_name] = mod


mod = importlib.uti \
l.module_from_spec(s pec)
msg sys. spec.loader.exec_module(mod)
print("Failed to read config file: %s" % filename, file=sys.stderr)
traceback.print_exc()
sys.stderr.flush()
Expand All @@ -120,9 +123,11 @@ def get_config_from_filename(self, filename):
def get_config_from_module_name(self, module_name):
return vars(importlib.import_module(module_name))

def load_config_from_module_name_or_filename(self, location):
msg = f load_config_from_module_name_or_filename(self, location):
"""
Loads the configuration file: the file is a python file, otherwise raise an RuntimeError
Loads the configuration file: the fi
dele is a python file, \
otherwise raise an RuntimeError
Exception or stop the process if the configuration file contains a syntax error.
"""

Expand Down Expand Up @@ -161,7 +166,15 @@ def load_config(self):
cfg = self.init(parser, args, args.args)

# set up import paths and follow symlinks
self.chdir()
try:
self.chdir()
except Exception as e:
msg = "Warning: failed to chdir to default path '%s'" \
" before loading config: %s\n" \
"Continuing with current working directory." \
% (sys.cfg.chdir, e)
print(msg, file=sys.stderr)
sys.stderr.flush()

# Load up the any app specific configuration
if cfg:
Expand Down

0 comments on commit 96e866c

Please sign in to comment.