Skip to content

Commit

Permalink
update docs/extensions/fancy_include.py with git_cast_file2repos.py
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jan 4, 2023
1 parent 61315c1 commit 7825548
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions docs/extensions/fancy_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
will display the doc string formatted with the first line as a
heading, a code block with line numbers, and the image file.
"""
import io
import os.path as op
import pathlib

from docutils.statemachine import ViewList
from docutils.parsers.rst import Directive
Expand All @@ -42,13 +41,13 @@ class IncludeDirective(Directive):

def run(self):
path = self.state.document.settings.env.config.fancy_include_path
full_path = op.join(path, self.arguments[0])
path = pathlib.Path(path)
full_path = path / self.arguments[0]

with io.open(full_path, "r") as myfile:
text = myfile.read()
text = full_path.read_text()

# add reference
name = op.basename(full_path)[:-3]
name = full_path.stem
rst = [".. _example_{}:".format(name),
"",
]
Expand All @@ -65,18 +64,18 @@ def run(self):

# image
for ext in [".png", ".jpg"]:
image_path = full_path[:-3] + ext
if op.exists(image_path):
image_path = full_path.with_suffix(ext)
if image_path.exists():
break
else:
image_path = ""
if image_path:
rst.append(".. figure:: {}".format(image_path))
rst.append(".. figure:: {}".format(image_path.as_posix()))
rst.append("")

# download file
rst.append(":download:`{}<{}>`".format(
op.basename(full_path), full_path))
rst.append(":download:`{} <{}>`".format(
full_path.name, full_path.as_posix()))

# code
rst.append("")
Expand Down

0 comments on commit 7825548

Please sign in to comment.