Skip to content

Commit 4ee4e7d

Browse files
committed
fix: do not change cwd if pointing to _quarto.yml
1 parent 079f009 commit 4ee4e7d

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

quartodoc/__main__.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import click
22
import contextlib
33
import os
4+
import sys
45
import time
56
import sphobjinv as soi
67
import yaml
@@ -115,7 +116,6 @@ def on_created(self, event):
115116

116117
def _enable_logs():
117118
import logging
118-
import sys
119119

120120
root = logging.getLogger("quartodoc")
121121
root.setLevel(logging.INFO)
@@ -181,32 +181,35 @@ def build(config, filter, dry_run, watch, verbose):
181181
if verbose:
182182
_enable_logs()
183183

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+
184188
builder = Builder.from_quarto_config(config)
185189
doc_build = partial(builder.build, filter=filter)
186190

187191
if dry_run:
188192
pass
189193
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()
210213

211214

212215
@click.command(

0 commit comments

Comments
 (0)