Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@ jobs:
python-version: "3.13"
version: latest

- name: ruff
run: |
uv run ruff check --output-format=github
uv run ruff format --check
- name: ruff check
run: uv run ruff check --output-format=github

- name: typecheck numpy-stubs/random (basedpyright)
- name: ruff format --check
run: uv run ruff format --check

- name: basedpyright (numpy-stubs)
run: uv run basedpyright src/numpy-stubs/random

- name: typecheck numpy-stubs/random (basedmypy)
- name: basedpyright (test)
run: uv run basedpyright test/

- name: basedmypy (numpy-stubs)
run: uv run --no-editable mypy src/numpy-stubs/random

- name: test static (basedpyright)
run: uv run --project test static bpr
- name: basedmypy (test)
run: uv run test/bmp.py

- name: test static (basedmypy)
run: uv run --project test static bmp
- name: pytest
run: uv run pytest
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"evenBetterToml.formatter.indentString": " ",
"evenBetterToml.formatter.indentTables": true,
"evenBetterToml.formatter.trailingNewline": true,
"mypy-type-checker.path": ["uv", "run", "--project=test", "static", "bmp", "--ide"]
"mypy-type-checker.path": ["uv", "run", "test/bmp.py", "--ide"]
}
25 changes: 20 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ dev = [
{include-group = "numpy"},
"libcst>=1.6.0",
"ruff>=0.9.4",
# keep in sync with test/pyproject.toml
"basedmypy[faster-cache]>=2.9.1",
"basedmypy[faster-cache]>=2.9.1", # keep in sync with test/my.py
"basedpyright>=1.26.0",
"pytest>=8.3.4",
]


Expand All @@ -60,7 +60,7 @@ packages = ["src/numpy-stubs"]
"/.github",
"/.vscode",
"/dist",
"/docs",
"/doc",
"/test",
"/tool",
".libcst.codemod.yaml",
Expand All @@ -81,27 +81,32 @@ strict = true
disable_bytearray_promotion = true
disable_memoryview_promotion = true
enable_error_code = ["ignore-without-code", "truthy-bool"]
disallow_any_explicit = false
disallow_any_expr = false
disallow_any_decorated = false
warn_unused_ignores = true
# TODO
disable_error_code = ["explicit-override"]
# basedmypy/mypy compat
bare_literals = false
default_return = false
disallow_any_explicit = false
disallow_untyped_calls = false
warn_unreachable = false


[tool.pyright]
include = [
"src/numpy-stubs",
"test/runtime/accept",
"test/static/accept",
"test/static/reject",
"test/static/sanity",
"tool",
]
ignore = [".venv", "test/.venv"]
stubPath = "."
venvPath = "."
venv = ".venv"
pythonPlatform = "All"
pythonVersion = "3.10"
typeCheckingMode = "standard" # TODO(jorenham): set to "all"
Expand All @@ -119,6 +124,7 @@ reportShadowedImports = true
reportUninitializedInstanceVariable = true
reportUnnecessaryTypeIgnoreComment = true
reportUnusedExpression = false
reportUnusedParameter = false
# basedpyright only
failOnWarnings = true
reportIgnoreCommentWithoutRule = true
Expand All @@ -132,7 +138,7 @@ strictGenericNarrowing = true


[tool.ruff]
src = ["src/numpy-stubs", "test", "tool"]
src = ["src/numpy-stubs", "test/runtime", "test/static", "tool"]
extend-exclude = [".git", ".mypy_cache", ".tox", ".venv"]
force-exclude = true
# https://typing.readthedocs.io/en/latest/guides/writing_stubs.html#maximum-line-length
Expand Down Expand Up @@ -163,6 +169,9 @@ preview = true
"PLC2701", # pylint/C: import-private-name
]

[tool.ruff.lint.flake8-builtins]
builtins-allowed-modules = ["random"]

[tool.ruff.lint.flake8-import-conventions]
banned-from = [
"abc",
Expand Down Expand Up @@ -190,6 +199,12 @@ preview = true
[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.ruff.lint.pylint]
allow-dunder-method-names = ["__array__", "__array_ufunc__"]


[tool.typos.default]
extend-ignore-identifiers-re = ['ND|nd']

[tool.typos.files]
extend-exclude = ["*.pyi", ".mypyignore"]
28 changes: 20 additions & 8 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
# NumType testing

## basedmypy

Mypy and basedmypy will only recognize the `src/numpy-stubs` if `numtype` is installed in an
isolated project, and it cannot be editable.
The private `numtype-test` project in this directory provides entrypoints that will run basedmypy
and basedpyright.

To run basedmypy (`bmp` for short) on the static tests, run
The `bmp.py` script creates an isolated environment, that doesn't include numpy, and will run
basedmypy. If no paths are provided, it will default to `--explicit-package-bases test`.

```bash
uv run static <bmp|bpr|all> [OPTIONS]
uv run test/bmp.py [OPTIONS]
```

Here, `bmp` runs (based)`mypy`, `bpr` runs `basedpyright`, and `all` runs both.
If no options are provided, it defaults to `static/`.
## basedpyright

Unlike mypy, no additional project isolation trickery is required, so it can be run directly
from the main project:

```bash
uv run basedpyright [OPTIONS]
```

To run this form the root `numtype` directory, you can pass an additional `--project=test` flag
to the `uv run` command (i.e. before `static`).
## pytest

Pytest also works out-of-the box, and will, by default, run the tests in `test/runtime`:

```bash
uv run pytest [OPTIONS]
```
49 changes: 49 additions & 0 deletions test/bmp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# /// script
# dependencies = [
# "numtype",
# "pytest", # imported in test/runtime
# "basedmypy[faster-cache]",
# ]
#
# [tool.uv]
# reinstall-package = ["numtype"]
#
# [tool.uv.sources]
# numtype = {path = ".."}
# ///

"""
Usage: `uv run test/bmp.py <OPTIONS>`
"""

import subprocess
import sys
from pathlib import Path

TEST_DIR = Path(__file__).parent
CWD = Path.cwd()


cmd = ["mypy"]

if TEST_DIR.parent != CWD and "--config-file" not in sys.argv:
config_path = TEST_DIR.parent / "pyproject.toml"
try: # noqa: SIM105
config_path = config_path.relative_to(CWD)
except ValueError:
pass

cmd.extend(("--config-file", str(config_path)))

if len(sys.argv) > 1 or any(not arg.lstrip().startswith("-") for arg in sys.argv[1:]):
cmd.extend(sys.argv[1:])
else:
cmd.append("--explicit-package-bases") # avoids submodule name clashes
cmd.extend(sys.argv[1:])
cmd.append(str(TEST_DIR.relative_to(CWD)))


if "--ide" not in sys.argv:
print(*cmd)

sys.exit(subprocess.call(cmd))
75 changes: 0 additions & 75 deletions test/main.py

This file was deleted.

30 changes: 0 additions & 30 deletions test/pyproject.toml

This file was deleted.

9 changes: 9 additions & 0 deletions test/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extend = "../pyproject.toml"

[lint]
extend-ignore = [
"D", # pydocstyle
"ERA", # eradicate
"S", # flake8-bandit
"T", # flake8-print
]
Empty file added test/runtime/accept/__init__.py
Empty file.
Loading