Skip to content

Commit 3f15d86

Browse files
authored
modernize pre-commit (#133)
* replace `isort` and `flake8` with `ruff` * use the compiled version of `black` * add `prettier` * add `taplo` * upgrade `black` * run `prettier` * run `taplo-format` * run `ruff`
1 parent 52c65e6 commit 3f15d86

File tree

8 files changed

+148
-101
lines changed

8 files changed

+148
-101
lines changed

.github/dependabot.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 2
22
updates:
3-
- package-ecosystem: 'github-actions'
4-
directory: '/'
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
55
schedule:
66
# Check for updates once a week
7-
interval: 'weekly'
7+
interval: "weekly"

.github/workflows/ci.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ name: CI
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88

99
jobs:
1010
linux:
11-
name: 'sphinx v${{matrix.sphinx-version}} py${{matrix.python-version}}'
11+
name: "sphinx v${{matrix.sphinx-version}} py${{matrix.python-version}}"
1212
runs-on: ubuntu-latest
1313

1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
python-version: ['3.8', '3.9', '3.10', '3.11']
18-
sphinx-version: ['3.5', '4.5', '5.0', '5.1', '5.2', '5.3', '6.0', '6.1']
17+
python-version: ["3.8", "3.9", "3.10", "3.11"]
18+
sphinx-version: ["3.5", "4.5", "5.0", "5.1", "5.2", "5.3", "6.0", "6.1"]
1919
exclude:
2020
# sphinx versions incompatible with python 3.10
2121
- python-version: "3.10"

.github/workflows/nightly.yaml

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: Nightly CI
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88
schedule:
9-
- cron: '0 0 * * *'
9+
- cron: "0 0 * * *"
1010

1111
jobs:
1212
detect-ci-trigger:
@@ -51,7 +51,7 @@ jobs:
5151
uses: actions/checkout@v4
5252
with:
5353
# need to fetch all tags to get a correct version
54-
fetch-depth: 0 # fetch all branches and tags
54+
fetch-depth: 0 # fetch all branches and tags
5555

5656
- name: setup python
5757
uses: actions/setup-python@v5
@@ -97,72 +97,72 @@ jobs:
9797
&& github.repository == 'xarray-contrib/sphinx-autosummary-accessors'
9898
&& needs.upstream-dev.outputs.artifacts_availability == 'true'
9999
steps:
100-
- name: checkout the repository
101-
uses: actions/checkout@v4
102-
- name: setup python
103-
uses: actions/setup-python@v5
104-
with:
105-
python-version: "3.x"
106-
- uses: actions/download-artifact@v4
107-
with:
108-
path: /tmp/workspace/logs
109-
- name: Move all log files into a single directory
110-
run: |
111-
rsync -a /tmp/workspace/logs/output-*/ ./logs
112-
ls -R ./logs
113-
- name: Parse logs
114-
run: |
115-
shopt -s globstar
116-
python .github/workflows/format-report.py logs/**/*-log sphinx-log.txt
117-
- name: Report failures
118-
uses: actions/github-script@v6
119-
with:
120-
github-token: ${{ secrets.GITHUB_TOKEN }}
121-
script: |
122-
const fs = require('fs');
123-
const sphinx_logs = fs.readFileSync('sphinx-logs.txt', 'utf8');
124-
const title = "⚠️ Nightly upstream-dev CI failed ⚠️"
125-
const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
126-
const issue_body = `[Workflow Run URL](${workflow_url})\n${sphinx_logs}`
127-
128-
// Run GraphQL query against GitHub API to find the most recent open issue used for reporting failures
129-
const query = `query($owner:String!, $name:String!, $creator:String!, $label:String!){
130-
repository(owner: $owner, name: $name) {
131-
issues(first: 1, states: OPEN, filterBy: {createdBy: $creator, labels: [$label]}, orderBy: {field: CREATED_AT, direction: DESC}) {
132-
edges {
133-
node {
134-
body
135-
id
136-
number
100+
- name: checkout the repository
101+
uses: actions/checkout@v4
102+
- name: setup python
103+
uses: actions/setup-python@v5
104+
with:
105+
python-version: "3.x"
106+
- uses: actions/download-artifact@v4
107+
with:
108+
path: /tmp/workspace/logs
109+
- name: Move all log files into a single directory
110+
run: |
111+
rsync -a /tmp/workspace/logs/output-*/ ./logs
112+
ls -R ./logs
113+
- name: Parse logs
114+
run: |
115+
shopt -s globstar
116+
python .github/workflows/format-report.py logs/**/*-log sphinx-log.txt
117+
- name: Report failures
118+
uses: actions/github-script@v6
119+
with:
120+
github-token: ${{ secrets.GITHUB_TOKEN }}
121+
script: |
122+
const fs = require('fs');
123+
const sphinx_logs = fs.readFileSync('sphinx-logs.txt', 'utf8');
124+
const title = "⚠️ Nightly upstream-dev CI failed ⚠️"
125+
const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
126+
const issue_body = `[Workflow Run URL](${workflow_url})\n${sphinx_logs}`
127+
128+
// Run GraphQL query against GitHub API to find the most recent open issue used for reporting failures
129+
const query = `query($owner:String!, $name:String!, $creator:String!, $label:String!){
130+
repository(owner: $owner, name: $name) {
131+
issues(first: 1, states: OPEN, filterBy: {createdBy: $creator, labels: [$label]}, orderBy: {field: CREATED_AT, direction: DESC}) {
132+
edges {
133+
node {
134+
body
135+
id
136+
number
137+
}
137138
}
138139
}
139140
}
141+
}`;
142+
143+
const variables = {
144+
owner: context.repo.owner,
145+
name: context.repo.repo,
146+
label: 'CI',
147+
creator: "github-actions[bot]"
148+
}
149+
const result = await github.graphql(query, variables)
150+
151+
// If no issue is open, create a new issue,
152+
// else update the body of the existing issue.
153+
if (result.repository.issues.edges.length === 0) {
154+
github.rest.issues.create({
155+
owner: variables.owner,
156+
repo: variables.name,
157+
body: issue_body,
158+
title: title,
159+
labels: [variables.label]
160+
})
161+
} else {
162+
github.rest.issues.update({
163+
owner: variables.owner,
164+
repo: variables.name,
165+
issue_number: result.repository.issues.edges[0].node.number,
166+
body: issue_body
167+
})
140168
}
141-
}`;
142-
143-
const variables = {
144-
owner: context.repo.owner,
145-
name: context.repo.repo,
146-
label: 'CI',
147-
creator: "github-actions[bot]"
148-
}
149-
const result = await github.graphql(query, variables)
150-
151-
// If no issue is open, create a new issue,
152-
// else update the body of the existing issue.
153-
if (result.repository.issues.edges.length === 0) {
154-
github.rest.issues.create({
155-
owner: variables.owner,
156-
repo: variables.name,
157-
body: issue_body,
158-
title: title,
159-
labels: [variables.label]
160-
})
161-
} else {
162-
github.rest.issues.update({
163-
owner: variables.owner,
164-
repo: variables.name,
165-
issue_number: result.repository.issues.edges[0].node.number,
166-
body: issue_body
167-
})
168-
}

.github/workflows/publish.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Set up Python
1414
uses: actions/setup-python@v5
1515
with:
16-
python-version: '3.x'
16+
python-version: "3.x"
1717
- name: Install dependencies
1818
run: |
1919
python -m pip install --upgrade pip build twine

.pre-commit-config.yaml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,24 @@ repos:
1010
- id: trailing-whitespace
1111
- id: requirements-txt-fixer
1212
- id: check-merge-conflict
13-
- repo: https://github.com/pycqa/isort
14-
rev: 5.13.2
13+
- repo: https://github.com/rbubley/mirrors-prettier
14+
rev: v3.4.2
1515
hooks:
16-
- id: isort
17-
- repo: https://github.com/psf/black
18-
rev: 24.10.0
16+
- id: prettier
17+
args: ["--cache-location=.prettier_cache/cache"]
18+
- repo: https://github.com/ComPWA/taplo-pre-commit
19+
rev: v0.9.3
1920
hooks:
20-
- id: black
21-
- repo: https://github.com/PyCQA/flake8
22-
rev: 7.1.1
21+
- id: taplo-format
22+
args: ["--option", "array_auto_collapse=false"]
23+
- id: taplo-lint
24+
args: ["--no-schema"]
25+
- repo: https://github.com/astral-sh/ruff-pre-commit
26+
rev: v0.9.4
27+
hooks:
28+
- id: ruff
29+
args: ["--fix", "--show-fixes"]
30+
- repo: https://github.com/psf/black-pre-commit-mirror
31+
rev: 25.1.0
2332
hooks:
24-
- id: flake8
33+
- id: black

pyproject.toml

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[project]
22
name = "sphinx-autosummary-accessors"
3-
license = {text = "MIT"}
3+
license = { text = "MIT" }
44
description = "sphinx autosummary extension to properly format pandas or xarray accessors"
55
authors = [
6-
{name = "Justus Magin", email = "[email protected]"}
6+
{ name = "Justus Magin", email = "[email protected]" },
77
]
88
readme = "README.rst"
99
requires-python = ">=3.8"
1010
dependencies = [
11-
"sphinx >= 3.5",
11+
"sphinx >= 3.5",
1212
]
1313
dynamic = ["version"]
1414

@@ -22,14 +22,52 @@ requires = ["setuptools>=64", "setuptools-scm[toml]>=7.0"]
2222
build-backend = "setuptools.build_meta"
2323

2424
[tool.setuptools.packages.find]
25-
include = ["sphinx_autosummary_accessors", "sphinx_autosummary_accessors.templates"]
25+
include = [
26+
"sphinx_autosummary_accessors",
27+
"sphinx_autosummary_accessors.templates",
28+
]
2629

2730
[tool.setuptools_scm]
2831
fallback_version = "999"
2932

30-
[tool.isort]
31-
profile = "black"
32-
skip_gitignore = "true"
33-
force_to_top = "true"
34-
default_section = "THIRDPARTY"
35-
known_first_party = "sphinx_autosummary_accessors"
33+
[tool.ruff]
34+
target-version = "py38"
35+
builtins = ["ellipsis"]
36+
exclude = [
37+
".git",
38+
".eggs",
39+
"build",
40+
"dist",
41+
"__pycache__",
42+
]
43+
line-length = 100
44+
45+
[tool.ruff.lint]
46+
# E402: module level import not at top of file
47+
# E501: line too long - let black worry about that
48+
# E731: do not assign a lambda expression, use a def
49+
ignore = [
50+
"E402",
51+
"E501",
52+
"E731",
53+
]
54+
select = [
55+
"F", # Pyflakes
56+
"E", # Pycodestyle
57+
"I", # isort
58+
"UP", # Pyupgrade
59+
"TID", # flake8-tidy-imports
60+
"W",
61+
]
62+
extend-safe-fixes = [
63+
"TID252", # absolute imports
64+
]
65+
fixable = ["I", "TID252"]
66+
67+
[tool.ruff.lint.isort]
68+
known-first-party = ["sphinx_autosummary_accessors"]
69+
known-third-party = ["sphinx"]
70+
71+
[tool.ruff.lint.flake8-tidy-imports]
72+
# Disallow all relative imports.
73+
ban-relative-imports = "all"

sphinx_autosummary_accessors/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
except ImportError:
44
from importlib_metadata import version
55

6-
from . import autosummary
7-
from .documenters import (
6+
from sphinx_autosummary_accessors import autosummary
7+
from sphinx_autosummary_accessors.documenters import (
88
AccessorAttributeDocumenter,
99
AccessorCallableDocumenter,
1010
AccessorDocumenter,
1111
AccessorMethodDocumenter,
1212
)
13-
from .templates import templates_path # noqa: F401
13+
from sphinx_autosummary_accessors.templates import templates_path # noqa: F401
1414

1515
try:
1616
__version__ = version("sphinx-autosummary-accessors")

sphinx_autosummary_accessors/autosummary.py

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

33
from sphinx.ext.autosummary import Autosummary, generate
44

5-
from .templates import known_templates
5+
from sphinx_autosummary_accessors.templates import known_templates
66

77
directives_re = re.compile(r"^\.\. ([^:]+):: (.+)$", re.MULTILINE)
88

0 commit comments

Comments
 (0)