8000 Lint on GitHub Actions via pre-commit by hugovk · Pull Request #159 · python/python-docs-theme · GitHub
[go: up one dir, main page]

Skip to content

Lint on GitHub Actions via pre-commit #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 13, 2023
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: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 88
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can/should this specified with a --flag (or disabled if black already checks this)?
If we do we can get rid of this file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be done with a flag, but then it would only apply to that invocation with the flag, and not if we run Flake8 myself from the command line. This file means it is read by both.

We can't remove it either. Black will set some files to 88 chars wide, and then Flake8 would complain because it's over 80.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

20 changes: 20 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/pypi-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 18 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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/
Expand All @@ -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
Expand Down
50 changes: 50 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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).


Expand Down
1 change: 0 additions & 1 deletion code_of_conduct.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

51 changes: 23 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
8 changes: 5 additions & 3 deletions python_docs_theme/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion python_docs_theme/static/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ document.addEventListener("DOMContentLoaded", function () {
closeMenu()
}
})
})
})
0