mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Merge pull request #1068 from slava-sh/836-add-config-type-prefix
Prefix config file with its type Fixes #836
This commit is contained in:
commit
ec3664dd30
@ -47,8 +47,8 @@ You can now run the app with the following command::
|
||||
Commonly Used Arguments
|
||||
^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
* ``-c CONFIG, --config=CONFIG`` - Specify the path to a config file or
|
||||
Python module.
|
||||
* ``-c CONFIG, --config=CONFIG`` - Specify a config file in the form
|
||||
``$(PATH)``, ``file:$(PATH)``, or ``python:$(MODULE_NAME)``.
|
||||
* ``-b BIND, --bind=BIND`` - Specify a server socket to bind. Server sockets
|
||||
can be any of ``$(HOST)``, ``$(HOST):$(PORT)``, or ``unix:$(PATH)``.
|
||||
An IP is a valid ``$(HOST)``.
|
||||
|
||||
@ -16,14 +16,20 @@ Config File
|
||||
config
|
||||
~~~~~~
|
||||
|
||||
* ``-c FILE, --config FILE``
|
||||
* ``-c CONFIG, --config CONFIG``
|
||||
* ``None``
|
||||
|
||||
The path to a Gunicorn config file, or python module.
|
||||
The Gunicorn config file.
|
||||
|
||||
A string of the form ``PATH``, ``file:PATH``, or ``python:MODULE_NAME``.
|
||||
|
||||
Only has an effect when specified on the command line or as part of an
|
||||
application specific configuration.
|
||||
|
||||
.. versionchanged:: 19.4
|
||||
Loading the config from a Python module requires the ``python:``
|
||||
prefix.
|
||||
|
||||
Server Socket
|
||||
-------------
|
||||
|
||||
|
||||
@ -108,10 +108,15 @@ class Application(BaseApplication):
|
||||
Exception or stop the process if the configuration file contains a syntax error.
|
||||
"""
|
||||
|
||||
try:
|
||||
cfg = self.get_config_from_module_name(module_name=location)
|
||||
except ImportError:
|
||||
cfg = self.get_config_from_filename(filename=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
|
||||
cfg = self.get_config_from_filename(filename)
|
||||
|
||||
for k, v in cfg.items():
|
||||
# Ignore unknown names
|
||||
@ -127,9 +132,7 @@ class Application(BaseApplication):
|
||||
return cfg
|
||||
|
||||
def load_config_from_file(self, filename):
|
||||
return self.load_config_from_module_name_or_filename(
|
||||
location=filename
|
||||
)
|
||||
return self.load_config_from_module_name_or_filename(location=filename)
|
||||
|
||||
def load_config(self):
|
||||
# parse console args
|
||||
|
||||
@ -465,14 +465,20 @@ class ConfigFile(Setting):
|
||||
name = "config"
|
||||
section = "Config File"
|
||||
cli = ["-c", "--config"]
|
||||
meta = "FILE"
|
||||
meta = "CONFIG"
|
||||
validator = validate_string
|
||||
default = None
|
||||
desc = """\
|
||||
The path to a Gunicorn config file, or python module.
|
||||
The Gunicorn config file.
|
||||
|
||||
A string of the form ``PATH``, ``file:PATH``, or ``python:MODULE_NAME``.
|
||||
|
||||
Only has an effect when specified on the command line or as part of an
|
||||
application specific configuration.
|
||||
|
||||
.. versionchanged:: 19.4
|
||||
Loading the config from a Python module requires the ``python:``
|
||||
prefix.
|
||||
"""
|
||||
|
||||
class Bind(Setting):
|
||||
|
||||
@ -183,8 +183,15 @@ def test_load_config():
|
||||
assert app.cfg.workers == 3
|
||||
assert app.cfg.proc_name == "fooey"
|
||||
|
||||
def test_load_config_explicit_file():
|
||||
with AltArgs(["prog_name", "-c", "file:%s" % cfg_file()]):
|
||||
app = NoConfigApp()
|
||||
assert app.cfg.bind == ["unix:/tmp/bar/baz"]
|
||||
assert app.cfg.workers == 3
|
||||
assert app.cfg.proc_name == "fooey"
|
||||
|
||||
def test_load_config_module():
|
||||
with AltArgs(["prog_name", "-c", cfg_module()]):
|
||||
with AltArgs(["prog_name", "-c", "python:%s" % cfg_module()]):
|
||||
app = NoConfigApp()
|
||||
assert app.cfg.bind == ["unix:/tmp/bar/baz"]
|
||||
assert app.cfg.workers == 3
|
||||
@ -197,7 +204,7 @@ def test_cli_overrides_config():
|
||||
assert app.cfg.proc_name == "fooey"
|
||||
|
||||
def test_cli_overrides_config_module():
|
||||
with AltArgs(["prog_name", "-c", cfg_module(), "-b", "blarney"]):
|
||||
with AltArgs(["prog_name", "-c", "python:%s" % cfg_module(), "-b", "blarney"]):
|
||||
app = NoConfigApp()
|
||||
assert app.cfg.bind == ["blarney"]
|
||||
assert app.cfg.proc_name == "fooey"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user