diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..2bcd70e3 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 88 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..85097631 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,20 @@ +name: Lint + +on: [push, pull_request, workflow_dispatch] + +env: + FORCE_COLOR: 1 + +permissions: + contents: read + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: "3.x" + - uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/pypi-package.yml b/.github/workflows/pypi-package.yml index 2b8f8aa9..355a35fd 100644 --- a/.github/workflows/pypi-package.yml +++ b/.github/workflows/pypi-package.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: hynek/build-and-inspect-python-package@v1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fa5ed351..e6578909 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,22 +1,25 @@ name: Tests -on: - push: - pull_request: - workflow_dispatch: +on: [push, pull_request, workflow_dispatch] + +env: + FORCE_COLOR: 1 jobs: build_doc: name: Build CPython docs runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - branch: [origin/main, 3.12, 3.11, '3.10', 3.9, 3.8] + branch: ["origin/main", "3.12", "3.11", "3.10", "3.9", "3.8"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: python-version: 3 + allow-prereleases: true + cache: pip - name: Clone docsbuild scripts run: | git clone https://github.com/python/docsbuild-scripts/ @@ -26,15 +29,15 @@ jobs: python -m pip install -r docsbuild-scripts/requirements.txt - name: Build documentation run: > - python ./docsbuild-scripts/build_docs.py - --quick - --build-root ./build_root - --www-root ./www - --log-directory ./logs - --group $(id -g) - --skip-cache-invalidation - --theme $(pwd) - --language en + python ./docsbuild-scripts/build_docs.py + --quick + --build-root ./build_root + --www-root ./www + --log-directory ./logs + --group $(id -g) + --skip-cache-invalidation + --theme $(pwd) + --language en --branch ${{ matrix.branch }} - name: Upload uses: actions/upload-artifact@v3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..008784c6 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,50 @@ +repos: + - repo: https://github.com/asottile/pyupgrade + rev: v3.15.0 + hooks: + - id: pyupgrade + args: [--py38-plus] + + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 23.9.1 + hooks: + - id: black + + - repo: https://github.com/PyCQA/isort + rev: 5.12.0 + hooks: + - id: isort + args: [--add-import=from __future__ import annotations] + + - repo: https://github.com/PyCQA/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + additional_dependencies: + [flake8-2020, flake8-implicit-str-concat, flake8-logging] + + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 + hooks: + - id: python-check-blanket-noqa + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: check-json + - id: check-toml + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: trailing-whitespace + + - repo: https://github.com/abravalheri/validate-pyproject + rev: v0.14 + hooks: + - id: validate-pyproject + +ci: + autoupdate_schedule: quarterly diff --git a/README.rst b/README.rst index 3f2e8443..0a8db3fb 100644 --- a/README.rst +++ b/README.rst @@ -10,7 +10,7 @@ projects if you so choose, but please keep in mind that in doing so you're also choosing to accept some of the responsibility for maintaining that collective trust. -To use the theme, install it into your docs build environment via ``pip`` +To use the theme, install it into your docs build environment via ``pip`` (preferably in a virtual environment). diff --git a/code_of_conduct.rst b/code_of_conduct.rst index 28de97ce..4bc6630f 100644 --- a/code_of_conduct.rst +++ b/code_of_conduct.rst @@ -11,4 +11,3 @@ which includes all infrastructure used in the development of Python itself In general this means everyone is expected to be open, considerate, and respectful of others no matter what their position is within the project. - diff --git a/pyproject.toml b/pyproject.toml index 149c548f..014cb945 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,43 +1,38 @@ [build-system] -requires = ["flit_core>=3.7"] build-backend = "flit_core.buildapi" +requires = [ + "flit_core>=3.7", +] -# project metadata [project] name = "python-docs-theme" version = "2023.9" description = "The Sphinx theme for the CPython docs and related projects" readme = "README.rst" -urls.Code = "https://github.com/python/python-docs-theme" -urls.Download = "https://pypi.org/project/python-docs-theme/" -urls.Homepage = "https://github.com/python/python-docs-theme/" -urls."Issue tracker" = "https://github.com/python/python-docs-theme/issues" license.file = "LICENSE" +authors = [{name = "PyPA", email = "distutils-sig@python.org"}] requires-python = ">=3.8" - -# Classifiers list: https://pypi.org/classifiers/ classifiers = [ - "Development Status :: 5 - Production/Stable", - "Framework :: Sphinx :: Theme", - "Intended Audience :: Developers", - "License :: OSI Approved :: Python Software Foundation License", - "Operating System :: OS Independent", - "Topic :: Documentation", - "Topic :: Software Development :: Documentation", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.13", + "Development Status :: 5 - Production/Stable", + "Framework :: Sphinx :: Theme", + "Intended Audience :: Developers", + "License :: OSI Approved :: Python Software Foundation License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Topic :: Documentation", + "Topic :: Software Development :: Documentation", ] - -[[project.authors]] -name = "PyPA" -email = "distutils-sig@python.org" - +urls.Code = "https://github.com/python/python-docs-theme" +urls.Download = "https://pypi.org/project/python-docs-theme/" +urls.Homepage = "https://github.com/python/python-docs-theme/" +urls."Issue tracker" = "https://github.com/python/python-docs-theme/issues" [project.entry-points."sphinx.html_themes"] python_docs_theme = 'python_docs_theme' diff --git a/python_docs_theme/__init__.py b/python_docs_theme/__init__.py index 0857b5fb..77476754 100644 --- a/python_docs_theme/__init__.py +++ b/python_docs_theme/__init__.py @@ -1,8 +1,10 @@ +from __future__ import annotations + import hashlib import os from functools import lru_cache from pathlib import Path -from typing import Any, Dict, List +from typing import Any import sphinx.application from sphinx.builders.html import StandaloneHTMLBuilder @@ -19,7 +21,7 @@ def _asset_hash(path: str) -> str: return f"{path}?digest={digest}" -def _add_asset_hashes(static: List[str], add_digest_to: List[str]) -> None: +def _add_asset_hashes(static: list[str], add_digest_to: list[str]) -> None: for asset in add_digest_to: index = static.index(asset) static[index].filename = _asset_hash(asset) # type: ignore @@ -29,7 +31,7 @@ def _html_page_context( app: sphinx.application.Sphinx, pagename: str, templatename: str, - context: Dict[str, Any], + context: dict[str, Any], doctree: Any, ) -> None: if app.config.html_theme != "python_docs_theme": diff --git a/python_docs_theme/static/menu.js b/python_docs_theme/static/menu.js index e2335857..c7ab03ea 100644 --- a/python_docs_theme/static/menu.js +++ b/python_docs_theme/static/menu.js @@ -54,4 +54,4 @@ document.addEventListener("DOMContentLoaded", function () { closeMenu() } }) -}) \ No newline at end of file +})