Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <[email protected]>
  • Loading branch information
nstarman committed Nov 27, 2024
1 parent 19c4cae commit 2c1ab5e
Show file tree
Hide file tree
Showing 9 changed files with 1,192 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci_workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: CI
on:
push:
branches:
- main
- main
tags:
- '*'
- "*"
pull_request:

concurrency:
Expand Down
89 changes: 89 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
ci:
autoupdate_schedule: "monthly"
autoupdate_commit_msg: "chore: update pre-commit hooks"
autofix_commit_msg: "style: pre-commit fixes"

default_stages: [pre-commit, pre-push]

repos:
- repo: meta
hooks:
- id: check-useless-excludes

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v5.0.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: name-tests-test
args: ["--pytest-test-first"]
- id: trailing-whitespace

- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.4
hooks:
- id: check-dependabot
- id: check-github-workflows
- id: check-readthedocs

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.3"
hooks:
# Run the linter
- id: ruff
types_or: [python, pyi, jupyter]
args: ["--fix", "--show-fixes"]
# Run the formatter
- id: ruff-format
types_or: [python, pyi, jupyter]

- repo: https://github.com/adamchainz/blacken-docs
rev: "1.19.1"
hooks:
- id: blacken-docs
additional_dependencies: [black==23.*]

- repo: https://github.com/rbubley/mirrors-prettier
rev: "v3.3.3"
hooks:
- id: prettier
types_or: [yaml, markdown, html, css, scss, javascript, json]
args: [--prose-wrap=always]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.13.0"
hooks:
- id: mypy
files: src
additional_dependencies:
- pytest

- repo: https://github.com/codespell-project/codespell
rev: "v2.3.0"
hooks:
- id: codespell

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.23
hooks:
- id: validate-pyproject

- repo: local
hooks:
- id: disallow-caps
name: Disallow improper capitalization
language: pygrep
entry: PyBind|Numpy|Cmake|CCache|Github|PyTest
exclude: .pre-commit-config.yaml
33 changes: 30 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies = [
"array-api-compat>=1.9.1",
"astropy>=7.0",
"numpy>=2.0",
"typing-extensions>=4.12.2",
]
dynamic = ["version"]

Expand Down Expand Up @@ -103,6 +104,30 @@ exclude_lines = [
"@overload",
]

[tool.mypy]
python_version = "3.11"
files = ["quantity"]
strict = true

disallow_incomplete_defs = true
disallow_untyped_defs = false
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
warn_return_any = true
warn_unreachable = true
warn_unused_configs = true

[[tool.mypy.overrides]]
module = ["quantity._dev.*", "quantity.tests.*"]
ignore_errors = true

[[tool.mypy.overrides]]
ignore_missing_imports = true
module = [
"astropy.*",
"array_api_compat.*"
]


[tool.ruff]
exclude=[ # package template provided files.
"setup.py",
Expand Down Expand Up @@ -140,10 +165,12 @@ ignore = [
"PLR2004", # Magic value used in comparison
"RET505", # Unnecessary `else`/`elif` after `return` statement
]
isort.required-imports = ["from __future__ import annotations"]
# Uncomment if using a _compat.typing backport
# typing-modules = ["quantity_2_0._compat.typing"]

[tool.ruff.lint.per-file-ignores]
"tests/**" = ["T20"]
"noxfile.py" = ["T20"]

[dependency-groups]
typing = [
"mypy>=1.13.0",
]
17 changes: 17 additions & 0 deletions quantity/_array_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Minimal definition of the Array API."""

from __future__ import annotations

from typing import Any, Protocol


class HasArrayNameSpace(Protocol):
"""Minimal defintion of the Array API."""

def __array_namespace__(self) -> Any: ...


class Array(HasArrayNameSpace, Protocol):
"""Minimal defintion of the Array API."""

def __pow__(self, other: Any) -> Array: ...
24 changes: 24 additions & 0 deletions quantity/_quantity_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Minimal definition of the Quantity API."""

__all__ = ["Quantity", "ArrayQuantity", "Unit"]

from typing import Protocol, runtime_checkable

from astropy.units import UnitBase as Unit

from ._array_api import Array


@runtime_checkable
class Quantity(Protocol):
"""Minimal definition of the Quantity API."""

value: Array
unit: Unit


@runtime_checkable
class ArrayQuantity(Quantity, Array, Protocol):
"""An array-valued Quantity."""

...
Loading

0 comments on commit 2c1ab5e

Please sign in to comment.