Skip to content

Commit

Permalink
Merge pull request #296 from machow/fix-working-dir
Browse files Browse the repository at this point in the history
fix: do not change cwd if pointing to _quarto.yml
  • Loading branch information
machow authored Oct 13, 2023
2 parents 3057d0f + 4ee4e7d commit f4005ce
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions quartodoc/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import click
import contextlib
import os
import sys
import time
import sphobjinv as soi
import yaml
Expand Down Expand Up @@ -115,7 +116,6 @@ def on_created(self, event):

def _enable_logs():
import logging
import sys

root = logging.getLogger("quartodoc")
root.setLevel(logging.INFO)
Expand Down Expand Up @@ -181,32 +181,35 @@ def build(config, filter, dry_run, watch, verbose):
if verbose:
_enable_logs()

# allow users to include files like _renderer.py in their quarto docs folder
if config != "_quarto.yml":
sys.path.append(str(Path(config).parent.absolute()))

builder = Builder.from_quarto_config(config)
doc_build = partial(builder.build, filter=filter)

if dry_run:
pass
else:
with chdir(Path(config).parent):
if watch:
pkg_path = get_package_path(builder.package)
print(f"Watching {pkg_path} for changes...")
observer = Observer()
observer._event_queue.maxsize = 1 # the default is 0 which is infinite, and there isn't a way to set this in the constructor
event_handler = QuartoDocFileChangeHandler(callback=doc_build)
observer.schedule(event_handler, pkg_path, recursive=True)
observer.schedule(event_handler, cfg_path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
finally:
observer.stop()
observer.join()
else:
doc_build()
if watch:
pkg_path = get_package_path(builder.package)
print(f"Watching {pkg_path} for changes...")
observer = Observer()
observer._event_queue.maxsize = 1 # the default is 0 which is infinite, and there isn't a way to set this in the constructor
event_handler = QuartoDocFileChangeHandler(callback=doc_build)
observer.schedule(event_handler, pkg_path, recursive=True)
observer.schedule(event_handler, cfg_path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
pass
finally:
observer.stop()
observer.join()
else:
doc_build()


@click.command(
Expand Down

0 comments on commit f4005ce

Please sign in to comment.