Skip to content

Commit 0e8f3c0

Browse files
authored
Merge pull request #54 from jasongrout/paths
Adopt the path convention of other directives like literalinclude
2 parents 2501e5b + e571e00 commit 0e8f3c0

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/jupyterlite_sphinx.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from sphinx.application import Sphinx
1616
from sphinx.util.docutils import SphinxDirective
17+
from sphinx.parsers import RSTParser
1718

1819

1920
CONTENT_DIR = "_contents"
@@ -185,12 +186,11 @@ def run(self):
185186
)
186187

187188
if self.arguments:
188-
notebook = self.arguments[0]
189-
190-
# If we didn't get an absolute path,
191-
# try to find the Notebook relatively to the source
192-
if not os.path.isabs(notebook):
193-
notebook = os.path.join(source_location, notebook)
189+
# As with other directives like literalinclude, an absolute path is
190+
# assumed to be relative to the document root, and a relative path
191+
# is assumed to be relative to the source file
192+
rel_filename, notebook = self.env.relfn2path(self.arguments[0])
193+
self.env.note_dependency(rel_filename)
194194

195195
notebook_name = os.path.basename(notebook)
196196

@@ -227,7 +227,7 @@ class RetroLiteDirective(_LiteDirective):
227227
iframe_cls = RetroLiteIframe
228228

229229

230-
class RetroLiteParser(rst.Parser):
230+
class RetroLiteParser(RSTParser):
231231
"""Sphinx source parser for Jupyter notebooks.
232232
233233
Shows the Notebook using retrolite."""
@@ -236,8 +236,10 @@ class RetroLiteParser(rst.Parser):
236236

237237
def parse(self, inputstring, document):
238238
title = os.path.splitext(os.path.basename(document.current_source))[0]
239+
# Make the "absolute" filename relative to the source root
240+
filename = "/" + os.path.relpath(document.current_source, self.env.app.srcdir)
239241
super().parse(
240-
f"{title}\n{'=' * len(title)}\n.. retrolite:: {document.current_source}",
242+
f"{title}\n{'=' * len(title)}\n.. retrolite:: {filename}",
241243
document,
242244
)
243245

0 commit comments

Comments
 (0)