Skip to content

Commit

Permalink
watch for changes only apps non-excluded, fxies issue #919
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Sep 8, 2024
1 parent 89bc8dd commit 1ca29bd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions py4web/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1611,10 +1611,21 @@ def watch_folder_event_loop(apps_folder):
async def watch_folder(apps_folder):
"""Async function that watches a folder for changes"""
click.echo(f"watching ({mode}-mode) python file changes in: {apps_folder}")

# Then load all the apps as submodules
if os.environ.get("PY4WEB_APP_NAMES"):
app_names = os.environ.get("PY4WEB_APP_NAMES").split(",")
else:
app_names = None

async for changes in awatch(os.path.join(apps_folder)):
apps = []
for subpath in [pathlib.Path(pair[1]) for pair in changes]:
name = subpath.relative_to(apps_folder).parts[0]
# ignore apps not listed in app names
if app_names is not None and name not in app_names:
continue
# record the name of the app that changed
if subpath.suffix == ".py":
apps.append(name)
## manage `app_watch_handler` decorators
Expand All @@ -1625,11 +1636,13 @@ async def watch_folder(apps_folder):
APP_WATCH["tasks"][handler] = {}
APP_WATCH["tasks"][handler][subpath.as_posix()] = True

# reimport the apps the changed
for name in apps:
if mode == "lazy":
DIRTY_APPS[name] = True
else:
Reloader.import_app(name)

## in 'lazy' mode it's done in bottle's 'before_request' hook
if mode != "lazy":
try_app_watch_tasks()
Expand Down

0 comments on commit 1ca29bd

Please sign in to comment.