Skip to content

Commit 3d0db63

Browse files
tirthasheshpateljpmckinneypre-commit-ci[bot]choldgraf
authored
[MAINT] Add support for Python 3.11 (#105)
Co-authored-by: James McKinney <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Chris Holdgraf <[email protected]>
1 parent e8fb510 commit 3d0db63

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
strategy:
2727
matrix:
2828
os: [ubuntu-latest]
29-
python-version: ["3.7", "3.8", "3.9", "3.10"]
29+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
3030
include:
3131
- os: windows-latest
3232
python-version: 3.8

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ classifiers = [
1919
"Programming Language :: Python :: 3.8",
2020
"Programming Language :: Python :: 3.9",
2121
"Programming Language :: Python :: 3.10",
22+
"Programming Language :: Python :: 3.11",
2223
"Programming Language :: Python :: Implementation :: CPython",
2324
"Topic :: Software Development :: Libraries :: Python Modules",
2425
"Topic :: Text Processing :: Markup",

sphinx_design/_compat.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Helpers for cross compatibility across dependency versions."""
2+
from importlib import resources
23
from typing import Callable, Iterable
34

45
from docutils.nodes import Element
@@ -9,3 +10,10 @@ def findall(node: Element) -> Callable[..., Iterable[Element]]:
910
# findall replaces traverse in docutils v0.18
1011
# note a difference is that findall is an iterator
1112
return getattr(node, "findall", node.traverse)
13+
14+
15+
# TODO: >= Python 3.9, only use `resources.files` and drop `resources.read_text`
16+
def read_text(module: resources.Package, filename: str) -> str:
17+
if hasattr(resources, "files"):
18+
return resources.files(module).joinpath(filename).read_text()
19+
return resources.read_text(module, filename)

sphinx_design/extension.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import hashlib
2-
import importlib.resources as resources
32
from pathlib import Path
43

54
from docutils import nodes
@@ -10,7 +9,7 @@
109
from sphinx.util.docutils import SphinxDirective
1110

1211
from . import compiled as static_module
13-
from ._compat import findall
12+
from ._compat import findall, read_text
1413
from .article_info import setup_article_info
1514
from .badges_buttons import setup_badges_and_buttons
1615
from .cards import setup_cards
@@ -64,10 +63,10 @@ def update_css_js(app: Sphinx):
6463
js_path = static_path / "design-tabs.js"
6564
app.add_js_file(js_path.name)
6665
if not js_path.exists():
67-
content = resources.read_text(static_module, "sd_tabs.js")
66+
content = read_text(static_module, "sd_tabs.js")
6867
js_path.write_text(content)
6968
# Read the css content and hash it
70-
content = resources.read_text(static_module, "style.min.css")
69+
content = read_text(static_module, "style.min.css")
7170
hash = hashlib.md5(content.encode("utf8")).hexdigest()
7271
# Write the css file
7372
css_path = static_path / f"design-style.{hash}.min.css"

sphinx_design/icons.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from functools import lru_cache
2-
import importlib.resources as resources
32
import json
43
import re
54
from typing import Any, Dict, List, Optional, Sequence, Tuple
@@ -11,6 +10,7 @@
1110
from sphinx.util.docutils import SphinxDirective, SphinxRole
1211

1312
from . import compiled
13+
from ._compat import read_text
1414
from .shared import WARNING_TYPE
1515

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

5454

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

246246

0 commit comments

Comments
 (0)