Skip to content

Commit

Permalink
MAINT: autoupdate pre-commit hooks (#19)
Browse files Browse the repository at this point in the history
* DX: disable telemetry
* DX: do not cancel parallel runs on `main` branch
* DX: execute formatter pre-commit hooks first
* DX: format notebooks on save
* DX: install Jinja syntax extension for VS Code
* DX: outsource PR linting to ComPWA/actions
* DX: switch to built-in VS Code lines sorter
* DX: switch to Python 3.9 for the dev environment
* DX: switch to Ruff as formatter
* MAINT: address Ruff issues
* MAINT: apply new `black` formatting
* MAINT: autoupdate pre-commit hooks
* MAINT: upgrade release-drafter workflow
  • Loading branch information
redeboer authored Mar 10, 2024
1 parent 330a49e commit e8afc9a
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 109 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: CI

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
cancel-in-progress: |-
${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }}
env:
PYTHONHASHSEED: "0"
Expand Down
23 changes: 2 additions & 21 deletions .github/workflows/pr-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,5 @@ on:
- unlabeled

jobs:
check-labels:
name: Check labels
runs-on: ubuntu-22.04
steps:
- uses: docker://agilepathway/pull-request-label-checker:latest # cspell:ignore agilepathway
with:
any_of: >-
🐛 Bug,✨ Feature,⚙️ Enhancement,⚠️ Interface,❗ Behavior,📝 Docs,🔨 Maintenance,🖱️ DX
none_of: Epic,💫 Good first issue
repo_token: ${{ secrets.GITHUB_TOKEN }}

check-title:
name: Check title
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: npm install @compwa/commitlint-config
- name: Create commitlint config
run: |
echo "module.exports = {extends: ['@compwa/commitlint-config']}" > commitlint.config.js
- uses: JulienKode/pull-request-name-linter-action@v0.5.0 # cspell:ignore kode
lint-pr:
uses: ComPWA/actions/.github/workflows/pr-linting.yml@v1
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
update_release_draft:
runs-on: ubuntu-22.04
steps:
- uses: release-drafter/release-drafter@v5
- uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55 changes: 23 additions & 32 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ repos:
- id: check-hooks-apply
- id: check-useless-excludes

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.2
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand All @@ -34,18 +41,25 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier

- repo: https://github.com/ComPWA/mirrors-taplo
rev: v0.8.1
hooks:
- id: black
- id: taplo

- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
hooks:
- id: blacken-docs
- id: toml-sort
args:
- --in-place

- repo: https://github.com/ComPWA/policy
rev: 0.2.0
rev: 0.3.0
hooks:
- id: check-dev-files
args:
Expand All @@ -56,7 +70,7 @@ repos:
- --repo-title=sphinx-api-relink

- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.3.0
rev: v8.6.0
hooks:
- id: cspell

Expand All @@ -80,30 +94,7 @@ repos:
types:
- python

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier

- repo: https://github.com/ComPWA/mirrors-pyright
rev: v1.1.345
rev: v1.1.353
hooks:
- id: pyright

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.13
hooks:
- id: ruff
args: [--fix]

- repo: https://github.com/ComPWA/mirrors-taplo
rev: v0.8.1
hooks:
- id: taplo

- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
hooks:
- id: toml-sort
args:
- --in-place
9 changes: 5 additions & 4 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"github.vscode-github-actions",
"ms-python.black-formatter",
"ms-python.mypy-type-checker",
"ms-python.python",
"ms-python.vscode-pylance",
"redhat.vscode-yaml",
"ryanluker.vscode-coverage-gutters",
"Soulcode.vscode-unwanted-extensions",
"soulcode.vscode-unwanted-extensions",
"stkb.rewrap",
"streetsidesoftware.code-spell-checker",
"tamasfe.even-better-toml",
"tyriar.sort-lines",
"wholroyd.jinja",
"yzhang.markdown-all-in-one"
],
"unwantedRecommendations": [
"bungcip.better-toml",
"davidanson.vscode-markdownlint",
"garaioag.garaio-vscode-unwanted-recommendations",
"ms-python.black-formatter",
"ms-python.flake8",
"ms-python.isort",
"ms-python.pylint",
"travisillig.vscode-json-stable-stringify"
"travisillig.vscode-json-stable-stringify",
"tyriar.sort-lines"
]
}
16 changes: 13 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.rulers": [88]
},
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"black-formatter.importStrategy": "fromEnvironment",
"coverage-gutters.coverageFileNames": ["coverage.xml"],
"coverage-gutters.coverageReportFileName": "**/htmlcov/index.html",
"coverage-gutters.showGutterCoverage": false,
"coverage-gutters.showLineCoverage": true,
"cSpell.enabled": true,
"diffEditor.experimental.showMoves": true,
"editor.formatOnSave": true,
"files.associations": {
"*.rst_t": "jinja"
},
"files.watcherExclude": {
"**/*_cache/**": true,
"**/.eggs/**": true,
Expand All @@ -45,13 +47,21 @@
"git.rebaseWhenSync": true,
"github-actions.workflows.pinned.refresh.enabled": true,
"github-actions.workflows.pinned.workflows": [".github/workflows/ci.yml"],
"gitlens.telemetry.enabled": false,
"multiDiffEditor.experimental.enabled": true,
"mypy-type-checker.args": ["--config-file=${workspaceFolder}/pyproject.toml"],
"mypy-type-checker.importStrategy": "fromEnvironment",
"notebook.codeActionsOnSave": {
"notebook.source.organizeImports": "explicit"
},
"notebook.formatOnSave.enabled": true,
"python.analysis.autoImportCompletions": false,
"python.analysis.typeCheckingMode": "strict",
"python.testing.unittestEnabled": false,
"redhat.telemetry.enabled": false,
"rewrap.wrappingColumn": 88,
"ruff.enable": true,
"ruff.organizeImports": true
"ruff.importStrategy": "fromEnvironment",
"ruff.organizeImports": true,
"telemetry.telemetryLevel": "off"
}
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/ComPWA/sphinx-api-relink/main.svg)](https://results.pre-commit.ci/latest/github/ComPWA/sphinx-api-relink/main)
[![Spelling checked](https://img.shields.io/badge/cspell-checked-brightgreen.svg)](https://github.com/streetsidesoftware/cspell/tree/master/packages/cspell)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

This package is a plugin for the [`sphinx.ext.autodoc`](https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html) extension. The [`autodoc_type_aliases`](https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_type_aliases) configuration does not always work well when using postponed evaluation of annotations ([PEP 563](https://peps.python.org/pep-0563), i.e. `from __future__ import annotations`) or when importing through [`typing.TYPE_CHECKING`](https://docs.python.org/3/library/typing.html#typing.TYPE_CHECKING), because `sphinx.ext.autodoc` generates the API dynamically (not statically, as opposed to [`sphinx-autoapi`](https://github.com/readthedocs/sphinx-autoapi)).
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: sphinx-api-relink
channels:
- defaults
dependencies:
- python==3.8.*
- python==3.9.*
- pip
- pip:
- -e .[dev]
Expand Down
63 changes: 23 additions & 40 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,17 @@ requires-python = ">=3.7"

[project.optional-dependencies]
dev = ["sphinx-api-relink[sty]"]
format = ["black"]
lint = [
sty = [
"mypy",
"pre-commit >=1.4.0",
"ruff",
"sphinx-api-relink[mypy]",
"sphinx-api-relink[types]",
]
mypy = [
"mypy",
types = [
"types-colorama",
"types-docutils",
"types-requests",
]
sty = [
"pre-commit >=1.4.0",
"sphinx-api-relink[format]",
"sphinx-api-relink[lint]",
]

[project.readme]
content-type = "text/markdown"
Expand Down Expand Up @@ -91,31 +86,6 @@ where = ["src"]
[tool.setuptools_scm]
write_to = "src/version.py"

[tool.black]
exclude = '''
/(
.*\.egg-info
| .*build
| \.eggs
| \.git
| \.pytest_cache
| \.tox
| \.venv
| \.vscode
| dist
)/
'''
include = '\.pyi?$'
preview = true
target-version = [
"py310",
"py311",
"py312",
"py37",
"py38",
"py39",
]

[tool.coverage.run]
branch = true
source = ["src"]
Expand Down Expand Up @@ -157,6 +127,16 @@ reportUnusedVariable = true
typeCheckingMode = "strict"

[tool.ruff]
preview = true
show-fixes = true
src = ["src"]
target-version = "py37"

[tool.ruff.format]
docstring-code-format = true
line-ending = "lf"

[tool.ruff.lint]
extend-select = [
"A",
"B",
Expand Down Expand Up @@ -201,16 +181,19 @@ ignore = [
"D407",
"D416",
"E501",
"ISC001",
"PLW1514",
"PLW2901",
"S404",
"SIM108",
"UP036",
]
show-fixes = true
src = ["src"]
target-version = "py37"
task-tags = ["cspell"]

[tool.ruff.per-file-ignores]
[tool.ruff.lint.isort]
split-on-trailing-comma = false

[tool.ruff.lint.per-file-ignores]
"setup.py" = ["D100"]
"tests/*" = [
"D",
Expand All @@ -221,7 +204,7 @@ task-tags = ["cspell"]
"S101",
]

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.tomlsort]
Expand Down
8 changes: 4 additions & 4 deletions src/sphinx_api_relink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ def replace_type_to_xref(app: Sphinx, _: BuildEnvironment) -> None:
k: v if isinstance(v, str) else v[1] for k, v in target_substitutions.items()
}
ref_types = _get_target_types(app)
ref_types.update(
{v[1]: v[0] for v in target_substitutions.values() if isinstance(v, tuple)}
)
ref_types.update({
v[1]: v[0] for v in target_substitutions.values() if isinstance(v, tuple)
})

def _new_type_to_xref(
target: str,
Expand Down Expand Up @@ -193,7 +193,7 @@ def _create_nodes(env: BuildEnvironment, title: str) -> list[nodes.Node]:


def wiki_role(pattern: str) -> RoleFunction:
def role( # noqa: PLR0913
def role( # noqa: PLR0913, PLR0917
name: str,
rawtext: str,
text: str,
Expand Down
2 changes: 1 addition & 1 deletion src/sphinx_api_relink/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def pin_minor(package_name: str) -> str:


def set_intersphinx_version_remapping(
version_remapping: dict[str, dict[str, str]]
version_remapping: dict[str, dict[str, str]],
) -> None:
if not isinstance(version_remapping, dict):
msg = (
Expand Down

0 comments on commit e8afc9a

Please sign in to comment.