From 4448569e69835d92661d5fd34cf20e485842c8ad Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Tue, 31 Oct 2017 07:51:18 +0300 Subject: [PATCH 1/3] Add test and update documentation --- docs/source/settings.rst | 4 ++++ gunicorn/config.py | 4 ++++ tests/test_config.py | 14 ++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/docs/source/settings.rst b/docs/source/settings.rst index 248f061ee..37725e7d5 100644 --- a/docs/source/settings.rst +++ b/docs/source/settings.rst @@ -42,6 +42,10 @@ application specific configuration. Loading the config from a Python module requires the ``python:`` prefix. +.. versionchanged:: 19.8 + Pre-19.4 behavior of loading a config file without a ``python:`` + prefix is now restored. + Server Socket ------------- diff --git a/gunicorn/config.py b/gunicorn/config.py index cab56ea53..56d8ca76b 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -519,6 +519,10 @@ class ConfigFile(Setting): .. versionchanged:: 19.4 Loading the config from a Python module requires the ``python:`` prefix. + + .. versionchanged:: 19.8 + Pre-19.4 behavior of loading a config file without a ``python:`` + prefix is now restored. """ class Bind(Setting): diff --git a/tests/test_config.py b/tests/test_config.py index 714d29262..31424e830 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -238,6 +238,20 @@ def test_load_config_module(): assert app.cfg.proc_name == "fooey" +@pytest.mark.parametrize("options", [ + ["-c", cfg_module()], + ["-c", cfg_file()], +]) +def test_load_fallback(options): + cmdline = ["prog_name"] + cmdline.extend(options) + with AltArgs(cmdline): + app = NoConfigApp() + assert app.cfg.bind == ["unix:/tmp/bar/baz"] + assert app.cfg.workers == 3 + assert app.cfg.proc_name == "fooey" + + def test_cli_overrides_config(): with AltArgs(["prog_name", "-c", cfg_file(), "-b", "blarney"]): app = NoConfigApp() From 2b3088fb7259013e7136a58062f805bdebf3b098 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Tue, 31 Oct 2017 07:58:37 +0300 Subject: [PATCH 2/3] Restore changes from original PR --- gunicorn/app/base.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gunicorn/app/base.py b/gunicorn/app/base.py index 2caa9e09d..56ef5169e 100644 --- a/gunicorn/app/base.py +++ b/gunicorn/app/base.py @@ -121,12 +121,14 @@ def load_config_from_module_name_or_filename(self, location): if location.startswith("python:"): module_name = location[len("python:"):] cfg = self.get_config_from_module_name(module_name) - else: - if location.startswith("file:"): - filename = location[len("file:"):] - else: - filename = location + elif location.startswith("file:"): + filename = location[len("file:"):] cfg = self.get_config_from_filename(filename) + else: + try: + cfg = self.get_config_from_module_name(location) + except ImportError: + cfg = self.get_config_from_filename(location) for k, v in cfg.items(): # Ignore unknown names From 9b75c772f5455a2416d5664b40cf82a008deb0e1 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Tue, 31 Oct 2017 08:00:53 +0300 Subject: [PATCH 3/3] tweak test name --- tests/test_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_config.py b/tests/test_config.py index 31424e830..dfce678c3 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -242,7 +242,7 @@ def test_load_config_module(): ["-c", cfg_module()], ["-c", cfg_file()], ]) -def test_load_fallback(options): +def test_load_config_fallback(options): cmdline = ["prog_name"] cmdline.extend(options) with AltArgs(cmdline):