From 7825548e7bd9ec92b5dfc9f302ef5ea1c0f4304e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Wed, 4 Jan 2023 18:23:12 +0100 Subject: [PATCH] update docs/extensions/fancy_include.py with git_cast_file2repos.py --- docs/extensions/fancy_include.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/docs/extensions/fancy_include.py b/docs/extensions/fancy_include.py index 4e387eb..d3f1a95 100644 --- a/docs/extensions/fancy_include.py +++ b/docs/extensions/fancy_include.py @@ -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 @@ -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), "", ] @@ -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("")