Skip to content

Commit

Permalink
Fix benoitc#1576 - config file/module in GUNICORN_CMD_ARGS
Browse files Browse the repository at this point in the history
  • Loading branch information
Code0x58 committed Sep 16, 2017
1 parent 9e3dbd5 commit 6a2a8b3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions THANKS
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,4 @@ Ryan Peck <[email protected]>
Alex Conrad <[email protected]>
Nik Nyby <[email protected]>
Ed Morley <[email protected]>
Oliver Bristow <[email protected]>
22 changes: 11 additions & 11 deletions gunicorn/app/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,26 +147,26 @@ def load_config(self):
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
Expand Down
1 change: 1 addition & 0 deletions tests/config/test_cfg_alt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
proc_name = "not-fooey"
14 changes: 14 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
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")

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 6a2a8b3

Please sign in to comment.