Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
include:
- os: windows-latest
python-version: 3.8
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ classifiers = [
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Text Processing :: Markup",
Expand Down
8 changes: 8 additions & 0 deletions sphinx_design/_compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helpers for cross compatibility across dependency versions."""
from importlib import resources
from typing import Callable, Iterable

from docutils.nodes import Element
Expand All @@ -9,3 +10,10 @@ def findall(node: Element) -> Callable[..., Iterable[Element]]:
# findall replaces traverse in docutils v0.18
# note a difference is that findall is an iterator
return getattr(node, "findall", node.traverse)


# TODO: >= Python 3.9, only use `resources.files` and drop `resources.read_text`
def read_text(module: resources.Package, filename: str) -> str:
if hasattr(resources, "files"):
return resources.files(module).joinpath(filename).read_text()
return resources.read_text(module, filename)
7 changes: 3 additions & 4 deletions sphinx_design/extension.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import hashlib
import importlib.resources as resources
from pathlib import Path

from docutils import nodes
Expand All @@ -10,7 +9,7 @@
from sphinx.util.docutils import SphinxDirective

from . import compiled as static_module
from ._compat import findall
from ._compat import findall, read_text
from .article_info import setup_article_info
from .badges_buttons import setup_badges_and_buttons
from .cards import setup_cards
Expand Down Expand Up @@ -64,10 +63,10 @@ def update_css_js(app: Sphinx):
js_path = static_path / "design-tabs.js"
app.add_js_file(js_path.name)
if not js_path.exists():
content = resources.read_text(static_module, "sd_tabs.js")
content = read_text(static_module, "sd_tabs.js")
js_path.write_text(content)
# Read the css content and hash it
content = resources.read_text(static_module, "style.min.css")
content = read_text(static_module, "style.min.css")
hash = hashlib.md5(content.encode("utf8")).hexdigest()
# Write the css file
css_path = static_path / f"design-style.{hash}.min.css"
Expand Down
6 changes: 3 additions & 3 deletions sphinx_design/icons.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from functools import lru_cache
import importlib.resources as resources
import json
import re
from typing import Any, Dict, List, Optional, Sequence, Tuple
Expand All @@ -11,6 +10,7 @@
from sphinx.util.docutils import SphinxDirective, SphinxRole

from . import compiled
from ._compat import read_text
from .shared import WARNING_TYPE

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -48,7 +48,7 @@ def setup_icons(app: Sphinx) -> None:
@lru_cache(1)
def get_octicon_data() -> Dict[str, Any]:
"""Load all octicon data."""
content = resources.read_text(compiled, "octicons.json")
content = read_text(compiled, "octicons.json")
return json.loads(content)


Expand Down Expand Up @@ -240,7 +240,7 @@ def visit_fontawesome_warning(self, node: nodes.Element) -> None:
@lru_cache(1)
def get_material_icon_data(style: str) -> Dict[str, Any]:
"""Load all octicon data."""
content = resources.read_text(compiled, f"material_{style}.json")
content = read_text(compiled, f"material_{style}.json")
return json.loads(content)


Expand Down