Skip to content

Commit

Permalink
Merge pull request #20 from najuzilu/misc-edits
Browse files Browse the repository at this point in the history
Miscellaneous edits
  • Loading branch information
najuzilu authored Sep 1, 2020
2 parents b08c78d + 4919a4f commit f5c056e
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 46 deletions.
1 change: 0 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
sphinx>=3.0
sphinx-book-theme
myst-nb
sphinxcontrib-prettyproof
sphinxcontrib-bibtex
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions sphinxcontrib/prettyproof/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
23 changes: 3 additions & 20 deletions sphinxcontrib/prettyproof/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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,
Expand All @@ -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")
Expand Down
1 change: 0 additions & 1 deletion sphinxcontrib/prettyproof/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<p class="admonition-title">')
Expand Down
18 changes: 18 additions & 0 deletions sphinxcontrib/prettyproof/proof_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
7 changes: 3 additions & 4 deletions tests/test_algorithm.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions tests/test_duplicate_label.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pathlib import Path
from subprocess import run
import pytest
import os


Expand All @@ -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
5 changes: 2 additions & 3 deletions tests/test_missing_ref.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pathlib import Path
from subprocess import run
import pytest
import os


Expand All @@ -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
6 changes: 3 additions & 3 deletions tests/test_proof.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down
7 changes: 3 additions & 4 deletions tests/test_sphinx_build.py
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit f5c056e

Please sign in to comment.