Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change --reload-extra-file option to get multiple files at once #3124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion gunicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import copy
import grp
import inspect
import itertools
import os
import pwd
import re
Expand Down Expand Up @@ -940,15 +941,22 @@ class ReloadExtraFiles(Setting):
section = "Debugging"
cli = ["--reload-extra-file"]
meta = "FILES"
validator = validate_list_of_existing_files
default = []
nargs = '+'
desc = """\
Extends :ref:`reload` option to also watch and reload on additional files
(e.g., templates, configurations, specifications, etc.).

.. versionadded:: 19.8
.. versionchanged:: 22.0
It is now possible to pass multiple arguments to each instance of the flag.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs explanation for those previously valid command lines (this option appearing last, omitting =) broken:

You may need to use the -- separator to distinguish option arguments from application name, e.g.
gunicorn --reload-extra-file file1 file2 -- project:wsgiapp

"""

# Once Python 3.8 is required, the `extend` makes this overload unnecessary
def validator(val):
flat = list(itertools.chain.from_iterable(val))
return validate_list_of_existing_files(flat)


class Spew(Setting):
name = "spew"
Expand Down
30 changes: 30 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,36 @@ def nworkers_changed_3(server, new_value, old_value):
assert c.nworkers_changed(1, 2, 3) == 3


def test_reload_extra_files(tmp_path):
try:
tmp_path.mkdir()
except FileExistsError:
pass

foo_path = tmp_path / 'foo'
bar_path = tmp_path / 'bar'
baz_path = tmp_path / 'baz'
foo_path.touch()
bar_path.touch()
baz_path.touch()

args = ["prog_name", "--config", cfg_file()]
with AltArgs(args):
app = NoConfigApp()
assert app.cfg.reload_extra_files == []

args.extend(['--reload-extra-file', str(foo_path)])
with AltArgs(args):
app = NoConfigApp()
print(app.cfg.reload_extra_files)
assert app.cfg.reload_extra_files == [str(foo_path)]

args.extend(['--reload-extra-file', str(bar_path), str(baz_path)])
with AltArgs(args):
app = NoConfigApp()
assert app.cfg.reload_extra_files == [str(foo_path), str(bar_path), str(baz_path)]


def test_statsd_host():
c = config.Config()
assert c.statsd_host is None
Expand Down