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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.20
rev: v0.16.1
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- id: ruff-format

- repo: https://github.com/rbubley/mirrors-prettier
rev: 39e2973981e6d2f9b6c543b0086a2d2393abdc89 # frozen: v3.9.4
rev: 0ee178619d696787ca73d210cc191d720868c631 # frozen: v3.9.6
hooks:
- id: prettier
types_or: [scss, javascript]

- repo: https://github.com/codespell-project/codespell
rev: v2.4.2
rev: v2.4.3
hooks:
- id: codespell
exclude: >
Expand Down
12 changes: 6 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -- Project information -----------------------------------------------------
import os
from urllib.request import urlopen
from pathlib import Path
from datetime import datetime
from pathlib import Path
from urllib.request import urlopen

project = "Sphinx Book Theme"
copyright = str(datetime.now().year)
Expand Down Expand Up @@ -198,7 +198,7 @@

# -- Download latest theme elements page from PyData -----------------------------

path_pydata_content = "https://raw.githubusercontent.com/pydata/pydata-sphinx-theme/main/docs/user_guide/theme-elements.md" # noqa
path_pydata_content = "https://raw.githubusercontent.com/pydata/pydata-sphinx-theme/main/docs/user_guide/theme-elements.md"
path_content_file = Path(__file__).parent / "content/pydata-content-blocks.md"
if not path_content_file.exists():
with urlopen(path_pydata_content) as resp:
Expand All @@ -208,8 +208,8 @@
content[ix_title] = "# PyData Theme Elements"
content.insert(
ix_title + 1,
"\nThis is a collection of content blocks with special support from this theme's parent theme, [the PyData Sphinx Theme](https://pydata-sphinx-theme.readthedocs.io/en/latest/user_guide/theme-elements.html)\n", # noqa
) # noqa
"\nThis is a collection of content blocks with special support from this theme's parent theme, [the PyData Sphinx Theme](https://pydata-sphinx-theme.readthedocs.io/en/latest/user_guide/theme-elements.html)\n",
)
content = "\n".join(content)
# Replace a relative link in the pydata docs w/ the respective one here
content = content.replace("../examples/pydata.ipynb", "notebooks.md")
Expand All @@ -230,7 +230,7 @@ def setup(app):
app.add_css_file("https://assets.readthedocs.org/static/css/badge_only.css")

# Create the dummy data file so we can link it
# ref: https://github.com/readthedocs/readthedocs.org/blob/bc3e147770e5740314a8e8c33fec5d111c850498/readthedocs/core/static-src/core/js/doc-embed/footer.js # noqa: E501
# ref: https://github.com/readthedocs/readthedocs.org/blob/bc3e147770e5740314a8e8c33fec5d111c850498/readthedocs/core/static-src/core/js/doc-embed/footer.js
app.add_js_file("rtd-data.js")
app.add_js_file(
"https://assets.readthedocs.org/static/javascript/readthedocs-doc-embed.js",
Expand Down
6 changes: 3 additions & 3 deletions docs/scripts/update_kitchen_sink.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from urllib.request import urlopen
from pathlib import Path
from urllib.request import urlopen

EXTRA_MESSAGE = """\

Expand All @@ -14,7 +14,7 @@
:color: primary

Go to Sphinx Themes
""" # noqa
"""

kitchen_sink_files = [
"admonitions.rst",
Expand All @@ -32,7 +32,7 @@
path_sink = Path(__file__).parent.parent / "reference" / "kitchen-sink"
for ifile in kitchen_sink_files:
print(f"Reading {ifile}...")
url = f"https://github.com/sphinx-themes/sphinx-themes.org/raw/master/sample-docs/kitchen-sink/{ifile}" # noqa
url = f"https://github.com/sphinx-themes/sphinx-themes.org/raw/master/sample-docs/kitchen-sink/{ifile}"
text = urlopen(url).read().decode()
# The sphinx-themes docs expect Furo to be installed, so we overwrite w/ this path
text = text.replace("src/furo", "src/sphinx_book_theme")
Expand Down
18 changes: 9 additions & 9 deletions src/sphinx_book_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

import hashlib
import os
from functools import cache, lru_cache
from pathlib import Path
from functools import lru_cache

from docutils import nodes as docutil_nodes
from pydata_sphinx_theme.utils import get_theme_options_dict
from sphinx.application import Sphinx
from sphinx.locale import get_translation
from sphinx.util import logging
from pydata_sphinx_theme.utils import get_theme_options_dict

from ._compat import findall
from ._transforms import HandleFootnoteTransform
from .directives import Margin
from .nodes import SideNoteNode
from .header_buttons import (
prep_header_buttons,
add_header_buttons,
update_sourcename,
prep_header_buttons,
update_context_with_repository_info,
update_sourcename,
)
from .header_buttons.launch import add_launch_buttons
from .header_buttons.source import add_source_buttons
from ._compat import findall
from ._transforms import HandleFootnoteTransform
from .nodes import SideNoteNode

__version__ = "1.5.0.dev"
"""sphinx-book-theme version"""
Expand Down Expand Up @@ -74,7 +74,7 @@ def add_metadata_to_page(app, pagename, templatename, context, doctree):
context["theme_search_bar_text"] = translation("Search") + "..."


@lru_cache(maxsize=None)
@cache
def _gen_hash(path: str) -> str:
return hashlib.sha1(path.read_bytes()).hexdigest()

Expand Down Expand Up @@ -173,7 +173,7 @@ def check_deprecation_keys(app):
for key in deprecated_config_list:
if key in get_theme_options_dict(app):
SPHINX_LOGGER.warning(
f"'{key}' was deprecated from version 0.3.4 onwards. See the CHANGELOG for more information: https://github.com/executablebooks/sphinx-book-theme/blob/master/CHANGELOG.md" # noqa: E501
f"'{key}' was deprecated from version 0.3.4 onwards. See the CHANGELOG for more information: https://github.com/executablebooks/sphinx-book-theme/blob/master/CHANGELOG.md"
f"[{DEFAULT_LOG_TYPE}]",
type=DEFAULT_LOG_TYPE,
)
Expand Down
3 changes: 2 additions & 1 deletion src/sphinx_book_theme/_compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from docutils.nodes import Element
from collections.abc import Iterator

from docutils.nodes import Element


def findall(node: Element, *args, **kwargs) -> Iterator[Element]:
# findall replaces traverse in docutils v0.18
Expand Down
4 changes: 2 additions & 2 deletions src/sphinx_book_theme/_compile_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import json
import os
from pathlib import Path
import subprocess
from pathlib import Path

# In case the smodin.io code is different from the Sphinx code
RENAME_LANGUAGE_CODES = {
Expand Down Expand Up @@ -34,7 +34,7 @@ def convert_json(folder=None):
if language in RENAME_LANGUAGE_CODES:
language = RENAME_LANGUAGE_CODES[language]
out_path = (
out_folder / "locales" / language / "LC_MESSAGES" / "booktheme.po" # noqa: E501
out_folder / "locales" / language / "LC_MESSAGES" / "booktheme.po"
)
if not out_path.parent.exists():
out_path.parent.mkdir(parents=True)
Expand Down
10 changes: 6 additions & 4 deletions src/sphinx_book_theme/_transforms.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from sphinx.transforms.post_transforms import SphinxPostTransform
from typing import Any

from docutils import nodes as docutil_nodes
from sphinx import addnodes as sphinx_nodes
from pydata_sphinx_theme.utils import get_theme_options_dict
from .nodes import SideNoteNode
from sphinx import addnodes as sphinx_nodes
from sphinx.transforms.post_transforms import SphinxPostTransform

from ._compat import findall
from .nodes import SideNoteNode


class HandleFootnoteTransform(SphinxPostTransform):
Expand All @@ -16,7 +18,7 @@ class HandleFootnoteTransform(SphinxPostTransform):
def run(self, **kwargs: Any) -> None:
theme_options = get_theme_options_dict(self.app)
if theme_options.get("use_sidenotes", False) is False:
return None
return
# Cycle through footnote references, and move their content next to the
# reference. This lets us display the reference in the margin,
# or just below on narrow screens.
Expand Down
6 changes: 2 additions & 4 deletions src/sphinx_book_theme/header_buttons/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""Generate metadata for header buttons."""

from pydata_sphinx_theme.utils import config_provided_by_user, get_theme_options_dict
from sphinx.errors import SphinxError
from sphinx.locale import get_translation
from pydata_sphinx_theme.utils import config_provided_by_user, get_theme_options_dict

from sphinx.util import logging


LOGGER = logging.getLogger(__name__)
MESSAGE_CATALOG_NAME = "booktheme"
translation = get_translation(MESSAGE_CATALOG_NAME)
Expand Down Expand Up @@ -167,7 +165,7 @@ def update_context_with_repository_info(app):

# If no provider is given, try to infer one from the repo url
if provider == "":
for iprov in default_provider_urls.keys():
for iprov in default_provider_urls:
if iprov in provider_url.lower():
provider = iprov
break
Expand Down
9 changes: 4 additions & 5 deletions src/sphinx_book_theme/header_buttons/launch.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
"""Launch buttons for Binder / Thebe / Colab / etc."""

from pathlib import Path
from typing import Any, Optional
from urllib.parse import urlencode, quote
from shutil import copy2
from typing import Any
from urllib.parse import quote, urlencode

from docutils.nodes import document
from sphinx.application import Sphinx
from sphinx.locale import get_translation
from sphinx.util import logging
from shutil import copy2

from . import get_repo_parts, get_repo_url


SPHINX_LOGGER = logging.getLogger(__name__)

MESSAGE_CATALOG_NAME = "booktheme"
Expand All @@ -24,7 +23,7 @@ def add_launch_buttons(
pagename: str,
templatename: str,
context: dict[str, Any],
doctree: Optional[document],
doctree: document | None,
):
"""Builds a binder link and inserts it in HTML context for use in templating.

Expand Down
4 changes: 2 additions & 2 deletions src/sphinx_book_theme/header_buttons/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def add_source_buttons(app, pagename, templatename, context, doctree):
repo_url, provider = get_repo_url(context)
if provider in ("github", "gitlab"):
if provider == "github":
url = f"{repo_url}/issues/new?title=Issue%20on%20page%20%2F{context['pagename']}.html&body=Your%20issue%20content%20here." # noqa: E501
url = f"{repo_url}/issues/new?title=Issue%20on%20page%20%2F{context['pagename']}.html&body=Your%20issue%20content%20here."
elif provider == "gitlab":
url = f"{repo_url}/-/issues/new?issue[title]=Issue%20on%20page%20%2F{context['pagename']}.html&issue[description]=Your%20issue%20content%20here." # noqa: E501
url = f"{repo_url}/-/issues/new?issue[title]=Issue%20on%20page%20%2F{context['pagename']}.html&issue[description]=Your%20issue%20content%20here."
repo_buttons.append(
{
"type": "link",
Expand Down
3 changes: 2 additions & 1 deletion src/sphinx_book_theme/nodes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, cast

from docutils import nodes
from sphinx.application import Sphinx
from typing import Any, cast


class SideNoteNode(nodes.Element):
Expand Down
9 changes: 4 additions & 5 deletions tests/test_build.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import os
from importlib.metadata import version
from pathlib import Path
from shutil import copytree, rmtree
from importlib.metadata import version
from packaging.version import parse

from bs4 import BeautifulSoup
import pytest
import sphinx
from bs4 import BeautifulSoup
from packaging.version import parse
from sphinx.testing.util import SphinxTestApp


sphinx_version = parse(version("sphinx"))
path_tests = Path(__file__).parent

Expand Down Expand Up @@ -351,7 +350,7 @@ def test_repo_custombranch(sphinx_build_factory, file_regression):
"html_theme_options": {
"repository_branch": "foo",
"use_edit_page_button": True,
"repository_url": "https://github.com/executablebooks/sphinx-book-theme", # noqa: E501
"repository_url": "https://github.com/executablebooks/sphinx-book-theme",
"launch_buttons": {"binderhub_url": "https://mybinder.org"},
"navigation_with_keys": True,
}
Expand Down
Loading