Skip to content

Commit e00ce63

Browse files
authored
feat: drop python3.8 support, add 3.12 testing (#90) adds nofollow source links
* feat: step towards frozen requirements * feat: pin to python 3.10 and all versions * fix: update github workflow files * fix: RTD python version * remove version pinning * drop python3.8 add 3.12 * fix: type validation * prevent indexing source pages via crawling
1 parent 5949429 commit e00ce63

File tree

8 files changed

+87
-31
lines changed

8 files changed

+87
-31
lines changed

.github/workflows/tests.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
unit:
4848
strategy:
4949
matrix:
50-
platform: [ubuntu-20.04, ubuntu-22.04, windows-latest]
50+
platform: [ubuntu-22.04, windows-latest]
5151
runs-on: ${{ matrix.platform }}
5252
steps:
5353
- uses: actions/checkout@v4
@@ -57,7 +57,6 @@ jobs:
5757
uses: actions/setup-python@v5
5858
with:
5959
python-version: |
60-
3.8
6160
3.10
6261
3.11
6362
3.12-dev
@@ -88,7 +87,7 @@ jobs:
8887
integration:
8988
strategy:
9089
matrix:
91-
platform: [ubuntu-20.04, ubuntu-22.04, windows-latest]
90+
platform: [ubuntu-22.04, windows-latest]
9291
runs-on: ${{ matrix.platform }}
9392
steps:
9493
- uses: actions/checkout@v4
@@ -98,7 +97,6 @@ jobs:
9897
uses: actions/setup-python@v5
9998
with:
10099
python-version: |
101-
3.8
102100
3.10
103101
3.11
104102
3.12-dev

.readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ formats:
1717
build:
1818
os: ubuntu-22.04
1919
tools:
20-
python: "3.8" # We still support Python 3.8 for now.
20+
python: "3.10" # We only support 3.10+.
2121
jobs:
2222
build:
2323
epub:

canonical_sphinx/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# You should have received a copy of the GNU General Public License along
1515
# with this program. If not, see <http://www.gnu.org/licenses/>.
1616
"""Sphinx configuration, extension and theme for Canonical documentation."""
17-
from typing import List, Optional, Any, Dict
17+
from typing import Any
1818

1919
from sphinx.application import Sphinx
2020

@@ -35,7 +35,7 @@
3535
__version__ = "dev"
3636

3737

38-
def hello(people: Optional[List[Any]] = None) -> None:
38+
def hello(people: list[Any] | None = None) -> None:
3939
"""Says hello."""
4040
print("Hello *craft team!")
4141
if people:
@@ -48,7 +48,7 @@ def copy_custom_files(app: Sphinx) -> None:
4848
shutil.copytree(str(theme_dir / "PDF"), app.outdir, dirs_exist_ok=True)
4949

5050

51-
def setup(app: Sphinx) -> Dict[str, Any]:
51+
def setup(app: Sphinx) -> dict[str, Any]:
5252
"""Configure the main extension and theme."""
5353
app.setup_extension("canonical_sphinx.config")
5454
app.connect( # pyright: ignore [reportUnknownMemberType]

canonical_sphinx/config.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,59 @@
1818
import importlib.util
1919
import os
2020
from pathlib import Path
21-
from typing import Any, Dict
21+
from typing import Any
2222

2323
from sphinx.application import Sphinx
2424
from sphinx.config import Config
2525
from sphinx.errors import ConfigError
2626
from sphinx.util import logging
2727

2828

29-
def setup(app: Sphinx) -> Dict[str, Any]:
29+
class SphinxConfig(Config):
30+
"""Expanded class for linting config options."""
31+
32+
notfound_urls_prefix: str
33+
html_theme: str
34+
html_last_updated_fmt: str
35+
html_permalinks_icon: str
36+
html_theme_options: dict[str, Any]
37+
html_favicon: str
38+
notfound_template: str
39+
latex_engine: str
40+
latex_show_pagerefs: bool
41+
latex_show_urls: str
42+
latex_table_style: list[str]
43+
latex_config: str
44+
latex_elements: dict[str, Any]
45+
html_copy_source: bool
46+
html_show_sourcelink: bool
47+
48+
def __init__(self) -> None:
49+
pass
50+
51+
52+
def setup(app: Sphinx) -> dict[str, Any]:
3053
"""Perform the main configuration and theme-setting."""
3154
# These are options that the user can set on their "conf.py"
3255
# (many options are still missing).
33-
app.add_config_value(
56+
app.add_config_value( # pyright: ignore [reportUnknownMemberType]
3457
"disable_feedback_button",
3558
default=False,
3659
rebuild="env",
3760
types=bool,
3861
)
39-
app.add_config_value("slug", default="", rebuild="env", types=str)
40-
app.add_config_value("epub_build", default=False, rebuild="env", types=bool)
62+
app.add_config_value( # pyright: ignore [reportUnknownMemberType]
63+
"slug",
64+
default="",
65+
rebuild="env",
66+
types=str,
67+
)
68+
app.add_config_value( # pyright: ignore [reportUnknownMemberType]
69+
"epub_build",
70+
default=False,
71+
rebuild="env",
72+
types=bool,
73+
)
4174

4275
extra_extensions = [
4376
"myst_parser",
@@ -88,7 +121,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
88121
}
89122

90123

91-
def config_inited(app: Sphinx, config: Config) -> None: # noqa: PLR0915, PLR0912
124+
def config_inited(app: Sphinx, config: SphinxConfig) -> None: # noqa: PLR0915, PLR0912
92125
"""Read user-provided values and setup defaults."""
93126
# Get the Sphinx warning logger early
94127
logger = logging.getLogger(__name__)
@@ -184,7 +217,9 @@ def config_inited(app: Sphinx, config: Config) -> None: # noqa: PLR0915, PLR091
184217
with Path.open(theme_dir / "PDF/latex_elements_template.txt", "r+") as file:
185218
config.latex_config = file.read()
186219

187-
if config.latex_elements == {}:
220+
if (
221+
config.latex_elements == {}
222+
): # pyright: ignore [reportUnnecessaryComparison] type: # ignore[comparison-overlap]
188223

189224
config.latex_elements = ast.literal_eval(config.latex_config)
190225

canonical_sphinx/theme/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
# You should have received a copy of the GNU General Public License along
1515
# with this program. If not, see <http://www.gnu.org/licenses/>.
1616
"""Sphinx theme for Canonical documentation."""
17-
from typing import Any, Dict
17+
from typing import Any
1818
from pathlib import Path
1919

2020
from sphinx.application import Sphinx
2121

2222

23-
def setup(app: Sphinx) -> Dict[str, Any]:
23+
def setup(app: Sphinx) -> dict[str, Any]:
2424
"""Add "canonical_sphinx_theme" as a valid html theme."""
2525
app.add_html_theme("canonical_sphinx_theme", str(Path(__file__).parent))
2626
return {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{% extends "basic-ng/components/view-this-page.html" %}
2+
{% from "basic-ng/components/view-this-page.html" import determine_page_view_link with context %}
3+
4+
{%- macro furo_view_button(url) -%}
5+
<div class="view-this-page">
6+
<a class="muted-link" href="{{ url }}" rel="nofollow" title="{{ _("View this page") }}">
7+
<svg><use href="#svg-eye"></use></svg>
8+
<span class="visually-hidden">{{ _("View this page") }}</span>
9+
</a>
10+
</div>
11+
{%- endmacro -%}
12+
13+
{% block link_available -%}
14+
{{ furo_view_button(determine_page_view_link()) }}
15+
{%- endblock %}
16+
17+
{% block link_not_available %}
18+
{# Make nice things happen, on Read the Docs #}
19+
{%- if READTHEDOCS and conf_py_path and page_source_suffix and github_user != "None" and github_repo != "None" and github_version and pagename and page_source_suffix %}
20+
{% set url = "https://github.com/" + github_user + "/" + github_repo + "/blob/" + github_version + conf_py_path + pagename + page_source_suffix + "?plain=true" %}
21+
{{ furo_view_button(url) }}
22+
{%- endif -%}
23+
{% endblock %}

pyproject.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "canonical-sphinx"
33
dynamic = ["version", "readme"]
44
dependencies = [
5-
"sphinx>=7.1.2,<8",
5+
"Sphinx",
66
"furo",
77
"myst-parser",
88
"linkify-it-py",
@@ -11,9 +11,9 @@ classifiers = [
1111
"Development Status :: 1 - Planning",
1212
"License :: OSI Approved :: GNU General Public License (GPL)",
1313
"Programming Language :: Python :: 3",
14-
"Programming Language :: Python :: 3.8",
14+
"Programming Language :: Python :: 3.10",
1515
]
16-
requires-python = ">=3.8"
16+
requires-python = ">=3.10"
1717

1818
[project.scripts]
1919
canonical-sphinx-hello = "canonical_sphinx:hello"
@@ -22,9 +22,9 @@ canonical-sphinx-hello = "canonical_sphinx:hello"
2222
full = [
2323
"canonical-sphinx-extensions",
2424
"sphinx-copybutton",
25-
"sphinx-design",
25+
"sphinx_design",
2626
"sphinx-notfound-page",
27-
"sphinx-reredirects",
27+
"sphinx_reredirects",
2828
"sphinx-tabs",
2929
"sphinxcontrib-jquery",
3030
"sphinxext-opengraph",
@@ -94,7 +94,7 @@ namespaces = false
9494
canonical_sphinx = ["theme/PDF/*.ttf", "theme/PDF/*.pdf", "theme/PDF/*.png", "theme/PDF/*.txt"]
9595

9696
[tool.black]
97-
target-version = ["py38"]
97+
target-version = ["py310"]
9898

9999
[tool.codespell]
100100
ignore-words-list = "buildd,crate,keyserver,comandos,ro,dedent,dedented"
@@ -128,7 +128,7 @@ exclude_also = [
128128

129129
[tool.pyright]
130130
strict = ["canonical_sphinx"]
131-
pythonVersion = "3.8"
131+
pythonVersion = "3.10"
132132
pythonPlatform = "Linux"
133133
exclude = [
134134
"**/.*",
@@ -139,7 +139,7 @@ exclude = [
139139
]
140140

141141
[tool.mypy]
142-
python_version = "3.8"
142+
python_version = "3.10"
143143
exclude = [
144144
"build",
145145
"tests",
@@ -166,7 +166,7 @@ strict = false
166166

167167
[tool.ruff]
168168
line-length = 88
169-
target-version = "py38"
169+
target-version = "py310"
170170
src = ["canonical_sphinx", "tests"]
171171
extend-exclude = [
172172
"docs",

tox.ini

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ env_list = # Environments to run when called with no parameters.
33
format-{black,ruff,codespell}
44
pre-commit
55
lint-{black,ruff,mypy,pyright,shellcheck,codespell,docs,yaml}
6-
unit-py3.{8,10,11}
6+
unit-py3.{10,11,12}
77
integration-py3.10
88
# Integration tests probably take a while, so we're only running them on Python
99
# 3.10, which is included in core22.
@@ -42,15 +42,15 @@ extras = dev
4242
allowlist_externals = mkdir
4343
commands_pre = mkdir -p {tox_root}/results
4444

45-
[testenv:{unit,integration}-py3.{8,9,10,11,12}] # Configuration for all tests using pytest
45+
[testenv:{unit,integration}-py3.{10,11,12}] # Configuration for all tests using pytest
4646
base = testenv, test
4747
description =
4848
unit: Run unit tests with pytest
4949
integration: Run integration tests with pytest
5050
labels =
51-
py3.{8,10,11}: tests
52-
unit-py3.{8,10,11}: unit-tests
53-
integration-py3.{8,10,11}: integration-tests
51+
py3.{10,11,12}: tests
52+
unit-py3.{10,11,12}: unit-tests
53+
integration-py3.{10,11,12}: integration-tests
5454
change_dir =
5555
unit: tests/unit
5656
integration: tests/integration

0 commit comments

Comments
 (0)