From f5e205bbe12f001ecd33c928659eaed6bef50fde Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Fri, 12 May 2023 13:55:33 -0600 Subject: [PATCH] Remove the `includenodoc` and `customcarditem` directives (#270) * Remove the `includenodoc` and `customcarditem` directives * Fix fmt (cherry picked from commit 86af1b76161df00384db14bb5fb2757f97b73567) --- docs/conf.py | 4 +- docs/custom_directives.py | 129 +------------------------------------- 2 files changed, 4 insertions(+), 129 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 9e34f4e..e1ba037 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -36,7 +36,7 @@ import qiskit_sphinx_theme import qiskit_finance -from custom_directives import IncludeDirective, CustomCalloutItemDirective, CustomCardItemDirective +from custom_directives import CustomCalloutItemDirective # Set env flag so that we can doc functions that may otherwise not be loaded # see for example interactive visualizations in qiskit.visualization. @@ -203,7 +203,5 @@ def setup(app): - app.add_directive("includenodoc", IncludeDirective) - app.add_directive("customcarditem", CustomCardItemDirective) app.add_directive("customcalloutitem", CustomCalloutItemDirective) app.setup_extension("versionutils") diff --git a/docs/custom_directives.py b/docs/custom_directives.py index 7094491..4e621b7 100644 --- a/docs/custom_directives.py +++ b/docs/custom_directives.py @@ -1,132 +1,9 @@ +import os +import re + from docutils.parsers.rst import Directive, directives from docutils.statemachine import StringList from docutils import nodes -import re -import os - -try: - FileNotFoundError -except NameError: - FileNotFoundError = IOError - - -class IncludeDirective(Directive): - """Include source file without docstring at the top of file. - - Implementation just replaces the first docstring found in file - with '' once. - - Example usage: - - .. includenodoc:: /beginner/examples_tensor/two_layer_net_tensor.py - - """ - - # defines the parameter the directive expects - # directives.unchanged means you get the raw value from RST - required_arguments = 1 - optional_arguments = 0 - final_argument_whitespace = True - has_content = False - add_index = False - - docstring_pattern = r'"""(?P(?:.|[\r\n])*?)"""\n' - docstring_regex = re.compile(docstring_pattern) - - def run(self): - document = self.state.document - env = document.settings.env - rel_filename, filename = env.relfn2path(self.arguments[0]) - - try: - text = open(filename).read() - text_no_docstring = self.docstring_regex.sub("", text, count=1) - - code_block = nodes.literal_block(text=text_no_docstring) - return [code_block] - except FileNotFoundError as e: - print(e) - return [] - - -class CustomCardItemDirective(Directive): - option_spec = { - "header": directives.unchanged, - "image": directives.unchanged, - "link": directives.unchanged, - "card_description": directives.unchanged, - "tags": directives.unchanged, - } - - def run(self): - try: - if "header" in self.options: - header = self.options["header"] - else: - raise ValueError("header not doc found") - - if "image" in self.options: - image = "" - else: - image = "_static/img/thumbnails/default.png" - - if "link" in self.options: - link = self.options["link"] - else: - link = "" - - if "card_description" in self.options: - card_description = self.options["card_description"] - else: - card_description = "" - - if "tags" in self.options: - tags = self.options["tags"] - else: - tags = "" - - except FileNotFoundError as e: - print(e) - return [] - except ValueError as e: - print(e) - raise - return [] - - card_rst = CARD_TEMPLATE.format( - header=header, image=image, link=link, card_description=card_description, tags=tags - ) - card_list = StringList(card_rst.split("\n")) - card = nodes.paragraph() - self.state.nested_parse(card_list, self.content_offset, card) - return [card] - - -CARD_TEMPLATE = """ -.. raw:: html - -
- -
- -
- -
-

{header}

-
- -

{card_description}

- -

{tags}

- -
{image}
- -
- -
- -
-""" class CustomCalloutItemDirective(Directive):