From 7fbeb07b0431a4305b22c013520a829144701e1c Mon Sep 17 00:00:00 2001 From: firekim2 Date: Fri, 3 Aug 2018 11:24:04 +0900 Subject: [PATCH] change --reload-extra-file option to get multiple files at once Co-authored-by: Randall Leeds --- gunicorn/config.py | 10 +++++++++- tests/test_config.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/gunicorn/config.py b/gunicorn/config.py index e7e4fac54..98758999a 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -9,6 +9,7 @@ import copy import grp import inspect +import itertools import os import pwd import re @@ -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): + flat = list(itertools.chain.from_iterable(val)) + return validate_list_of_existing_files(flat) + class Spew(Setting): name = "spew" diff --git a/tests/test_config.py b/tests/test_config.py index c094f6a21..da5a83c6f 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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