From 26f1361296909c126c34723ac6495974a096b780 Mon Sep 17 00:00:00 2001 From: jorenham Date: Mon, 3 Feb 2025 02:36:00 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=A7=20use=20`--project`=20instead?= =?UTF-8?q?=20of=20`--directory`=20in=20`uv=20run`,=20and=20always=20reins?= =?UTF-8?q?tall=20`numtype`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 2 +- test/main.py | 10 +++------- test/pyproject.toml | 12 +++++++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 12a993ed..7616f153 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,5 +11,5 @@ "evenBetterToml.formatter.indentString": " ", "evenBetterToml.formatter.indentTables": true, "evenBetterToml.formatter.trailingNewline": true, - "mypy-type-checker.path": ["uv", "run", "--directory=test", "static", "bmp"] + "mypy-type-checker.path": ["uv", "run", "--project=test", "static", "bmp"] } diff --git a/test/main.py b/test/main.py index 07236760..89d08699 100644 --- a/test/main.py +++ b/test/main.py @@ -23,17 +23,13 @@ def _static_bmp(args: list[str], /) -> int: return _call_static( args, "mypy", - "--explicit-package-bases", - "--hide-error-context", - "--hide-error-code-links", - "--no-pretty", - "--tb", - "--config-file=../pyproject.toml", + "--config-file", + str(PROJECT_PATH / "pyproject.toml"), ) def _static_bpr(args: list[str], /) -> int: - return _call_static(args, "basedpyright", "--project=../") + return _call_static(args, "basedpyright", "--project", str(PROJECT_PATH)) def static(args: list[str] | None = None, /) -> int: diff --git a/test/pyproject.toml b/test/pyproject.toml index 1b4a131d..7de3e2db 100644 --- a/test/pyproject.toml +++ b/test/pyproject.toml @@ -11,14 +11,20 @@ requires-python = ">=3.10" dependencies = [ "numtype", "basedmypy[faster-cache]>=2.9.1", + # "mypy[faster-cache]>=1.14.1", "basedpyright>=1.26.0", ] - [project.scripts] static = "main:static" -[tool.uv.sources] -numtype = {path = ".."} +[tool.uv] +reinstall-package = ["numtype"] + + [tool.uv.pip] + strict = true + + [tool.uv.sources] + numtype = {path = ".."} [tool.hatch.build] packages = ["."] From 64596c6d63ed2a82c92cdaffc07e5ad0376a4b3f Mon Sep 17 00:00:00 2001 From: jorenham Date: Mon, 3 Feb 2025 02:37:09 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=A6=20declare=20`src/numpy-stubs`?= =?UTF-8?q?=20as=20project=20package?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8342d030..8a61538b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,8 +26,10 @@ classifiers = [ "Typing :: Typed", ] requires-python = ">=3.10" +packages = [{include = "src/numpy-stubs" }] dependencies = [] + [project.optional-dependencies] numpy = ["numpy>=2.2.2,<2.3"] @@ -68,8 +70,14 @@ packages = ["src/numpy-stubs"] [tool.mypy] python_version = "3.10" -strict = true +mypy_path = "src" +pretty = false +show_error_context = false +show_error_code_links = false +show_traceback = false + +strict = true disable_bytearray_promotion = true disable_memoryview_promotion = true enable_error_code = ["ignore-without-code", "truthy-bool"] @@ -93,7 +101,7 @@ include = [ "tool", ] ignore = [".venv", "test/.venv"] -stubPath = "src" +stubPath = "." pythonPlatform = "All" pythonVersion = "3.10" typeCheckingMode = "standard" # TODO(jorenham): set to "all" @@ -124,7 +132,7 @@ strictGenericNarrowing = true [tool.ruff] -src = ["src", "test", "tool"] +src = ["src/numpy-stubs", "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 From 18c39e9fc565b024edc041ce097b827c629ea48b Mon Sep 17 00:00:00 2001 From: jorenham Date: Mon, 3 Feb 2025 02:40:18 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=93=9D=20document=20the=20way=20to=20?= =?UTF-8?q?run=20(based)mypy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/README.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/README.md b/test/README.md index 0e041695..88efaa62 100644 --- a/test/README.md +++ b/test/README.md @@ -1 +1,18 @@ -# numtype-test +# NumType testing + +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 + +```bash +uv run static [OPTIONS] +``` + +Here, `bmp` runs (based)`mypy`, `bpr` runs `basedpyright`, and `all` runs both. +If no options are provided, it defaults to `static/`. + +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`).