Skip to content

Commit

Permalink
refactor: Update pyproject.toml, fix lints, typing (#10)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
dangotbanned authored Aug 19, 2024
1 parent b937d72 commit cc6330f
Show file tree
Hide file tree
Showing 10 changed files with 362 additions and 205 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* text=auto
* text=auto eol=lf
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
name: py ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -21,4 +21,4 @@ jobs:
pip install .[dev]
- name: Test with pytest
run: |
pytest tests
pytest --pyargs --numprocesses=logical tests
24 changes: 12 additions & 12 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
name: black-ruff-mypy
name: ruff-mypy
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v4
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"
# Installing all dependencies and not just the linters as mypy needs them for type checking
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]
- name: Check formatting with black
run: |
black --diff --color .
black --check .
pip install hatch
- name: Lint with ruff
run: |
ruff check .
hatch run ruff check .
- name: Check formatting with ruff
run: |
hatch run ruff format --diff .
hatch run ruff format --check .
- name: Lint with mypy
run: |
mypy sphinxext_altair tests
hatch run mypy sphinxext_altair tests
258 changes: 215 additions & 43 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# 2 project configuration
# 3 tool configuration, for:
# - hatch
# - black
# - ruff
# - pytest
# - mypy
Expand All @@ -16,19 +15,19 @@ build-backend = "hatchling.build"
name = "sphinxext-altair"
authors = [ {name = "sphinxext-altair Contributors"} ]
dependencies = [
"altair>=4.0.0",
"altair>=5.0.0",
"docutils",
"jinja2",
"sphinx",
"typing_extensions>=4.0.1; python_version<\"3.8\"",
"typing_extensions>=4.10.0; python_version<\"3.13\"",
]
description = "sphinxext-altair: Sphinx extension for embedding Altair charts"
readme = "README.md"
keywords = [
"altair",
"sphinxext"
]
requires-python = ">=3.7"
requires-python = ">=3.9"
dynamic = ["version"]
license-files = { paths = ["LICENSE"] }
classifiers= [
Expand All @@ -37,11 +36,10 @@ classifiers= [
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Framework :: Sphinx :: Extension",
"Programming Language :: Python :: 3.7",
"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",
"Typing :: Typed",
]

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

[tool.hatch.build]
include = [
"/sphinxext_altair"
]
include = ["/sphinxext_altair"]

[tool.hatch.envs.default]
features = ["dev"]
installer = "uv"

[tool.hatch.envs.hatch-test]
features = ["dev"]
default-args = ["--numprocesses=logical","--doctest-modules", "tests"]
parallel = true

[tool.hatch.envs.default.scripts]
test = [
"black --diff --color --check .",
"ruff check .",
[[tool.hatch.envs.hatch-test.matrix]]
python = ["3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.hatch-test.scripts]
run = [
"ruff check .",
"ruff format --diff --check .",
"mypy sphinxext_altair tests",
"python -m pytest tests"
"pytest{env:HATCH_TEST_ARGS:} {args}"
]
run-cov = "coverage run -m pytest{env:HATCH_TEST_ARGS:} {args}"
cov-combine = "coverage combine"
cov-report = "coverage report"

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


[tool.black]
line-length = 88
target-version = ["py37", "py38", "py39", "py310", "py311"]
exclude = '''
/(
\.eggs
| \.git
| \.mypy_cache
| build
| dist
| .venv
)/
'''
[tool.hatch.envs.doc.scripts]
clean-build-html = ["sphinx-build -b html --fresh-env tests/roots/test-altairplot tests/roots/test-altairplot/_build/html"]
build-html = ["sphinx-build -b html tests/roots/test-altairplot tests/roots/test-altairplot/_build/html"]
serve = ["(cd tests/roots/test-altairplot/_build/html && python -m http.server)"]

[tool.ruff]
target-version = "py310"
target-version = "py39"
line-length = 88
indent-width = 4
exclude = []

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "lf"
# https://docs.astral.sh/ruff/formatter/#docstring-formatting
docstring-code-format = true
docstring-code-line-length = 88

[tool.ruff.lint]
# https://docs.astral.sh/ruff/preview/
preview = true

# https://docs.astral.sh/ruff/settings/#lint_extend-safe-fixes
extend-safe-fixes=[
# unnecessary-comprehension-in-call
"C419",
# literal-membership
"PLR6201",
# from __future__ import annotations #
# ---------------------------------- #
"UP006",
"UP007",
"UP008",
"TCH",
# assign exception msg to variable #
# -------------------------------- #
"EM101",
"EM102",
# trailing-whitespace
"W291",
# blank line contains whitespace
"W293",
# unsorted-dunder-all
"RUF022",
# pydocstyle #
# ---------- #
# fits-on-one-line
"D200",
# escape-sequence-in-docstring
"D301",
# ends-in-period
"D400",
# missing-return-type-special-method
"ANN204",
# unnecessary-dict-comprehension-for-iterable
"C420",
]

# https://docs.astral.sh/ruff/preview/#using-rules-that-are-in-preview
extend-select=[
# refurb
"FURB",
# pylint (preview) autofix #
# ------------------------ #
# unnecessary-dunder-call
"PLC2801",
# unnecessary-dict-index-lookup
"PLR1733",
# unnecessary-list-index-lookup
"PLR1736",
# literal-membership
"PLR6201",
# unspecified-encoding
"PLW1514",
]
select = [
# flake8-bugbear
"B",
# flake8-comprehensions
"C4",
# pycodestyle-error
"E",
# pycodestyle-warning
"W",
# flake8-errmsg
"EM",
# pyflakes
"F",
# flake8-future-annotations
"FA",
# flynt
"FLY",
# flake8-pie
"PIE",
# flake8-pytest-style
"PT",
# flake8-use-pathlib
"PTH",
# Ruff-specific rules
"RUF",
# flake8-simplify
"SIM",
# flake8-type-checking
"TCH",
# flake8-tidy-imports
"TID"
"TID",
# pyupgrade
"UP",
# pycodestyle-warning
"W",
# pylint (stable) autofix #
# ----------------------- #
# iteration-over-set
"PLC0208",
# manual-from-import
"PLR0402",
# useless-return
"PLR1711",
# repeated-equality-comparison
"PLR1714",
# collapsible-else-if
"PLR5501",
# useless-else-on-loop
"PLW0120",
# subprocess-run-without-check
"PLW1510",
# nested-min-max
"PLW3301",
# pydocstyle #
# ---------- #
"D",
# multi-line-summary-second-line
"D213",
# numpy-specific-rules
"NPY",
# flake8-annotations
"ANN",
# unsorted-imports
"I001",
# complex-structure
"C901",
]
exclude = [
".git",
"build",
"__pycache__",
ignore = [
# Whitespace before ':'
"E203",
# Too many leading '#' for block comment
"E266",
# Line too long
"E501",
# zip() without an explicit strict= parameter set.
# python>=3.10 only
"B905",
# mutable-class-default
"RUF012",
# suppressible-exception
# https://github.com/vega/altair/pull/3431#discussion_r1629808660
"SIM105",
# pydocstyle/ https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules #
# ------------------------------------------------------------------------- #
# undocumented-public-module
"D100",
# undocumented-public-class
"D101",
# undocumented-public-method
"D102",
# undocumented-public-function
"D103",
# undocumented-public-package
"D104",
# undocumented-magic-method
"D105",
# undocumented-public-init
"D107",
# indent-with-spaces
"D206",
# multi-line-summary-first-line ((D213) is the opposite of this)
"D212",
# Imperative mood
"D401",
# Blank line after last section
"D413",
# doc-line-too-long
"W505",
# Any as annotation
"ANN401"
]
# https://docs.astral.sh/ruff/settings/#lintpydocstyle
pydocstyle={ convention="numpy" }
mccabe={ max-complexity=10 }

[[tool.mypy.overrides]]
module = [
"altair.*"
[tool.ruff.lint.isort]
extra-standard-library = ["typing_extensions"]
known-first-party=[
"altair",
"altair_tiles",
"vega_datasets",
"vegafusion",
"vl_convert",
]
split-on-trailing-comma = false

[tool.ruff.lint.per-file-ignores]
"!sphinxext_altair/altairplot.py" = ["ANN"]

[[tool.mypy.overrides]]
module = ["altair.*"]
ignore_missing_imports = true
Loading

0 comments on commit cc6330f

Please sign in to comment.