Skip to content

Commit 91692ec

Browse files
authored
Merge pull request #107 from machow/feat-cli
feat: add cli entrypoint
2 parents 6470891 + 869d873 commit 91692ec

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-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)

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ dev =
3939
jupyterlab
4040
jupytext
4141

42+
[options.entry_points]
43+
console_scripts =
44+
quartodoc = quartodoc.__main__:cli
45+
4246

4347
[project.scripts]
4448
quartodoc = "quartodoc.cli:main"

0 commit comments

Comments
 (0)