Skip to content

Commit 56a9f68

Browse files
authored
Don't include cwd() when non-empty --reload-dirs is passed (#2598)
1 parent bdf95fd commit 56a9f68

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

tests/supervisors/test_reload.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -306,24 +306,17 @@ def test_watchfiles_no_changes(self) -> None:
306306

307307

308308
@pytest.mark.skipif(WatchFilesReload is None, reason="watchfiles not available")
309-
def test_should_watch_one_dir_cwd(mocker: MockerFixture, reload_directory_structure: Path):
309+
def test_should_watch_cwd(mocker: MockerFixture, reload_directory_structure: Path):
310310
mock_watch = mocker.patch("uvicorn.supervisors.watchfilesreload.watch")
311-
app_dir = reload_directory_structure / "app"
312-
app_first_dir = reload_directory_structure / "app_first"
313311

314-
with as_cwd(reload_directory_structure):
315-
config = Config(
316-
app="tests.test_config:asgi_app",
317-
reload=True,
318-
reload_dirs=[str(app_dir), str(app_first_dir)],
319-
)
320-
WatchFilesReload(config, target=run, sockets=[])
321-
mock_watch.assert_called_once()
322-
assert mock_watch.call_args[0] == (Path.cwd(),)
312+
config = Config(app="tests.test_config:asgi_app", reload=True, reload_dirs=[])
313+
WatchFilesReload(config, target=run, sockets=[])
314+
mock_watch.assert_called_once()
315+
assert mock_watch.call_args[0] == (Path.cwd(),)
323316

324317

325318
@pytest.mark.skipif(WatchFilesReload is None, reason="watchfiles not available")
326-
def test_should_watch_separate_dirs_outside_cwd(mocker: MockerFixture, reload_directory_structure: Path):
319+
def test_should_watch_multiple_dirs(mocker: MockerFixture, reload_directory_structure: Path):
327320
mock_watch = mocker.patch("uvicorn.supervisors.watchfilesreload.watch")
328321
app_dir = reload_directory_structure / "app"
329322
app_first_dir = reload_directory_structure / "app_first"
@@ -337,7 +330,6 @@ def test_should_watch_separate_dirs_outside_cwd(mocker: MockerFixture, reload_di
337330
assert set(mock_watch.call_args[0]) == {
338331
app_dir,
339332
app_first_dir,
340-
Path.cwd(),
341333
}
342334

343335

uvicorn/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ def __init__(
313313
+ "directories, watching current working directory.",
314314
reload_dirs,
315315
)
316-
self.reload_dirs = [Path(os.getcwd())]
316+
self.reload_dirs = [Path.cwd()]
317317

318318
logger.info(
319319
"Will watch for changes in these directories: %s",

uvicorn/supervisors/watchfilesreload.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ def __init__(
6363
self.reloader_name = "WatchFiles"
6464
self.reload_dirs = []
6565
for directory in config.reload_dirs:
66-
if Path.cwd() not in directory.parents:
67-
self.reload_dirs.append(directory)
68-
if Path.cwd() not in self.reload_dirs:
69-
self.reload_dirs.append(Path.cwd())
66+
self.reload_dirs.append(directory)
7067

7168
self.watch_filter = FileFilter(config)
7269
self.watcher = watch(

0 commit comments

Comments
 (0)