Skip to content

Commit e7e394d

Browse files
committed
WIP
Signed-off-by: nstarman <[email protected]>
1 parent 19c4cae commit e7e394d

8 files changed

+269
-46
lines changed

.github/workflows/ci_workflows.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: CI
33
on:
44
push:
55
branches:
6-
- main
6+
- main
77
tags:
8-
- '*'
8+
- "*"
99
pull_request:
1010

1111
concurrency:

.pre-commit-config.yaml

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
ci:
2+
autoupdate_schedule: "monthly"
3+
autoupdate_commit_msg: "chore: update pre-commit hooks"
4+
autofix_commit_msg: "style: pre-commit fixes"
5+
6+
default_stages: [pre-commit, pre-push]
7+
8+
repos:
9+
- repo: meta
10+
hooks:
11+
- id: check-useless-excludes
12+
13+
- repo: https://github.com/pre-commit/pre-commit-hooks
14+
rev: "v5.0.0"
15+
hooks:
16+
- id: check-added-large-files
17+
- id: check-case-conflict
18+
- id: check-merge-conflict
19+
- id: check-yaml
20+
- id: debug-statements
21+
- id: end-of-file-fixer
22+
- id: mixed-line-ending
23+
- id: name-tests-test
24+
args: ["--pytest-test-first"]
25+
- id: trailing-whitespace
26+
27+
- repo: https://github.com/pre-commit/pygrep-hooks
28+
rev: "v1.10.0"
29+
hooks:
30+
- id: rst-backticks
31+
- id: rst-directive-colons
32+
- id: rst-inline-touching-normal
33+
34+
- repo: https://github.com/python-jsonschema/check-jsonschema
35+
rev: 0.29.4
36+
hooks:
37+
- id: check-dependabot
38+
- id: check-github-workflows
39+
- id: check-readthedocs
40+
41+
- repo: https://github.com/astral-sh/ruff-pre-commit
42+
rev: "v0.7.3"
43+
hooks:
44+
# Run the linter
45+
- id: ruff
46+
types_or: [python, pyi, jupyter]
47+
args: ["--fix", "--show-fixes"]
48+
# Run the formatter
49+
- id: ruff-format
50+
types_or: [python, pyi, jupyter]
51+
52+
- repo: https://github.com/adamchainz/blacken-docs
53+
rev: "1.19.1"
54+
hooks:
55+
- id: blacken-docs
56+
additional_dependencies: [black==23.*]
57+
58+
- repo: https://github.com/rbubley/mirrors-prettier
59+
rev: "v3.3.3"
60+
hooks:
61+
- id: prettier
62+
types_or: [yaml, markdown, html, css, scss, javascript, json]
63+
args: [--prose-wrap=always]
64+
65+
- repo: https://github.com/pre-commit/mirrors-mypy
66+
rev: "v1.13.0"
67+
hooks:
68+
- id: mypy
69+
files: src
70+
additional_dependencies:
71+
- pytest
72+
73+
- repo: https://github.com/codespell-project/codespell
74+
rev: "v2.3.0"
75+
hooks:
76+
- id: codespell
77+
78+
- repo: https://github.com/abravalheri/validate-pyproject
79+
rev: v0.23
80+
hooks:
81+
- id: validate-pyproject
82+
83+
- repo: local
84+
hooks:
85+
- id: disallow-caps
86+
name: Disallow improper capitalization
87+
language: pygrep
88+
entry: PyBind|Numpy|Cmake|CCache|Github|PyTest
89+
exclude: .pre-commit-config.yaml

pyproject.toml

+30-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies = [
1818
"array-api-compat>=1.9.1",
1919
"astropy>=7.0",
2020
"numpy>=2.0",
21+
"typing-extensions>=4.12.2",
2122
]
2223
dynamic = ["version"]
2324

@@ -103,6 +104,30 @@ exclude_lines = [
103104
"@overload",
104105
]
105106

107+
[tool.mypy]
108+
python_version = "3.11"
109+
files = ["quantity"]
110+
strict = true
111+
112+
disallow_incomplete_defs = true
113+
disallow_untyped_defs = false
114+
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
115+
warn_return_any = true
116+
warn_unreachable = true
117+
warn_unused_configs = true
118+
119+
[[tool.mypy.overrides]]
120+
module = ["quantity._dev.*", "quantity.tests.*"]
121+
ignore_errors = true
122+
123+
[[tool.mypy.overrides]]
124+
ignore_missing_imports = true
125+
module = [
126+
"astropy.*",
127+
"array_api_compat.*"
128+
]
129+
130+
106131
[tool.ruff]
107132
exclude=[ # package template provided files.
108133
"setup.py",
@@ -140,10 +165,12 @@ ignore = [
140165
"PLR2004", # Magic value used in comparison
141166
"RET505", # Unnecessary `else`/`elif` after `return` statement
142167
]
143-
isort.required-imports = ["from __future__ import annotations"]
144-
# Uncomment if using a _compat.typing backport
145-
# typing-modules = ["quantity_2_0._compat.typing"]
146168

147169
[tool.ruff.lint.per-file-ignores]
148170
"tests/**" = ["T20"]
149171
"noxfile.py" = ["T20"]
172+
173+
[dependency-groups]
174+
typing = [
175+
"mypy>=1.13.0",
176+
]

quantity/_array_api.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Minimal definition of the Array API."""
2+
3+
from __future__ import annotations
4+
5+
from typing import Any, Protocol
6+
7+
8+
class HasArrayNameSpace(Protocol):
9+
"""Minimal defintion of the Array API."""
10+
11+
def __array_namespace__(self) -> Any: ...
12+
13+
14+
class Array(HasArrayNameSpace, Protocol):
15+
"""Minimal defintion of the Array API."""
16+
17+
def __pow__(self, other: Any) -> Array: ...

quantity/_quantity_api.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Minimal definition of the Quantity API."""
2+
3+
__all__ = ["Quantity", "ArrayQuantity", "Unit"]
4+
5+
from typing import Protocol, runtime_checkable
6+
7+
from astropy.units import UnitBase as Unit
8+
9+
from ._array_api import Array
10+
11+
12+
@runtime_checkable
13+
class Quantity(Protocol):
14+
"""Minimal definition of the Quantity API."""
15+
16+
value: Array
17+
unit: Unit
18+
19+
20+
@runtime_checkable
21+
class ArrayQuantity(Quantity, Array, Protocol):
22+
"""An array-valued Quantity."""
23+
24+
...

0 commit comments

Comments
 (0)