Skip to content

Commit

Permalink
change --reload-extra-file option to get multiple files at once
Browse files Browse the repository at this point in the history
Co-authored-by: Randall Leeds <randall@bleeds.info>
  • Loading branch information
firekim2 and tilgovi committed Dec 27, 2023
1 parent bd734c5 commit 9180f55
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
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.
"""

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


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 = tmp_path / 'foo'
bar = tmp_path / 'bar'
baz = tmp_path / 'baz'
foo.touch()
bar.touch()
baz.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)])
with AltArgs(args):
app = NoConfigApp()
print(app.cfg.reload_extra_files)
assert app.cfg.reload_extra_files == [str(foo)]

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


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

0 comments on commit 9180f55

Please sign in to comment.