|
1 | 1 | import click
|
2 | 2 | import contextlib
|
3 | 3 | import os
|
| 4 | +import sys |
4 | 5 | import time
|
5 | 6 | import sphobjinv as soi
|
6 | 7 | import yaml
|
@@ -115,7 +116,6 @@ def on_created(self, event):
|
115 | 116 |
|
116 | 117 | def _enable_logs():
|
117 | 118 | import logging
|
118 |
| - import sys |
119 | 119 |
|
120 | 120 | root = logging.getLogger("quartodoc")
|
121 | 121 | root.setLevel(logging.INFO)
|
@@ -181,32 +181,35 @@ def build(config, filter, dry_run, watch, verbose):
|
181 | 181 | if verbose:
|
182 | 182 | _enable_logs()
|
183 | 183 |
|
| 184 | + # allow users to include files like _renderer.py in their quarto docs folder |
| 185 | + if config != "_quarto.yml": |
| 186 | + sys.path.append(str(Path(config).parent.absolute())) |
| 187 | + |
184 | 188 | builder = Builder.from_quarto_config(config)
|
185 | 189 | doc_build = partial(builder.build, filter=filter)
|
186 | 190 |
|
187 | 191 | if dry_run:
|
188 | 192 | pass
|
189 | 193 | else:
|
190 |
| - with chdir(Path(config).parent): |
191 |
| - if watch: |
192 |
| - pkg_path = get_package_path(builder.package) |
193 |
| - print(f"Watching {pkg_path} for changes...") |
194 |
| - observer = Observer() |
195 |
| - observer._event_queue.maxsize = 1 # the default is 0 which is infinite, and there isn't a way to set this in the constructor |
196 |
| - event_handler = QuartoDocFileChangeHandler(callback=doc_build) |
197 |
| - observer.schedule(event_handler, pkg_path, recursive=True) |
198 |
| - observer.schedule(event_handler, cfg_path, recursive=True) |
199 |
| - observer.start() |
200 |
| - try: |
201 |
| - while True: |
202 |
| - time.sleep(1) |
203 |
| - except KeyboardInterrupt: |
204 |
| - pass |
205 |
| - finally: |
206 |
| - observer.stop() |
207 |
| - observer.join() |
208 |
| - else: |
209 |
| - doc_build() |
| 194 | + if watch: |
| 195 | + pkg_path = get_package_path(builder.package) |
| 196 | + print(f"Watching {pkg_path} for changes...") |
| 197 | + observer = Observer() |
| 198 | + observer._event_queue.maxsize = 1 # the default is 0 which is infinite, and there isn't a way to set this in the constructor |
| 199 | + event_handler = QuartoDocFileChangeHandler(callback=doc_build) |
| 200 | + observer.schedule(event_handler, pkg_path, recursive=True) |
| 201 | + observer.schedule(event_handler, cfg_path, recursive=True) |
| 202 | + observer.start() |
| 203 | + try: |
| 204 | + while True: |
| 205 | + time.sleep(1) |
| 206 | + except KeyboardInterrupt: |
| 207 | + pass |
| 208 | + finally: |
| 209 | + observer.stop() |
| 210 | + observer.join() |
| 211 | + else: |
| 212 | + doc_build() |
210 | 213 |
|
211 | 214 |
|
212 | 215 | @click.command(
|
|
0 commit comments