Fix #1576 - config file/module in GUNICORN_CMD_ARGS

This commit is contained in:
Oliver Bristow 2017-09-02 18:03:19 +01:00
parent 9e3dbd59c6
commit 6a2a8b3298
4 changed files with 27 additions and 11 deletions

1
THANKS
View File

@ -170,3 +170,4 @@ Ryan Peck <ryan@rypeck.com>
Alex Conrad <alexandre.conrad@gmail.com>
Nik Nyby <nnyby@columbia.edu>
Ed Morley <edmorley@users.noreply.github.com>
Oliver Bristow <evilumbrella+github@gmail.com>

View File

@ -147,26 +147,26 @@ class Application(BaseApplication):
for k, v in cfg.items():
self.cfg.set(k.lower(), v)
env_args = parser.parse_args(self.cfg.get_cmd_args_from_env())
if args.config:
self.load_config_from_file(args.config)
elif env_args.config:
self.load_config_from_file(env_args.config)
else:
default_config = get_default_config_file()
if default_config is not None:
self.load_config_from_file(default_config)
# Load up environment configuration
env_vars = self.cfg.get_cmd_args_from_env()
if env_vars:
env_args = parser.parse_args(env_vars)
for k, v in vars(env_args).items():
if v is None:
continue
if k == "args":
continue
self.cfg.set(k.lower(), v)
for k, v in vars(env_args).items():
if v is None:
continue
if k == "args":
continue
self.cfg.set(k.lower(), v)
# Lastly, update the configuration with any command line
# settings.
# Lastly, update the configuration with any command line settings.
for k, v in vars(args).items():
if v is None:
continue

View File

@ -0,0 +1 @@
proc_name = "not-fooey"

View File

@ -18,8 +18,12 @@ from gunicorn.instrument import statsd
dirname = os.path.dirname(__file__)
def cfg_module():
return 'config.test_cfg'
def alt_cfg_module():
return 'config.test_cfg_alt'
def cfg_file():
return os.path.join(dirname, "config", "test_cfg.py")
def alt_cfg_file():
return os.path.join(dirname, "config", "test_cfg_alt.py")
def paster_ini():
return os.path.join(dirname, "..", "examples", "frameworks", "pylonstest", "nose.ini")
@ -329,6 +333,16 @@ def test_load_enviroment_variables_config(monkeypatch):
app = NoConfigApp()
assert app.cfg.workers == 4
def test_config_file_environment_variable(monkeypatch):
monkeypatch.setenv("GUNICORN_CMD_ARGS", "--config=" + alt_cfg_file())
with AltArgs():
app = NoConfigApp()
assert app.cfg.proc_name == "not-fooey"
assert app.cfg.config == alt_cfg_file()
with AltArgs(["prog_name", "--config", cfg_file()]):
app = NoConfigApp()
assert app.cfg.proc_name == "fooey"
assert app.cfg.config == cfg_file()
def test_invalid_enviroment_variables_config(monkeypatch, capsys):
monkeypatch.setenv("GUNICORN_CMD_ARGS", "--foo=bar")