--reload-exclude cannot recursively ignore directories with '**' glob; changes outside --reload-dir trigger reload #2526
Replies: 1 comment 1 reply
-
When testing against a pattern, exclusion is currently done by I do not know of a way to ignore all folders that match a certain name: i.e. The The class below would allow for class FileFilter:
def __init__(self, config: Config):
default_includes = ["*.py"]
self.includes = [default for default in default_includes if default not in config.reload_excludes]
self.includes.extend(config.reload_includes)
self.includes = list(set(self.includes))
default_excludes = [".*", ".py[cod]", ".sw.*", "~*"]
self.excludes = [default for default in default_excludes if default not in config.reload_includes]
self.excludes.extend(config.reload_excludes)
self.excludes = list(set(self.excludes))
def __call__(self, path: Path) -> bool:
path_parts = [Path(part) for part in path.parts]
for include_pattern in self.includes:
if path.match(include_pattern):
if str(path).endswith(include_pattern):
return True # pragma: full coverage
for exclude_pattern in self.excludes:
# Exclude if the pattern matches the file path directly
if path.match(exclude_pattern):
return False # pragma: full coverage
# Exclude if the pattern matches any folder name directly
# (and doesn't contain a `/`)
if exclude_pattern.find("/") == -1 and any(part.match(exclude_pattern) for part in path_parts):
return False
return True
return False It would be best if Using Using If |
Beta Was this translation helpful? Give feedback.
-
Using uvicorn 0.32.1 (installed via pip) and python 3.9.18, and the attached directory structure (zipfile: uvicorn_test.zip), it seems that uvicorn is:
a) not properly honouring globs including the '**' pattern and
b) not properly honouring --reload-dir
steps to reproduce:
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
uvicorn --host 0.0.0.0 --port 4242 --reload --reload-dir myapp --reload-dir mylib/ --reload-exclude 'infra/**' myapp.api.main:app
echo "changed" >> infra/packages/foo/bar/baz.py
a) --reload-dir specifying only the 2 directories and
b) --reload-exclude specifically excluding subdirectories of infra/ using the '**' glob pattern.
uvicorn --host 0.0.0.0 --port 4242 --reload --reload-exclude 'infra/**' myapp.api.main:app
(removing --reload-dir)Output from uvicorn when I start it and modify the file in infra/packages/:
Another note: providing --reload-dir but not --reload gives the following output:
WARNING: Current configuration will not reload as not all conditions are met, please refer to documentation.
But I can't see anything about this in the documentation. I wouldn't expect to have to pass --reload if I'm passing --reload-dir, doesn't the one imply the other?
Beta Was this translation helpful? Give feedback.
All reactions