Skip to content

Commit 0b58fca

Browse files
12rambaudrammock
andauthored
refactor: spring cleaning (#1271)
* sanitize babel calls * move the gallery directive to an extention folder * clean test folder * split __init__.py * add links between tests * drop flake8 from pyproject.toml * rename folder * update docstring * only import modules instead of functions * ignore bootstrap license * reintegrate modifications from #1264 * typos / docstring improvements / whitespace * fix: expose traverse_or_findall in utils --------- Co-authored-by: Daniel McCloy <dan@mccloy.info>
1 parent e7a6c69 commit 0b58fca

File tree

28 files changed

+1294
-1190
lines changed

28 files changed

+1294
-1190
lines changed

.github/workflows/tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939

4040
# run our test suite on various combinations of OS / Python / Sphinx version
4141
run-pytest:
42+
needs: [lint]
4243
strategy:
4344
fail-fast: false
4445
matrix:
@@ -93,6 +94,7 @@ jobs:
9394

9495
# Build our site on the 3 major OSes and check for Sphinx warnings
9596
build-site:
97+
needs: [lint]
9698
strategy:
9799
fail-fast: false
98100
matrix:
@@ -120,6 +122,7 @@ jobs:
120122

121123
# Run local Lighthouse audit against built site
122124
audit:
125+
needs: [build-site]
123126
strategy:
124127
matrix:
125128
os: [ubuntu-latest]
@@ -163,6 +166,7 @@ jobs:
163166

164167
# Generate a profile of the code and upload as an artifact
165168
profile:
169+
needs: [build-site, run-pytest]
166170
strategy:
167171
matrix:
168172
os: [ubuntu-latest]

.pre-commit-config.yaml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,10 @@ repos:
1717
hooks:
1818
- id: black
1919

20-
- repo: https://github.com/PyCQA/flake8
21-
rev: 6.0.0
20+
- repo: https://github.com/charliermarsh/ruff-pre-commit
21+
rev: "v0.0.215"
2222
hooks:
23-
- id: flake8
24-
additional_dependencies: [Flake8-pyproject]
25-
26-
- repo: https://github.com/pre-commit/pre-commit-hooks
27-
rev: v4.4.0
28-
hooks:
29-
- id: check-builtin-literals
30-
- id: check-case-conflict
31-
- id: check-toml
32-
- id: check-yaml
33-
- id: debug-statements
34-
- id: end-of-file-fixer
35-
- id: trailing-whitespace
23+
- id: ruff
3624

3725
- repo: https://github.com/asottile/pyupgrade
3826
rev: v3.3.1

docs/scripts/gallery_directive/__init__.py renamed to docs/_extension/gallery_directive.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
It currently exists for maintainers of the pydata-sphinx-theme,
99
but might be abstracted into a standalone package if it proves useful.
1010
"""
11-
from yaml import safe_load
12-
from typing import List
1311
from pathlib import Path
12+
from typing import Any, Dict, List
1413

1514
from docutils import nodes
1615
from docutils.parsers.rst import directives
17-
from sphinx.util.docutils import SphinxDirective
16+
from sphinx.application import Sphinx
1817
from sphinx.util import logging
18+
from sphinx.util.docutils import SphinxDirective
19+
from yaml import safe_load
1920

2021
logger = logging.getLogger(__name__)
2122

@@ -142,3 +143,19 @@ def run(self) -> List[nodes.Node]:
142143
if self.options.get("container-class", []):
143144
container.attributes["classes"] += self.options.get("class", [])
144145
return [container]
146+
147+
148+
def setup(app: Sphinx) -> Dict[str, Any]:
149+
"""Add custom configuration to sphinx app.
150+
151+
Args:
152+
app: the Sphinx application
153+
Returns:
154+
the 2 parallel parameters set to ``True``.
155+
"""
156+
app.add_directive("gallery-grid", GalleryDirective)
157+
158+
return {
159+
"parallel_read_safe": True,
160+
"parallel_write_safe": True,
161+
}

docs/conf.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
"""Configuration file for the Sphinx documentation builder.
2+
3+
This file only contains a selection of the most common options. For a full
4+
list see the documentation:
5+
https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
"""
7+
18
# -- Path setup --------------------------------------------------------------
29
import os
310
import sys
11+
from pathlib import Path
12+
from typing import Any, Dict
13+
414
import pydata_sphinx_theme
15+
from sphinx.application import Sphinx
516

6-
sys.path.append("scripts")
7-
from gallery_directive import GalleryDirective
17+
sys.path.append(str(Path(".").resolve()))
818

919
# -- Project information -----------------------------------------------------
1020

@@ -22,6 +32,7 @@
2232
"sphinxext.rediraffe",
2333
"sphinx_design",
2434
"sphinx_copybutton",
35+
"_extension.gallery_directive",
2536
# For extension examples and demos
2637
"ablog",
2738
"jupyter_sphinx",
@@ -57,7 +68,6 @@
5768

5869
autosummary_generate = True
5970

60-
6171
# -- Internationalization ----------------------------------------------------
6272

6373
# specifying the natural language populates some key tags
@@ -223,9 +233,13 @@
223233
# -- application setup -------------------------------------------------------
224234

225235

226-
def setup_to_main(app, pagename, templatename, context, doctree):
236+
def setup_to_main(
237+
app: Sphinx, pagename: str, templatename: str, context, doctree
238+
) -> None:
239+
"""Add a function that jinja can access for returning an "edit this page" link pointing to `main`."""
240+
227241
def to_main(link: str) -> str:
228-
"""Transform "edit on github" links and make sure they always point to the main branch
242+
"""Transform "edit on github" links and make sure they always point to the main branch.
229243
230244
Args:
231245
link: the link to the github edit interface
@@ -240,6 +254,17 @@ def to_main(link: str) -> str:
240254
context["to_main"] = to_main
241255

242256

243-
def setup(app):
244-
app.add_directive("gallery-grid", GalleryDirective)
257+
def setup(app: Sphinx) -> Dict[str, Any]:
258+
"""Add custom configuration to sphinx app.
259+
260+
Args:
261+
app: the Sphinx application
262+
Returns:
263+
the 2 parralel parameters set to ``True``.
264+
"""
245265
app.connect("html-page-context", setup_to_main)
266+
267+
return {
268+
"parallel_read_safe": True,
269+
"parallel_write_safe": True,
270+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Package definition empty file."""

docs/examples/test_py_module/test.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class Foo:
5-
65
"""Docstring for class Foo.
76
87
This text tests for the formatting of docstrings generated from output
@@ -65,7 +64,6 @@ def add(self, val1, val2):
6564
:rtype: int
6665
6766
"""
68-
6967
return val1 + val2
7068

7169
def capitalize(self, myvalue):
@@ -76,12 +74,10 @@ def capitalize(self, myvalue):
7674
:rtype: string
7775
7876
"""
79-
8077
return myvalue.upper()
8178

8279
def another_function(self, a, b, **kwargs):
83-
"""
84-
Here is another function.
80+
"""Here is another function.
8581
8682
:param a: The number of green hats you own.
8783
:type a: int

docs/scripts/generate_collaborators_gallery.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
"""Uses the GitHub API to list a gallery of all people with direct access
2-
to the repository.
3-
"""
1+
"""Uses the GitHub API to list a gallery of all people with direct access to the repository."""
42

5-
from yaml import dump
6-
from subprocess import run
7-
import shlex
83
import json
4+
import shlex
95
from pathlib import Path
6+
from subprocess import run
7+
8+
from yaml import dump
109

11-
COLLABORATORS_API = "https://api.github.com/repos/pydata/pydata-sphinx-theme/collaborators?affiliation=direct" # noqa
10+
COLLABORATORS_API = "https://api.github.com/repos/pydata/pydata-sphinx-theme/collaborators?affiliation=direct"
1211

1312
print("Grabbing latest collaborators with GitHub API via GitHub's CLI...")
1413
out = run(shlex.split(f"gh api {COLLABORATORS_API}"), capture_output=True)

docs/scripts/generate_gallery_images.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
"""
2-
Use playwright to build a gallery of website using this theme
3-
"""
1+
"""Use playwright to build a gallery of website using this theme."""
42

53
from pathlib import Path
6-
from yaml import safe_load
74
from shutil import copy
8-
from playwright.sync_api import sync_playwright, TimeoutError
9-
from rich.progress import track
5+
6+
from playwright.sync_api import TimeoutError, sync_playwright
107
from rich import print
8+
from rich.progress import track
9+
from yaml import safe_load
1110

1211

13-
def regenerate_gallery():
14-
"""
15-
Regenerate images of snapshots for our gallery.
12+
def regenerate_gallery() -> None:
13+
"""Regenerate images of snapshots for our gallery.
1614
1715
This function should only be triggered in RTD builds as it increases the build
1816
time by 30-60s. Developers can still execute this function from time to time to
1917
populate their local gallery images with updated files.
2018
"""
21-
2219
# get the existing folders path
2320
_static_dir = Path(__file__).parents[1] / "_static"
2421

docs/scripts/update_kitchen_sink.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
from urllib.request import urlopen
1+
"""Script run to update the kitchen sink from https://sphinx-themes.org."""
2+
23
from pathlib import Path
4+
from urllib.request import urlopen
35

46
EXTRA_MESSAGE = """\
57
.. note::
@@ -11,7 +13,7 @@
1113
:color: primary
1214
1315
Go to Sphinx Themes
14-
""" # noqa
16+
"""
1517

1618
kitchen_sink_files = [
1719
"admonitions.rst",
@@ -29,7 +31,7 @@
2931
path_sink = Path(__file__).parent.parent / "examples" / "kitchen-sink"
3032
for ifile in kitchen_sink_files:
3133
print(f"Reading {ifile}...")
32-
url = f"https://github.com/sphinx-themes/sphinx-themes.org/raw/master/sample-docs/kitchen-sink/{ifile}" # noqa
34+
url = f"https://github.com/sphinx-themes/sphinx-themes.org/raw/master/sample-docs/kitchen-sink/{ifile}"
3335
text = urlopen(url).read().decode()
3436
# The sphinx-themes docs expect Furo to be installed, so we overwrite w/ PST
3537
text = text.replace("src/furo", "src/pydata_sphinx_theme")

0 commit comments

Comments
 (0)