Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions sphinx_proof/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ def run(self) -> List[Node]:
node_id = f"{label}"
else:
self.options["noindex"] = True
label = f"{realtyp}-{serial_no}"
node_id = f"{realtyp}-{serial_no}"
# new_serialno() is unique per document only; include docname
# so unlabeled directives do not collide across files.
doc_id = env.docname.replace("/", "-")
label = f"{doc_id}-{realtyp}-{serial_no}"
node_id = label
ids = [node_id]

# Duplicate label warning
Expand Down
6 changes: 6 additions & 0 deletions tests/books/test-unlabeled-multidoc/bar.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bar
===

.. prf:example::

An unlabeled example in bar.
51 changes: 51 additions & 0 deletions tests/books/test-unlabeled-multidoc/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = "sphinx-proof Test"
copyright = "2020, QuantEcon Developers"
author = "QuantEcon Developers"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ["sphinx_proof", "myst_parser"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "alabaster"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['_static']
6 changes: 6 additions & 0 deletions tests/books/test-unlabeled-multidoc/foo.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
foo
===

.. prf:example::

An unlabeled example in foo.
8 changes: 8 additions & 0 deletions tests/books/test-unlabeled-multidoc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
index
=====

.. toctree::
:maxdepth: 1

foo
bar
14 changes: 14 additions & 0 deletions tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ def test_duplicate_label(app, warnings):
assert "WARNING: duplicate algorithm label" in warnings(app)


@pytest.mark.sphinx("html", testroot="unlabeled-multidoc")
def test_unlabeled_examples_across_documents(app, warnings):
"""Unlabeled examples in different files must not share a label."""
app.build()
examples = {
label: info
for label, info in app.env.proof_list.items()
if info["realtype"] == "example"
}
assert len(examples) == 2
assert {info["docname"] for info in examples.values()} == {"foo", "bar"}
assert "duplicate example label" not in warnings(app)


# Tests for Proofs
@pytest.mark.sphinx("html", testroot="mybook")
@pytest.mark.parametrize(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_html/algorithm/_algo_nonumber.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="proof algorithm admonition" id="algorithm-0">
<p class="admonition-title" id="algorithm-0"><span class="caption-number">Algorithm </span> (Test algorithm directive)</p>
<div class="proof algorithm admonition" id="algorithm-_algo_nonumber-algorithm-0">
<p class="admonition-title" id="algorithm-_algo_nonumber-algorithm-0"><span class="caption-number">Algorithm </span> (Test algorithm directive)</p>
<section class="algorithm-content" id="proof-content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</section>
Expand Down
6 changes: 3 additions & 3 deletions tests/test_latex/test_latex_build.tex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


\chapter{content 2}
\label{\detokenize{algorithm/_algo_nonumber:content-2}}\label{\detokenize{algorithm/_algo_nonumber::doc}}\label{algorithm/_algo_nonumber:algorithm-0}
\label{\detokenize{algorithm/_algo_nonumber:content-2}}\label{\detokenize{algorithm/_algo_nonumber::doc}}\label{algorithm/_algo_nonumber:algorithm-_algo_nonumber-algorithm-0}
\begin{sphinxadmonition}{note}{Algorithm (Test algorithm directive)}


Expand Down Expand Up @@ -134,8 +134,8 @@ \chapter{content 5}
\renewcommand{\indexname}{Proof Index}
\begin{sphinxtheindex}
\let\bigletter\sphinxstyleindexlettergroup
\bigletter{algorithm\sphinxhyphen{}0}
\item\relax\sphinxstyleindexentry{algorithm\sphinxhyphen{}0}\sphinxstyleindexextra{algorithm/\_algo\_nonumber}\sphinxstyleindexpageref{algorithm/_algo_nonumber:\detokenize{algorithm-0}}
\bigletter{algorithm\sphinxhyphen{}\_algo\_nonumber\sphinxhyphen{}algorithm\sphinxhyphen{}0}
\item\relax\sphinxstyleindexentry{algorithm\sphinxhyphen{}\_algo\_nonumber\sphinxhyphen{}algorithm\sphinxhyphen{}0}\sphinxstyleindexextra{algorithm/\_algo\_nonumber}\sphinxstyleindexpageref{algorithm/_algo_nonumber:\detokenize{algorithm-_algo_nonumber-algorithm-0}}
\indexspace
\bigletter{test\sphinxhyphen{}algo\sphinxhyphen{}label}
\item\relax\sphinxstyleindexentry{test\sphinxhyphen{}algo\sphinxhyphen{}label}\sphinxstyleindexextra{algorithm/\_algo\_labeled\_titled\_with\_classname}\sphinxstyleindexpageref{algorithm/_algo_labeled_titled_with_classname:\detokenize{test-algo-label}}
Expand Down