From a8286708c1eef14f8d089223b882157a655a3909 Mon Sep 17 00:00:00 2001 From: jorenham Date: Mon, 10 Feb 2025 00:39:25 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20new=20public=20`numtype`=20packa?= =?UTF-8?q?ge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 18 +++++++++++------- src/{ => numpy-stubs}/ruff.toml | 2 +- src/numtype/__init__.py | 7 +++++++ src/numtype/ruff.toml | 2 ++ src/numtype/version.py | 7 +++++++ test/runtime/test_numtype.py | 18 ++++++++++++++++++ 6 files changed, 46 insertions(+), 8 deletions(-) rename src/{ => numpy-stubs}/ruff.toml (96%) create mode 100644 src/numtype/__init__.py create mode 100644 src/numtype/ruff.toml create mode 100644 src/numtype/version.py create mode 100644 test/runtime/test_numtype.py diff --git a/pyproject.toml b/pyproject.toml index 0db9a007..92c10d70 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,8 +26,11 @@ classifiers = [ "Typing :: Stubs Only", "Typing :: Typed", ] +packages = [ + {include = "src/numpy-stubs"}, + {include = "src/numtype"}, +] requires-python = ">=3.10" -packages = [{include = "src/numpy-stubs"}] dependencies = [] [project.optional-dependencies] @@ -53,7 +56,7 @@ dev = [ [tool.hatch.build] -packages = ["src/numpy-stubs"] +packages = ["src/numpy-stubs", "src/numtype"] [tool.hatch.build.targets.sdist] exclude = [ @@ -64,6 +67,7 @@ packages = ["src/numpy-stubs"] "/test", "/tool", ".libcst.codemod.yaml", + ".pre-commit-config.yaml", "CONTRIBUTING.md", "uv.lock", ] @@ -98,10 +102,9 @@ warn_unreachable = false [tool.pyright] include = [ "src/numpy-stubs", - "test/runtime/accept", - "test/static/accept", - "test/static/reject", - "test/static/sanity", + "src/numtype", + "test/runtime", + "test/static", "tool", ] ignore = [".venv", "test/.venv"] @@ -139,7 +142,7 @@ strictGenericNarrowing = true [tool.ruff] -src = ["src/numpy-stubs", "test/runtime", "test/static", "tool"] +src = ["src/numpy-stubs", "src/numtype", "test", "tool"] extend-exclude = [".git", ".mypy_cache", ".tox", ".venv"] force-exclude = true # https://typing.readthedocs.io/en/latest/guides/writing_stubs.html#maximum-line-length @@ -189,6 +192,7 @@ preview = true "datetime" = "dt" "numpy" = "np" "numpy.typing" = "npt" + "numtype" = "nt" [tool.ruff.lint.isort] case-sensitive = true diff --git a/src/ruff.toml b/src/numpy-stubs/ruff.toml similarity index 96% rename from src/ruff.toml rename to src/numpy-stubs/ruff.toml index b0202302..91887c46 100644 --- a/src/ruff.toml +++ b/src/numpy-stubs/ruff.toml @@ -1,4 +1,4 @@ -extend = "../pyproject.toml" +extend = "../../pyproject.toml" line-length = 130 [lint] diff --git a/src/numtype/__init__.py b/src/numtype/__init__.py new file mode 100644 index 00000000..bf27be55 --- /dev/null +++ b/src/numtype/__init__.py @@ -0,0 +1,7 @@ +"""A superset of `numpy.typing`. Will be expanded in the future.""" + +from numpy.typing import ArrayLike, DTypeLike, NBitBase, NDArray # noqa: ICN003 + +from .version import __version__ + +__all__ = ["ArrayLike", "DTypeLike", "NBitBase", "NDArray", "__version__"] diff --git a/src/numtype/ruff.toml b/src/numtype/ruff.toml new file mode 100644 index 00000000..7f811b74 --- /dev/null +++ b/src/numtype/ruff.toml @@ -0,0 +1,2 @@ +extend = "../../pyproject.toml" +line-length = 88 diff --git a/src/numtype/version.py b/src/numtype/version.py new file mode 100644 index 00000000..6cb3ebff --- /dev/null +++ b/src/numtype/version.py @@ -0,0 +1,7 @@ +"""Module to expose more detailed version info for the installed `numtype`.""" + +import importlib.metadata +from typing import Final + +__all__ = ["__version__"] +__version__: Final = importlib.metadata.version(__package__ or __file__.split("/")[-1]) diff --git a/test/runtime/test_numtype.py b/test/runtime/test_numtype.py new file mode 100644 index 00000000..27f6d593 --- /dev/null +++ b/test/runtime/test_numtype.py @@ -0,0 +1,18 @@ +import numtype as nt +import pytest + +import numpy as np +import numpy.typing as npt + + +def test_superset() -> None: + assert set(nt.__all__) > set(npt.__all__) + + +@pytest.mark.parametrize("name", npt.__all__) +def test_reexport(name: str) -> None: + assert getattr(nt, name) is getattr(npt, name) + + +def test_version() -> None: + assert nt.__version__.startswith(np.__version__)