Skip to content

Commit cd8547c

Browse files
committed
Add BaseWatchfiles class
1 parent 1bec904 commit cd8547c

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

jupyter_server/services/contents/filemanager.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from datetime import datetime
1111

1212
import nbformat
13+
import watchfiles
1314
from anyio.to_thread import run_sync
1415
from jupyter_core.paths import exists, is_file_hidden, is_hidden
1516
from send2trash import send2trash
@@ -22,7 +23,7 @@
2223

2324
from .filecheckpoints import AsyncFileCheckpoints, FileCheckpoints
2425
from .fileio import AsyncFileManagerMixin, FileManagerMixin
25-
from .manager import AsyncContentsManager, ContentsManager
26+
from .manager import AsyncContentsManager, BaseWatchfiles, ContentsManager
2627

2728
try:
2829
from os.path import samefile
@@ -33,9 +34,15 @@
3334
_script_exporter = None
3435

3536

37+
class Watchfiles(BaseWatchfiles):
38+
watch = watchfiles.watch
39+
awatch = watchfiles.awatch
40+
Change = watchfiles.Change
41+
42+
3643
class FileContentsManager(FileManagerMixin, ContentsManager):
3744

38-
import watchfiles
45+
watchfiles = Watchfiles
3946

4047
root_dir = Unicode(config=True)
4148

@@ -549,7 +556,7 @@ def get_kernel_path(self, path, model=None):
549556

550557
class AsyncFileContentsManager(FileContentsManager, AsyncFileManagerMixin, AsyncContentsManager):
551558

552-
import watchfiles
559+
watchfiles = Watchfiles
553560

554561
@default("checkpoints_class")
555562
def _checkpoints_class_default(self):

jupyter_server/services/contents/manager.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import json
66
import re
77
import warnings
8+
from enum import IntEnum
89
from fnmatch import fnmatch
910

1011
from nbformat import ValidationError, sign
@@ -34,11 +35,19 @@
3435
copy_pat = re.compile(r"\-Copy\d*\.")
3536

3637

37-
class NoWatchfilesAPI:
38-
pass
38+
class BaseWatchfiles:
39+
"""File system change notifyer API
3940
41+
Override this attribute in subclasses if the file system supports file change notifications.
42+
"""
43+
44+
def watch(*paths, **kwargs):
45+
pass
4046

41-
NOWATCHFILESAPI = NoWatchfilesAPI()
47+
async def awatch(*paths, **kwargs):
48+
pass
49+
50+
Change = IntEnum
4251

4352

4453
class ContentsManager(LoggingConfigurable):
@@ -416,19 +425,7 @@ def rename_file(self, old_path, new_path):
416425
# ContentsManager API part 2: methods that have useable default
417426
# implementations, but can be overridden in subclasses.
418427

419-
@property
420-
def watchfiles(self):
421-
"""File system change notifyer
422-
423-
Override this method in subclasses if the file system supports change notifications.
424-
425-
Returns
426-
-------
427-
api : class
428-
The supported API for file system change notifications. Loosely follows the API of the
429-
watchfiles Python package (can be a subset of it).
430-
"""
431-
return NOWATCHFILESAPI
428+
watchfiles = BaseWatchfiles
432429

433430
def delete(self, path):
434431
"""Delete a file/directory and any associated checkpoints."""

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ install_requires =
5353
terminado>=0.8.3
5454
tornado>=6.1.0
5555
traitlets>=5.1
56-
watchfiles>=0.13
56+
watchfiles==0.13
5757
websocket-client
5858

5959
[options.extras_require]

0 commit comments

Comments
 (0)