Skip to content

Commit 869d873

Browse files
committed
fix: ensure cli command can import _renderer.py file
1 parent d3d7c6e commit 869d873

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ examples/%/_site: examples/%/_quarto.yml
55
cd examples/$* \
66
&& quarto add --no-prompt ../.. \
77
&& quarto add --no-prompt quarto-ext/shinylive
8-
cd examples/$* && python -m quartodoc build _quarto.yml --verbose
9-
cd examples/$* && python -m quartodoc interlinks
8+
cd examples/$* && quartodoc build _quarto.yml --verbose
9+
cd examples/$* && quartodoc interlinks
1010
quarto render $(dir $<)
1111

1212
docs/examples/%: examples/%/_site
@@ -17,8 +17,8 @@ docs-build-examples: docs/examples/single-page docs/examples/pkgdown docs/exampl
1717

1818
docs-build: docs-build-examples
1919
cd docs && quarto add --no-prompt ..
20-
cd docs && python -m quartodoc build
21-
cd docs && python -m quartodoc interlinks
20+
cd docs && quartodoc build
21+
cd docs && quartodoc interlinks
2222
quarto render docs
2323

2424
requirements-dev.txt:

quartodoc/renderers/base.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,22 @@ def from_config(cls, cfg: "dict | Renderer | str"):
7474
raise TypeError(type(cfg))
7575

7676
if style.endswith(".py"):
77+
import os
78+
import sys
7779
import importlib
7880

79-
mod = importlib.import_module(style.rsplit(".", 1)[0])
80-
return mod.Renderer(**cfg)
81+
# temporarily add the current directory to sys path and import
82+
# this ensures that even if we're executing the quartodoc cli,
83+
# we can import a custom _renderer.py file.
84+
# it probably isn't ideal, but seems like a more convenient
85+
# option than requiring users to register entrypoints.
86+
sys.path.append(os.getcwd())
87+
88+
try:
89+
mod = importlib.import_module(style.rsplit(".", 1)[0])
90+
return mod.Renderer(**cfg)
91+
finally:
92+
sys.path.pop()
8193

8294
subclass = cls._registry[style]
8395
return subclass(**cfg)

0 commit comments

Comments
 (0)