8
8
from pathlib import Path
9
9
from watchdog .observers import Observer
10
10
from functools import partial
11
- from watchdog .events import FileSystemEventHandler
11
+ from watchdog .events import PatternMatchingEventHandler
12
12
from quartodoc import Builder , convert_inventory
13
+ from typing import List
13
14
14
15
def get_package_path (package_name ):
15
16
"""
@@ -21,11 +22,28 @@ def get_package_path(package_name):
21
22
except ModuleNotFoundError :
22
23
raise ModuleNotFoundError (f"Package { package_name } not found. Please install it in your environment." )
23
24
24
- class FileChangeHandler ( FileSystemEventHandler ):
25
+ class QuartoDocFileChangeHandler ( PatternMatchingEventHandler ):
25
26
"""
26
27
A handler for file changes.
27
28
"""
29
+
30
+ # Ignore patterns for the file watcher that are not relevant to the docs
31
+ py_ignore_patterns = [
32
+ '*/__pycache__/*' , # These are the compiled python code files which are automatically generated by Python
33
+ '*/.ipynb_checkpoints/*' , # This directory is created by Jupyter Notebook for auto-saving notebooks
34
+ '*/.vscode/*' , # If you're using Visual Studio Code, it creates this directory to store settings specific to that project.
35
+ '*/.idea/*' , # Similar to .vscode/, but for JetBrains IDEs like PyCharm.
36
+ '*/.git/*' , # i This directory is created by Git. It's not relevant to the docs.
37
+ '*/venv/*' , '*/env/*' , '*/.env/*' , # Common names for directories containing a Python virtual environment.
38
+ '*/.pytest_cache/*' , # This directory is created when you run Pytest.
39
+ '*/.eggs/*' , '*/dist/*' , '*/build/*' , '*/*.egg-info/*' , # These are typically created when building Python packages with setuptools.
40
+ '*.pyo' , # These are optimized .pyc files, created when Python is run with the -O flag.
41
+ '*.pyd' , # This is the equivalent of a .pyc file, but for C extensions on Windows.
42
+ '*/.mypy_cache/*' , # This directory is created when you run mypy.
43
+ ]
44
+
28
45
def __init__ (self , callback ):
46
+ super ().__init__ (ignore_patterns = self .py_ignore_patterns )
29
47
self .callback = callback
30
48
31
49
@classmethod
@@ -71,9 +89,6 @@ def cli():
71
89
pass
72
90
73
91
74
-
75
-
76
-
77
92
@click .command ()
78
93
@click .option ("--config" , default = "_quarto.yml" , help = "Change the path to the configuration file. The default is `./_quarto.yml`" )
79
94
@click .option ("--filter" , nargs = 1 , default = "*" , help = "Specify the filter to select specific files. The default is '*' which selects all files." )
@@ -97,7 +112,7 @@ def build(config, filter, dry_run, watch, verbose):
97
112
if watch :
98
113
pkg_path = get_package_path (builder .package )
99
114
print (f"Watching { pkg_path } for changes..." )
100
- event_handler = FileChangeHandler (callback = doc_build )
115
+ event_handler = QuartoDocFileChangeHandler (callback = doc_build )
101
116
observer = Observer ()
102
117
observer .schedule (event_handler , pkg_path , recursive = True )
103
118
observer .start ()
0 commit comments