Skip to content

Commit cc6330f

Browse files
authored
refactor: Update pyproject.toml, fix lints, typing (#10)
* ci: Update `pypject.toml` * ci: Update `.gitattributes` * ci: Update github workflows * test: Fix tests bound to `altair==5.8.0` Still hardcoded as it isn't a trivial switch to f-strings. Need to resolve nested quoting and braces * fix: Resolve namespace-related issues * fix: Add compat for removed `sphinx.testing.path.path` Was deprecated in `(3, 9)` but removed in later versions * refactor: Replace `os.path` in `conf.py` * refactor: Fix lints, typing, minor perf tweaks * refactor: Minor reduction in `AltairPlotDirective.run` * ci: Fix missing `hatch run` in github action https://github.com/dangotbanned/sphinxext-altair/actions/runs/10422611217/job/28867476849 * build: Drop support for `python<3.9` #10 (review)
1 parent b937d72 commit cc6330f

File tree

10 files changed

+362
-205
lines changed

10 files changed

+362
-205
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* text=auto
1+
* text=auto eol=lf

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
10+
python-version: ["3.9", "3.10", "3.11", "3.12"]
1111
name: py ${{ matrix.python-version }}
1212
steps:
13-
- uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1414
- name: Set up Python ${{ matrix.python-version }}
15-
uses: actions/setup-python@v4
15+
uses: actions/setup-python@v5
1616
with:
1717
python-version: ${{ matrix.python-version }}
1818
- name: Install dependencies
@@ -21,4 +21,4 @@ jobs:
2121
pip install .[dev]
2222
- name: Test with pytest
2323
run: |
24-
pytest tests
24+
pytest --pyargs --numprocesses=logical tests

.github/workflows/lint.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ on: [push, pull_request]
55
jobs:
66
build:
77
runs-on: ubuntu-latest
8-
name: black-ruff-mypy
8+
name: ruff-mypy
99
steps:
10-
- uses: actions/checkout@v3
11-
- name: Set up Python 3.10
12-
uses: actions/setup-python@v4
10+
- uses: actions/checkout@v4
11+
- name: Set up Python 3.12
12+
uses: actions/setup-python@v5
1313
with:
14-
python-version: "3.10"
14+
python-version: "3.12"
1515
# Installing all dependencies and not just the linters as mypy needs them for type checking
1616
- name: Install dependencies
1717
run: |
1818
python -m pip install --upgrade pip
19-
pip install .[dev]
20-
- name: Check formatting with black
21-
run: |
22-
black --diff --color .
23-
black --check .
19+
pip install hatch
2420
- name: Lint with ruff
2521
run: |
26-
ruff check .
22+
hatch run ruff check .
23+
- name: Check formatting with ruff
24+
run: |
25+
hatch run ruff format --diff .
26+
hatch run ruff format --check .
2727
- name: Lint with mypy
2828
run: |
29-
mypy sphinxext_altair tests
29+
hatch run mypy sphinxext_altair tests

pyproject.toml

Lines changed: 215 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# 2 project configuration
44
# 3 tool configuration, for:
55
# - hatch
6-
# - black
76
# - ruff
87
# - pytest
98
# - mypy
@@ -16,19 +15,19 @@ build-backend = "hatchling.build"
1615
name = "sphinxext-altair"
1716
authors = [ {name = "sphinxext-altair Contributors"} ]
1817
dependencies = [
19-
"altair>=4.0.0",
18+
"altair>=5.0.0",
2019
"docutils",
2120
"jinja2",
2221
"sphinx",
23-
"typing_extensions>=4.0.1; python_version<\"3.8\"",
22+
"typing_extensions>=4.10.0; python_version<\"3.13\"",
2423
]
2524
description = "sphinxext-altair: Sphinx extension for embedding Altair charts"
2625
readme = "README.md"
2726
keywords = [
2827
"altair",
2928
"sphinxext"
3029
]
31-
requires-python = ">=3.7"
30+
requires-python = ">=3.9"
3231
dynamic = ["version"]
3332
license-files = { paths = ["LICENSE"] }
3433
classifiers= [
@@ -37,11 +36,10 @@ classifiers= [
3736
"License :: OSI Approved :: BSD License",
3837
"Natural Language :: English",
3938
"Framework :: Sphinx :: Extension",
40-
"Programming Language :: Python :: 3.7",
41-
"Programming Language :: Python :: 3.8",
4239
"Programming Language :: Python :: 3.9",
4340
"Programming Language :: Python :: 3.10",
4441
"Programming Language :: Python :: 3.11",
42+
"Programming Language :: Python :: 3.12",
4543
"Typing :: Typed",
4644
]
4745

@@ -51,9 +49,9 @@ Source = "https://github.com/altair-viz/sphinxext-altair"
5149
[project.optional-dependencies]
5250
dev = [
5351
"hatch",
54-
"ruff",
55-
"black<24",
52+
"ruff>=0.6.0",
5653
"pytest",
54+
"pytest-xdist[psutil]~=3.5",
5755
"mypy",
5856
"types-docutils",
5957
# ipython is only installed for the convenience of the developer
@@ -67,64 +65,238 @@ path = "sphinxext_altair/__init__.py"
6765
allow-direct-references = true
6866

6967
[tool.hatch.build]
70-
include = [
71-
"/sphinxext_altair"
72-
]
68+
include = ["/sphinxext_altair"]
7369

7470
[tool.hatch.envs.default]
7571
features = ["dev"]
72+
installer = "uv"
73+
74+
[tool.hatch.envs.hatch-test]
75+
features = ["dev"]
76+
default-args = ["--numprocesses=logical","--doctest-modules", "tests"]
77+
parallel = true
7678

77-
[tool.hatch.envs.default.scripts]
78-
test = [
79-
"black --diff --color --check .",
80-
"ruff check .",
79+
[[tool.hatch.envs.hatch-test.matrix]]
80+
python = ["3.9", "3.10", "3.11", "3.12"]
81+
82+
[tool.hatch.envs.hatch-test.scripts]
83+
run = [
84+
"ruff check .",
85+
"ruff format --diff --check .",
8186
"mypy sphinxext_altair tests",
82-
"python -m pytest tests"
87+
"pytest{env:HATCH_TEST_ARGS:} {args}"
8388
]
89+
run-cov = "coverage run -m pytest{env:HATCH_TEST_ARGS:} {args}"
90+
cov-combine = "coverage combine"
91+
cov-report = "coverage report"
8492

85-
build-test-docs = ["sphinx-build -b html tests/roots/test-altairplot tests/roots/test-altairplot/_build/html"]
86-
serve-test-docs = ["(cd tests/roots/test-altairplot/_build/html && python -m http.server)"]
93+
[tool.hatch.envs.doc]
94+
features = ["dev"]
8795

88-
89-
[tool.black]
90-
line-length = 88
91-
target-version = ["py37", "py38", "py39", "py310", "py311"]
92-
exclude = '''
93-
/(
94-
\.eggs
95-
| \.git
96-
| \.mypy_cache
97-
| build
98-
| dist
99-
| .venv
100-
)/
101-
'''
96+
[tool.hatch.envs.doc.scripts]
97+
clean-build-html = ["sphinx-build -b html --fresh-env tests/roots/test-altairplot tests/roots/test-altairplot/_build/html"]
98+
build-html = ["sphinx-build -b html tests/roots/test-altairplot tests/roots/test-altairplot/_build/html"]
99+
serve = ["(cd tests/roots/test-altairplot/_build/html && python -m http.server)"]
102100

103101
[tool.ruff]
104-
target-version = "py310"
102+
target-version = "py39"
105103
line-length = 88
104+
indent-width = 4
105+
exclude = []
106+
107+
[tool.ruff.format]
108+
quote-style = "double"
109+
indent-style = "space"
110+
skip-magic-trailing-comma = false
111+
line-ending = "lf"
112+
# https://docs.astral.sh/ruff/formatter/#docstring-formatting
113+
docstring-code-format = true
114+
docstring-code-line-length = 88
115+
116+
[tool.ruff.lint]
117+
# https://docs.astral.sh/ruff/preview/
118+
preview = true
119+
120+
# https://docs.astral.sh/ruff/settings/#lint_extend-safe-fixes
121+
extend-safe-fixes=[
122+
# unnecessary-comprehension-in-call
123+
"C419",
124+
# literal-membership
125+
"PLR6201",
126+
# from __future__ import annotations #
127+
# ---------------------------------- #
128+
"UP006",
129+
"UP007",
130+
"UP008",
131+
"TCH",
132+
# assign exception msg to variable #
133+
# -------------------------------- #
134+
"EM101",
135+
"EM102",
136+
# trailing-whitespace
137+
"W291",
138+
# blank line contains whitespace
139+
"W293",
140+
# unsorted-dunder-all
141+
"RUF022",
142+
# pydocstyle #
143+
# ---------- #
144+
# fits-on-one-line
145+
"D200",
146+
# escape-sequence-in-docstring
147+
"D301",
148+
# ends-in-period
149+
"D400",
150+
# missing-return-type-special-method
151+
"ANN204",
152+
# unnecessary-dict-comprehension-for-iterable
153+
"C420",
154+
]
155+
156+
# https://docs.astral.sh/ruff/preview/#using-rules-that-are-in-preview
157+
extend-select=[
158+
# refurb
159+
"FURB",
160+
# pylint (preview) autofix #
161+
# ------------------------ #
162+
# unnecessary-dunder-call
163+
"PLC2801",
164+
# unnecessary-dict-index-lookup
165+
"PLR1733",
166+
# unnecessary-list-index-lookup
167+
"PLR1736",
168+
# literal-membership
169+
"PLR6201",
170+
# unspecified-encoding
171+
"PLW1514",
172+
]
106173
select = [
107174
# flake8-bugbear
108175
"B",
109176
# flake8-comprehensions
110177
"C4",
111178
# pycodestyle-error
112179
"E",
113-
# pycodestyle-warning
114-
"W",
180+
# flake8-errmsg
181+
"EM",
115182
# pyflakes
116183
"F",
184+
# flake8-future-annotations
185+
"FA",
186+
# flynt
187+
"FLY",
188+
# flake8-pie
189+
"PIE",
190+
# flake8-pytest-style
191+
"PT",
192+
# flake8-use-pathlib
193+
"PTH",
194+
# Ruff-specific rules
195+
"RUF",
196+
# flake8-simplify
197+
"SIM",
198+
# flake8-type-checking
199+
"TCH",
117200
# flake8-tidy-imports
118-
"TID"
201+
"TID",
202+
# pyupgrade
203+
"UP",
204+
# pycodestyle-warning
205+
"W",
206+
# pylint (stable) autofix #
207+
# ----------------------- #
208+
# iteration-over-set
209+
"PLC0208",
210+
# manual-from-import
211+
"PLR0402",
212+
# useless-return
213+
"PLR1711",
214+
# repeated-equality-comparison
215+
"PLR1714",
216+
# collapsible-else-if
217+
"PLR5501",
218+
# useless-else-on-loop
219+
"PLW0120",
220+
# subprocess-run-without-check
221+
"PLW1510",
222+
# nested-min-max
223+
"PLW3301",
224+
# pydocstyle #
225+
# ---------- #
226+
"D",
227+
# multi-line-summary-second-line
228+
"D213",
229+
# numpy-specific-rules
230+
"NPY",
231+
# flake8-annotations
232+
"ANN",
233+
# unsorted-imports
234+
"I001",
235+
# complex-structure
236+
"C901",
119237
]
120-
exclude = [
121-
".git",
122-
"build",
123-
"__pycache__",
238+
ignore = [
239+
# Whitespace before ':'
240+
"E203",
241+
# Too many leading '#' for block comment
242+
"E266",
243+
# Line too long
244+
"E501",
245+
# zip() without an explicit strict= parameter set.
246+
# python>=3.10 only
247+
"B905",
248+
# mutable-class-default
249+
"RUF012",
250+
# suppressible-exception
251+
# https://github.com/vega/altair/pull/3431#discussion_r1629808660
252+
"SIM105",
253+
# pydocstyle/ https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules #
254+
# ------------------------------------------------------------------------- #
255+
# undocumented-public-module
256+
"D100",
257+
# undocumented-public-class
258+
"D101",
259+
# undocumented-public-method
260+
"D102",
261+
# undocumented-public-function
262+
"D103",
263+
# undocumented-public-package
264+
"D104",
265+
# undocumented-magic-method
266+
"D105",
267+
# undocumented-public-init
268+
"D107",
269+
# indent-with-spaces
270+
"D206",
271+
# multi-line-summary-first-line ((D213) is the opposite of this)
272+
"D212",
273+
# Imperative mood
274+
"D401",
275+
# Blank line after last section
276+
"D413",
277+
# doc-line-too-long
278+
"W505",
279+
# Any as annotation
280+
"ANN401"
124281
]
282+
# https://docs.astral.sh/ruff/settings/#lintpydocstyle
283+
pydocstyle={ convention="numpy" }
284+
mccabe={ max-complexity=10 }
125285

126-
[[tool.mypy.overrides]]
127-
module = [
128-
"altair.*"
286+
[tool.ruff.lint.isort]
287+
extra-standard-library = ["typing_extensions"]
288+
known-first-party=[
289+
"altair",
290+
"altair_tiles",
291+
"vega_datasets",
292+
"vegafusion",
293+
"vl_convert",
129294
]
295+
split-on-trailing-comma = false
296+
297+
[tool.ruff.lint.per-file-ignores]
298+
"!sphinxext_altair/altairplot.py" = ["ANN"]
299+
300+
[[tool.mypy.overrides]]
301+
module = ["altair.*"]
130302
ignore_missing_imports = true

0 commit comments

Comments
 (0)