From 4919a4f8bff048bb1643c43cd480f3d2af487de0 Mon Sep 17 00:00:00 2001 From: najuzilu Date: Tue, 1 Sep 2020 15:19:19 +0200 Subject: [PATCH] misc edits --- docs/requirements.txt | 1 - setup.py | 11 ++++++----- sphinxcontrib/prettyproof/directive.py | 2 -- sphinxcontrib/prettyproof/domain.py | 23 +++-------------------- sphinxcontrib/prettyproof/nodes.py | 1 - sphinxcontrib/prettyproof/proof_type.py | 18 ++++++++++++++++++ tests/test_algorithm.py | 7 +++---- tests/test_duplicate_label.py | 5 ++--- tests/test_missing_ref.py | 5 ++--- tests/test_proof.py | 6 +++--- tests/test_sphinx_build.py | 7 +++---- 11 files changed, 40 insertions(+), 46 deletions(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 557f57c..5a54a06 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,5 +1,4 @@ sphinx>=3.0 sphinx-book-theme myst-nb -sphinxcontrib-prettyproof sphinxcontrib-bibtex \ No newline at end of file diff --git a/setup.py b/setup.py index fe1b695..d71a8cb 100644 --- a/setup.py +++ b/setup.py @@ -7,14 +7,15 @@ LONG_DESCRIPTION = """ This package contains a [Sphinx](http://www.sphinx-doc.org/en/master/) extension for producing proof, theorem, axiom, lemma, definition, criterion, remark, conjecture, -corollary, algorithm, exercise, example, property, observation and proposition directives. +corollary, algorithm, exercise, example, property, observation and proposition +directives. This project is maintained and supported by [najuzilu](https://github.com/najuzilu). """ SHORT_DESCRIPTION = """A Sphinx extension for producing proofs, theorems, axioms, lemmas, -definitions, criteria, remarks, conjectures, corollaries, algorithms, exercises, examples, -properties, observations and propositions.""" +definitions, criteria, remarks, conjectures, corollaries, algorithms, exercises, +examples, properties, observations and propositions.""" setup( @@ -24,8 +25,8 @@ author="QuantEcon", author_email="admin@quantecon.org", url="https://github.com/najuzilu/sphinxcontrib-prettyproof", - download_url="https://github.com/najuzilu/sphinxcontrib-prettyproof/archive/{}.tar.gz".format( - VERSION + download_url=( + f"https://github.com/najuzilu/sphinxcontrib-prettyproof/archive/{VERSION}.tar.gz" ), project_urls={ "Source": "https://github.com/najuzilu/sphinxcontrib-prettyproof", diff --git a/sphinxcontrib/prettyproof/directive.py b/sphinxcontrib/prettyproof/directive.py index 4169392..f227cd6 100644 --- a/sphinxcontrib/prettyproof/directive.py +++ b/sphinxcontrib/prettyproof/directive.py @@ -13,7 +13,6 @@ from sphinx.util import logging from docutils.parsers.rst import directives from sphinx.util.docutils import SphinxDirective -from docutils.statemachine import ViewList from .nodes import enumerable_node, unenumerable_node from .nodes import proof_node @@ -115,7 +114,6 @@ class ProofDirective(SphinxDirective): } def run(self) -> List[Node]: - content = ViewList() domain_name, typ = self.name.split(":")[0], self.name.split(":")[1] # If class in options add to class array diff --git a/sphinxcontrib/prettyproof/domain.py b/sphinxcontrib/prettyproof/domain.py index e82d047..5e15f35 100644 --- a/sphinxcontrib/prettyproof/domain.py +++ b/sphinxcontrib/prettyproof/domain.py @@ -20,8 +20,7 @@ from sphinx.util import logging from docutils import nodes from .directive import ProofDirective -from .proof_type import * - +from .proof_type import PROOF_TYPES logger = logging.getLogger(__name__) @@ -76,23 +75,7 @@ class ProofDomain(Domain): indices = {ProofIndex} - directives = { - "proof": ProofDirective, - "axiom": AxiomDirective, - "theorem": TheoremDirective, - "lemma": LemmaDirective, - "definition": DefinitionDirective, - "remark": RemarkDirective, - "conjecture": ConjectureDirective, - "corollary": CorollaryDirective, - "algorithm": AlgorithmDirective, - "criterion": CriterionDirective, - "exercise": ExerciseDirective, - "example": ExampleDirective, - "property": PropertyDirective, - "observation": ObservationDirective, - "proposition": PropositionDirective, - } + directives = {**{"proof": ProofDirective}, **PROOF_TYPES} def resolve_xref( self, @@ -107,7 +90,7 @@ def resolve_xref( try: match = env.proof_list[target] - except: + except Exception: path = self.env.doc2path(fromdocname)[:-3] msg = "label '{}' not found.".format(target) logger.warning(msg, location=path, color="red") diff --git a/sphinxcontrib/prettyproof/nodes.py b/sphinxcontrib/prettyproof/nodes.py index 5be8e56..9123fdd 100644 --- a/sphinxcontrib/prettyproof/nodes.py +++ b/sphinxcontrib/prettyproof/nodes.py @@ -45,7 +45,6 @@ def visit_unenumerable_node(self, node: Node) -> None: def depart_unenumerable_node(self, node: Node) -> None: typ = node.attributes.get("type", "") title = node.attributes.get("title", "") - _id = node.attributes.get("ids", [])[0] if title == "": idx = len(self.body) - self.body[-1::-1].index('

') diff --git a/sphinxcontrib/prettyproof/proof_type.py b/sphinxcontrib/prettyproof/proof_type.py index 4672cf0..965d395 100644 --- a/sphinxcontrib/prettyproof/proof_type.py +++ b/sphinxcontrib/prettyproof/proof_type.py @@ -93,3 +93,21 @@ class PropositionDirective(ElementDirective): """A custom proposition directive.""" name = "proposition" + + +PROOF_TYPES = { + "axiom": AxiomDirective, + "theorem": TheoremDirective, + "lemma": LemmaDirective, + "definition": DefinitionDirective, + "remark": RemarkDirective, + "conjecture": ConjectureDirective, + "corollary": CorollaryDirective, + "algorithm": AlgorithmDirective, + "criterion": CriterionDirective, + "exercise": ExerciseDirective, + "example": ExampleDirective, + "property": PropertyDirective, + "observation": ObservationDirective, + "proposition": PropositionDirective, +} diff --git a/tests/test_algorithm.py b/tests/test_algorithm.py index 909cc79..0fbd07b 100644 --- a/tests/test_algorithm.py +++ b/tests/test_algorithm.py @@ -1,7 +1,6 @@ from pathlib import Path -from subprocess import run, PIPE +from subprocess import run from bs4 import BeautifulSoup -import pytest import os path_tests = Path(__file__).parent.resolve() @@ -15,11 +14,11 @@ def test_build(tmpdir): os.chdir(path_book) # Clean build - run(f"make clean".split()) + run("make clean".split()) assert path_book.joinpath("conf.py").exists() # Build the book - run(f"make html".split(), check=True) + run("make html".split(), check=True) assert path_book.joinpath("build").exists() assert path_html.joinpath("index.html").exists() diff --git a/tests/test_duplicate_label.py b/tests/test_duplicate_label.py index 3c8e810..b96b4e9 100644 --- a/tests/test_duplicate_label.py +++ b/tests/test_duplicate_label.py @@ -1,6 +1,5 @@ from pathlib import Path from subprocess import run -import pytest import os @@ -13,10 +12,10 @@ def test_build(capfd): # Clean build os.chdir(path_book) - run(f"make clean".split()) + run("make clean".split()) assert path_book.joinpath("conf.py").exists() - run(f"make html".split(), check=True) + run("make html".split(), check=True) out, err = capfd.readouterr() assert "WARNING: duplicate algorithm label" in err diff --git a/tests/test_missing_ref.py b/tests/test_missing_ref.py index 617be4b..86e1553 100644 --- a/tests/test_missing_ref.py +++ b/tests/test_missing_ref.py @@ -1,6 +1,5 @@ from pathlib import Path from subprocess import run -import pytest import os @@ -13,10 +12,10 @@ def test_build(capfd): # Clean build os.chdir(path_book) - run(f"make clean".split()) + run("make clean".split()) assert path_book.joinpath("conf.py").exists() - run(f"make html".split(), check=True) + run("make html".split(), check=True) out, err = capfd.readouterr() assert "WARNING: label 'foo' not found" in err diff --git a/tests/test_proof.py b/tests/test_proof.py index d427a50..4c78360 100644 --- a/tests/test_proof.py +++ b/tests/test_proof.py @@ -1,5 +1,5 @@ from pathlib import Path -from subprocess import run, PIPE +from subprocess import run from bs4 import BeautifulSoup import pytest import os @@ -15,11 +15,11 @@ def test_build(tmpdir): os.chdir(path_book) # Clean build - run(f"make clean".split()) + run("make clean".split()) assert path_book.joinpath("conf.py").exists() # Build the book - run(f"make html".split(), check=True) + run("make html".split(), check=True) assert path_book.joinpath("build").exists() assert path_html.joinpath("index.html").exists() diff --git a/tests/test_sphinx_build.py b/tests/test_sphinx_build.py index 286faf2..bbdd665 100644 --- a/tests/test_sphinx_build.py +++ b/tests/test_sphinx_build.py @@ -1,6 +1,5 @@ from pathlib import Path -from subprocess import run, PIPE -import pytest +from subprocess import run import os path_tests = Path(__file__).parent.resolve() @@ -14,11 +13,11 @@ def test_build_book(tmpdir): os.chdir(path_book) # Clean build - run(f"make clean".split()) + run("make clean".split()) assert path_book.joinpath("conf.py").exists() # Build the book - run(f"make html".split(), check=True) + run("make html".split(), check=True) path_html = path_book.joinpath("build", "html") assert path_book.joinpath("build").exists()