From 512b82f66daa68bde03785f7632fa2720e0ac67b Mon Sep 17 00:00:00 2001 From: KotlinIsland <65446343+kotlinisland@users.noreply.github.com> Date: Mon, 7 Apr 2025 12:16:08 +1000 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=9A=80=20add=20`dprint`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 3 +++ .vscode/extensions.json | 3 ++- dprint.json | 12 ++++++++++++ lefthook.yml | 5 +++++ pyproject.toml | 5 ++++- uv.lock | 22 +++++++++++++++++++++- 6 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 dprint.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac1a3327..958ef6c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,9 @@ jobs: uv run ruff check --output-format=github uv run ruff format --check + - name: dprint + run: uv run --no-sync dprint check + - name: pytest run: uv run pytest diff --git a/.vscode/extensions.json b/.vscode/extensions.json index f5325d68..49c1a865 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -7,7 +7,8 @@ "ms-python.python", "redhat.vscode-yaml", "seatonjiang.gitmoji-vscode", - "tamasfe.even-better-toml" + "tamasfe.even-better-toml", + "dprint.dprint" ], "unwantedRecommendations": ["ms-pyright.pyright", "ms-python.vscode-pylance"] } diff --git a/dprint.json b/dprint.json new file mode 100644 index 00000000..b4c1b0e0 --- /dev/null +++ b/dprint.json @@ -0,0 +1,12 @@ +{ + "excludes": [ + "**/*-lock.json", + "**/node_modules" + ], + "plugins": [ + "https://plugins.dprint.dev/json-0.20.0.wasm", + "https://plugins.dprint.dev/markdown-0.18.0.wasm", + "https://plugins.dprint.dev/toml-0.7.0.wasm", + "https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.0.wasm" + ] +} diff --git a/lefthook.yml b/lefthook.yml index 898fa7a1..8b312227 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -23,6 +23,11 @@ pre-commit: exclude: - "tool/test/test_format_ignores.py" + - name: dprint + glob: "*.{json,jsonc,md,toml,yaml,yml}" + stage_fixed: true + run: uv {run} dprint fmt --incremental=false + - name: basedpyright glob: "*.{py,pyi}" run: uv {run} basedpyright --threads=3 {staged_files} diff --git a/pyproject.toml b/pyproject.toml index 9414d5e4..4b5a73d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,10 @@ dependencies = [] [dependency-groups] numpy = ["numtype[numpy]"] -lint = ["ruff>=0.12.7"] +lint = [ + "dprint-py>=0.50.1.4", + "ruff>=0.12.7", +] pytest = [ {include-group = "numpy"}, "pytest>=8.4.1", diff --git a/uv.lock b/uv.lock index 6c46a0b8..1807f301 100644 --- a/uv.lock +++ b/uv.lock @@ -144,6 +144,18 @@ version = "0.9.5" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/f1/2a/8c3ac3d8bc94e6de8d7ae270bb5bc437b210bb9d6d9e46630c98f4abd20c/csscompressor-0.9.5.tar.gz", hash = "sha256:afa22badbcf3120a4f392e4d22f9fff485c044a1feda4a950ecc5eba9dd31a05", size = 237808, upload-time = "2017-11-26T21:13:08.238Z" } +[[package]] +name = "dprint-py" +version = "0.50.1.4" +source = { registry = "https://pypi.org/simple" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/02/07/357c1a997f13b9a72cb86f654e9cfc087b68856102c3d78bf2a0646f0461/dprint_py-0.50.1.4-py3-none-macosx_11_0_arm64.whl", hash = "sha256:c1bc95f56c832f38a07fd76d7bee438b6e3f64128b9d5c31eed42e2fe79e4b5a", size = 21151554, upload-time = "2025-07-31T13:04:26.013Z" }, + { url = "https://files.pythonhosted.org/packages/6c/10/25ec06220055a4d38f728bdf26f95b1f7ffc44987cf44a3fefca0911fa31/dprint_py-0.50.1.4-py3-none-macosx_11_0_x86_64.whl", hash = "sha256:02d373d8aee97bfe2b91423351fbd3b5e2efef1c30dcf469599db42725265d67", size = 22366839, upload-time = "2025-07-31T13:04:28.376Z" }, + { url = "https://files.pythonhosted.org/packages/f9/41/1bcd3f5113bd1818f07ab1889163384aa74db052b1bfe361ab1518cfc5aa/dprint_py-0.50.1.4-py3-none-manylinux_2_17_aarch64.whl", hash = "sha256:a9261c4cdcb1d88d289ded67e3c0f678ea85367464ab99c65e46baaa2c120dd5", size = 23884927, upload-time = "2025-07-31T13:04:30.742Z" }, + { url = "https://files.pythonhosted.org/packages/d7/86/ab569f5b7203156767e2cd2be60d0febef18043ca9c1d4d37b7c6429b4f7/dprint_py-0.50.1.4-py3-none-manylinux_2_17_x86_64.whl", hash = "sha256:89fd0253fd11d4f80db2c779f056065cd345199684e60fa89494b1876d5485d8", size = 24459510, upload-time = "2025-07-31T13:04:33.901Z" }, + { url = "https://files.pythonhosted.org/packages/cb/2c/d71cd39383342e0bcfb7b0330ebdc8089c300d535674a1de2ee41c29ba97/dprint_py-0.50.1.4-py3-none-win_amd64.whl", hash = "sha256:7e141c1a0d5dc9793b7029808447c5f648499729ed57e35a3d56e9d608d09610", size = 20604053, upload-time = "2025-07-31T13:04:36.821Z" }, +] + [[package]] name = "ghp-import" version = "2.1.0" @@ -630,6 +642,7 @@ basedpyright = [ ] dev = [ { name = "basedpyright" }, + { name = "dprint-py" }, { name = "markdown-callouts" }, { name = "mkdocs-awesome-nav" }, { name = "mkdocs-include-markdown-plugin" }, @@ -657,9 +670,11 @@ docs = [ { name = "pygments" }, ] lint = [ + { name = "dprint-py" }, { name = "ruff" }, ] list-and-test = [ + { name = "dprint-py" }, { name = "numtype", extra = ["numpy"] }, { name = "pytest" }, { name = "ruff" }, @@ -713,6 +728,7 @@ basedpyright = [ ] dev = [ { name = "basedpyright", specifier = ">=1.31.1" }, + { name = "dprint-py", specifier = ">=0.50.1.4" }, { name = "markdown-callouts", specifier = ">=0.4.0" }, { name = "mkdocs-awesome-nav", specifier = ">=3.1.2" }, { name = "mkdocs-include-markdown-plugin", specifier = ">=7.1.6" }, @@ -739,8 +755,12 @@ docs = [ { name = "pydantic", marker = "python_full_version >= '3.14'", specifier = ">=2.12.0a1" }, { name = "pygments", specifier = ">=2.19.2" }, ] -lint = [{ name = "ruff", specifier = ">=0.12.7" }] +lint = [ + { name = "dprint-py", specifier = ">=0.50.1.4" }, + { name = "ruff", specifier = ">=0.12.7" }, +] list-and-test = [ + { name = "dprint-py", specifier = ">=0.50.1.4" }, { name = "numtype", extras = ["numpy"] }, { name = "pytest", specifier = ">=8.4.1" }, { name = "ruff", specifier = ">=0.12.7" }, From 9e6df55bb4f2f609249f02872acfdc76bc3c73f4 Mon Sep 17 00:00:00 2001 From: jorenham Date: Wed, 6 Aug 2025 18:53:09 +0200 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=94=A7=20configure=20`dprint`=20like?= =?UTF-8?q?=20`scipy-stubs`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dprint.jsonc | 23 +++++++++++++++++++++++ dprint.json | 12 ------------ 2 files changed, 23 insertions(+), 12 deletions(-) create mode 100644 .dprint.jsonc delete mode 100644 dprint.json diff --git a/.dprint.jsonc b/.dprint.jsonc new file mode 100644 index 00000000..1e79c0a1 --- /dev/null +++ b/.dprint.jsonc @@ -0,0 +1,23 @@ +{ + "lineWidth": 88, + "json": { + "array.preferSingleLine": true, + "jsonTrailingCommaFiles": [".vscode/extensions.json", ".vscode/settings.json"], + }, + "markdown": { + "emphasisKind": "asterisks", + // "textWrap": "always", + }, + "yaml": { + "braceSpacing": false, + "formatComments": true, + "indentBlockSequenceInMap": false, + }, + "excludes": ["**/*-lock.json", "**/*.lock", "dist/", "site/"], + "plugins": [ + "https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.1.wasm", + "https://plugins.dprint.dev/json-0.20.0.wasm", + "https://plugins.dprint.dev/markdown-0.19.0.wasm", + "https://plugins.dprint.dev/toml-0.7.0.wasm", + ], +} diff --git a/dprint.json b/dprint.json deleted file mode 100644 index b4c1b0e0..00000000 --- a/dprint.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "excludes": [ - "**/*-lock.json", - "**/node_modules" - ], - "plugins": [ - "https://plugins.dprint.dev/json-0.20.0.wasm", - "https://plugins.dprint.dev/markdown-0.18.0.wasm", - "https://plugins.dprint.dev/toml-0.7.0.wasm", - "https://plugins.dprint.dev/g-plane/pretty_yaml-v0.5.0.wasm" - ] -} From 5fea4e9aa7137e7c60b9cf03269abf82c92a2f2b Mon Sep 17 00:00:00 2001 From: jorenham Date: Wed, 6 Aug 2025 19:47:06 +0200 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=96=8C=EF=B8=8F=20format=20files=20wi?= =?UTF-8?q?th=20`dprint`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: KotlinIsland <65446343+kotlinisland@users.noreply.github.com> --- .github/ISSUE_TEMPLATE/bug-report.yml | 108 +++--- .github/ISSUE_TEMPLATE/documentation.yml | 2 +- .github/dependabot.yml | 50 +-- .github/labeler.yml | 1 - .github/workflows/ci.yml | 88 ++--- .github/workflows/docs.yml | 28 +- .github/workflows/publish-pypi.yml | 18 +- .taplo.toml | 2 +- .vscode/extensions.json | 4 +- .vscode/settings.json | 21 +- CONTRIBUTING.md | 5 +- docs/.markdownlint.yaml | 8 +- docs/.nav.yml | 6 +- docs/dev/style.md | 1 - docs/index.md | 10 +- docs/reference.md | 2 +- docs/user/differences.md | 22 +- lefthook.yml | 78 ++--- mkdocs.yml | 224 ++++++------- pyproject.toml | 363 ++++++++++----------- src/_numtype/@test/.ruff.toml | 4 +- src/numpy-stubs/.ruff.toml | 8 +- src/numpy-stubs/@test/.ruff.toml | 6 +- src/numpy-stubs/@test/generated/.ruff.toml | 6 +- src/numpy-stubs/@test/runtime/.ruff.toml | 7 +- src/numpy-stubs/@test/static/.ruff.toml | 8 +- src/numtype/@test/.ruff.toml | 4 +- tool/.ruff.toml | 16 +- 28 files changed, 549 insertions(+), 551 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index 8180e9b0..50f074ca 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -4,63 +4,63 @@ title: "" labels: ["stubs: Incorrect"] body: - - type: markdown - attributes: - value: > - Thank you for taking the time to file a bug report. Before creating a new - issue, please make sure to take a few minutes to check the issue tracker - for existing issues about the bug. +- type: markdown + attributes: + value: > + Thank you for taking the time to file a bug report. Before creating a new + issue, please make sure to take a few minutes to check the issue tracker + for existing issues about the bug. - - type: textarea - attributes: - label: "Describe the issue:" - validations: - required: true +- type: textarea + attributes: + label: "Describe the issue:" + validations: + required: true - - type: textarea - attributes: - label: "Reproduce the code example:" - description: > - A short code example that reproduces the error in your type-checker. - It should be self-contained, i.e., can be run as-is via e.g. mypy myproblem.py or pyright myproblem.py. - placeholder: | - import numpy as np - << your code here >> - render: python - validations: - required: true +- type: textarea + attributes: + label: "Reproduce the code example:" + description: > + A short code example that reproduces the error in your type-checker. + It should be self-contained, i.e., can be run as-is via e.g. mypy myproblem.py or pyright myproblem.py. + placeholder: | + import numpy as np + << your code here >> + render: python + validations: + required: true - - type: textarea - attributes: - label: "Error message:" - description: > - Please include all relevant error messages from your type-checker or IDE. - placeholder: | - << Full traceback starting from `Traceback: ...` or type checker output >> - render: shell +- type: textarea + attributes: + label: "Error message:" + description: > + Please include all relevant error messages from your type-checker or IDE. + placeholder: | + << Full traceback starting from `Traceback: ...` or type checker output >> + render: shell - - type: textarea - attributes: - label: "Python and NumPy versions:" - description: > - Output from `import sys, numpy; print(numpy.__version__); print(sys.version)`. - validations: - required: true +- type: textarea + attributes: + label: "Python and NumPy versions:" + description: > + Output from `import sys, numpy; print(numpy.__version__); print(sys.version)`. + validations: + required: true - - type: textarea - attributes: - label: "Type-checker version and configuration:" - description: > - Please include the exact version of the type-checker you are using. - Popular (static) type checkers include Mypy, Pyright / Pylance, Pytype, Pyre, PyCharm, etc. - Also include the full CLI command used to run the type-checker, and all of the relevant configuration options. - validations: - required: true +- type: textarea + attributes: + label: "Type-checker version and configuration:" + description: > + Please include the exact version of the type-checker you are using. + Popular (static) type checkers include Mypy, Pyright / Pylance, Pytype, Pyre, PyCharm, etc. + Also include the full CLI command used to run the type-checker, and all of the relevant configuration options. + validations: + required: true - - type: textarea - attributes: - label: "Additional type packages:" - description: > - If you are using typing-extensions or typing-stub packages, please list their versions here. - validations: - required: false +- type: textarea + attributes: + label: "Additional type packages:" + description: > + If you are using typing-extensions or typing-stub packages, please list their versions here. + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/documentation.yml b/.github/ISSUE_TEMPLATE/documentation.yml index ccd56b37..0b6d48cf 100644 --- a/.github/ISSUE_TEMPLATE/documentation.yml +++ b/.github/ISSUE_TEMPLATE/documentation.yml @@ -5,7 +5,7 @@ labels: ["topic: Docs"] body: - type: textarea - attributes: + attributes: label: "Issue with current documentation:" description: > Please make sure to leave a reference to the document/code you're diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 15aa04a2..6de11ad5 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,28 +1,28 @@ version: 2 updates: - - package-ecosystem: github-actions - directory: "/" - schedule: - interval: daily - allow: - - dependency-type: "all" - labels: - - "topic: dependencies" - - "tool: github-actions" - commit-message: - prefix: "⬆️ " +- package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + allow: + - dependency-type: "all" + labels: + - "topic: dependencies" + - "tool: github-actions" + commit-message: + prefix: "⬆️ " - - package-ecosystem: uv - directories: - - "/" - - "/tool" - schedule: - interval: daily - allow: - - dependency-type: "all" - versioning-strategy: increase - labels: - - "topic: dependencies" - - "tool: uv" - commit-message: - prefix: "⬆️ " +- package-ecosystem: uv + directories: + - "/" + - "/tool" + schedule: + interval: daily + allow: + - dependency-type: "all" + versioning-strategy: increase + labels: + - "topic: dependencies" + - "tool: uv" + commit-message: + prefix: "⬆️ " diff --git a/.github/labeler.yml b/.github/labeler.yml index efffe81b..5dd0a1ee 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -152,4 +152,3 @@ - any-glob-to-any-file: - .taplo.toml - **/.ruff.toml - diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 958ef6c9..96d51cfd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,40 +23,40 @@ jobs: timeout-minutes: 1 steps: - - uses: actions/checkout@v4.2.2 + - uses: actions/checkout@v4.2.2 - - name: typos - uses: crate-ci/typos@v1.35.1 + - name: typos + uses: crate-ci/typos@v1.35.1 - - name: markdownlint - uses: DavidAnson/markdownlint-cli2-action@v20.0.0 - with: - config: "docs/.markdownlint.yaml" - globs: "**/*.md" + - name: markdownlint + uses: DavidAnson/markdownlint-cli2-action@v20.0.0 + with: + config: "docs/.markdownlint.yaml" + globs: "**/*.md" - - uses: uncenter/setup-taplo@v1.0.8 - with: - version: "0.9.3" - - name: taplo - run: | - taplo validate --colors never --no-schema - taplo fmt --colors never --check + - uses: uncenter/setup-taplo@v1.0.8 + with: + version: "0.9.3" + - name: taplo + run: | + taplo validate --colors never --no-schema + taplo fmt --colors never --check - - uses: astral-sh/setup-uv@v6.4.3 + - uses: astral-sh/setup-uv@v6.4.3 - - name: ruff - run: | - uv run ruff check --output-format=github - uv run ruff format --check + - name: ruff + run: | + uv run ruff check --output-format=github + uv run ruff format --check - - name: dprint - run: uv run --no-sync dprint check + - name: dprint + run: uv run --no-sync dprint check - - name: pytest - run: uv run pytest + - name: pytest + run: uv run pytest - - name: format-ignores - run: uv run tool/format_ignores.py --check + - name: format-ignores + run: uv run tool/format_ignores.py --check # NOTE: Static typing only differs between `python<3.12` and otherwise, # so there's no need to run the type-checkers on all Python versions. @@ -69,14 +69,14 @@ jobs: matrix: py: ["3.11", "3.13"] steps: - - uses: actions/checkout@v4.2.2 + - uses: actions/checkout@v4.2.2 - - uses: astral-sh/setup-uv@v6.4.3 - with: - python-version: ${{ matrix.py }} + - uses: astral-sh/setup-uv@v6.4.3 + with: + python-version: ${{ matrix.py }} - - name: basedpyright - run: uv run basedpyright + - name: basedpyright + run: uv run basedpyright mypy: runs-on: ubuntu-latest @@ -86,14 +86,14 @@ jobs: matrix: py: ["3.11", "3.13"] steps: - - uses: actions/checkout@v4.2.2 + - uses: actions/checkout@v4.2.2 - - uses: astral-sh/setup-uv@v6.4.3 - with: - python-version: ${{ matrix.py }} + - uses: astral-sh/setup-uv@v6.4.3 + with: + python-version: ${{ matrix.py }} - - name: mypy - run: uv run --no-editable mypy --no-incremental --cache-dir=/dev/null . + - name: mypy + run: uv run --no-editable mypy --no-incremental --cache-dir=/dev/null . # NOTE: Stubtest does runtime inspections, so we consider all Python versions. @@ -106,11 +106,11 @@ jobs: os: [ubuntu-latest, macos-latest, windows-latest] py: ["3.11", "3.12", "3.13", "3.14"] steps: - - uses: actions/checkout@v4.2.2 + - uses: actions/checkout@v4.2.2 - - uses: astral-sh/setup-uv@v6.4.3 - with: - python-version: ${{ matrix.py }} + - uses: astral-sh/setup-uv@v6.4.3 + with: + python-version: ${{ matrix.py }} - - name: stubtest - run: uv run --active tool/stubtest.py + - name: stubtest + run: uv run --active tool/stubtest.py diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 3a213d00..cdbb766d 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -4,11 +4,11 @@ on: push: branches: [main] paths: - - "docs/**" - - ".github/workflows/docs.yml" - - "CONTRIBUTING.md" - - "mkdocs.yml" - - "uv.lock" + - "docs/**" + - ".github/workflows/docs.yml" + - "CONTRIBUTING.md" + - "mkdocs.yml" + - "uv.lock" permissions: contents: write @@ -20,16 +20,14 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Configure Git Credentials - run: | - git config user.name github-actions[bot] - git config user.email 41898282+github-actions[bot]@users.noreply.github.com + - name: Configure Git Credentials + run: | + git config user.name github-actions[bot] + git config user.email 41898282+github-actions[bot]@users.noreply.github.com - - uses: astral-sh/setup-uv@v6 - with: - enable-cache: true + - uses: astral-sh/setup-uv@v6 - - name: mkdocs gh-deploy - run: uv run --only-group=docs mkdocs gh-deploy --force + - name: mkdocs gh-deploy + run: uv run --only-group=docs mkdocs gh-deploy --force diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index aa226369..b90c9ae3 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -16,12 +16,12 @@ jobs: permissions: id-token: write steps: - - uses: actions/checkout@v4 - - name: setup uv - uses: astral-sh/setup-uv@v6 - with: - python-version: "3.13" - - name: uv build - run: uv build - - name: publish to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 + - uses: actions/checkout@v4 + - name: setup uv + uses: astral-sh/setup-uv@v6 + with: + python-version: "3.13" + - name: uv build + run: uv build + - name: publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.taplo.toml b/.taplo.toml index 26ca2799..b721b65e 100644 --- a/.taplo.toml +++ b/.taplo.toml @@ -13,7 +13,7 @@ column_width = 88 compact_arrays = true compact_inline_tables = true crlf = false -indent_string = " " # 4 spaces +indent_string = " " # 4 spaces indent_tables = true reorder_keys = false reorder_arrays = false diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 49c1a865..c158c57f 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -8,7 +8,7 @@ "redhat.vscode-yaml", "seatonjiang.gitmoji-vscode", "tamasfe.even-better-toml", - "dprint.dprint" + "dprint.dprint", ], - "unwantedRecommendations": ["ms-pyright.pyright", "ms-python.vscode-pylance"] + "unwantedRecommendations": ["ms-pyright.pyright", "ms-python.vscode-pylance"], } diff --git a/.vscode/settings.json b/.vscode/settings.json index 77d6b174..dd588a7c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,30 +1,19 @@ { "[markdown]": { - "editor.rulers": [ - 120 - ] + "editor.rulers": [88], }, "[python]": { - "editor.rulers": [ - 88, - 120 - ] + "editor.rulers": [88, 120], }, "[toml]": { - "editor.rulers": [88] + "editor.rulers": [88], }, "evenBetterToml.schema.enabled": false, "evenBetterToml.taplo.configFile.path": ".taplo.toml", "files.readonlyInclude": { - "**/generated/*.pyi": true + "**/generated/*.pyi": true, }, "git.branchProtection": ["main"], "markdownlint.configFile": "docs/.markdownlint.yaml", - "mypy-type-checker.path": [ - "uv", - "run", - "--no-editable", - "--no-sync", - "mypy" - ] + "mypy-type-checker.path": ["uv", "run", "--no-editable", "--no-sync", "mypy"], } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8e5e2385..26501799 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,10 +6,11 @@ grow. Pull requests (PRs) are always welcome, but making a PR is just the start. Please respond to comments and requests for changes to help move -the process forward. Please follow our [Code of -Conduct](https://numpy.org/code-of-conduct/), which applies to all +the process forward. Please follow our [Code of Conduct][COC], which applies to all interactions, including issues and PRs. For more, please read Thank you for contributing, and happy coding! + +[COC]: https://numpy.org/code-of-conduct/ diff --git a/docs/.markdownlint.yaml b/docs/.markdownlint.yaml index 247b798b..785f592e 100644 --- a/docs/.markdownlint.yaml +++ b/docs/.markdownlint.yaml @@ -9,9 +9,9 @@ MD031: list_items: false MD033: allowed_elements: - - h1 - - img - - a - - div + - h1 + - img + - a + - div MD036: false MD041: false diff --git a/docs/.nav.yml b/docs/.nav.yml index 21e3d486..4736e312 100644 --- a/docs/.nav.yml +++ b/docs/.nav.yml @@ -1,6 +1,6 @@ flatten_single_child_sections: true nav: - - User Guide: user - - API Reference: reference.md - - Development: dev +- User Guide: user +- API Reference: reference.md +- Development: dev diff --git a/docs/dev/style.md b/docs/dev/style.md index 145d5c7b..2063db96 100644 --- a/docs/dev/style.md +++ b/docs/dev/style.md @@ -1,4 +1,3 @@ - # Style Guide ## `TypeVar` names diff --git a/docs/index.md b/docs/index.md index aee245c0..bbbd02da 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,7 +1,7 @@ --- hide: - - navigation - - toc +- navigation +- toc --- # NumType documentation @@ -13,9 +13,10 @@ routines for fast operations on arrays, including mathematical, logical, shape manipulation, sorting, selecting, I/O, discrete Fourier transforms, basic linear algebra, basic statistical operations, random simulation and much more. +
-- :material-book-open-variant:{ .lg .middle }   __User guide__ +- :material-book-open-variant:{ .lg .middle }   **User guide** --- @@ -24,7 +25,7 @@ algebra, basic statistical operations, random simulation and much more. [:octicons-arrow-right-24: To the user guide](user/index.md) -- :material-code-brackets:{ .lg .middle }   __API reference__ +- :material-code-brackets:{ .lg .middle }   **API reference** --- @@ -43,3 +44,4 @@ algebra, basic statistical operations, random simulation and much more. [:octicons-arrow-right-24: To the contributor's guide](dev/index.md)
+ diff --git a/docs/reference.md b/docs/reference.md index e318aaa2..f86f0035 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -1,6 +1,6 @@ --- hide: - - navigation +- navigation --- # NumType reference diff --git a/docs/user/differences.md b/docs/user/differences.md index 786c3d6f..7079d9c3 100644 --- a/docs/user/differences.md +++ b/docs/user/differences.md @@ -56,10 +56,14 @@ NT = TypeVar("NT", bound=npt.NBitBase) def f(x: np.floating[NT]) -> np.floating[NT]: ... ``` + + /// /// tab | Python 3.12 and above select: True + + ```py import numpy as np import numpy.typing as npt @@ -67,12 +71,16 @@ import numpy.typing as npt def f[NT: npt.NBitBase](x: np.floating[NT]) -> np.floating[NT]: ... ``` + + /// you can write /// tab | Python 3.11 and above + + ```py import numpy as np from typing import TypeVar @@ -82,16 +90,22 @@ FloatT = TypeVar("FloatT", bound=np.floating) def f(x: FloatT) -> FloatT: ... ``` + + /// /// tab | Python 3.12 and above select: True + + ```py import numpy as np def f[FloatT: np.floating](x: FloatT) -> FloatT: ... ``` + + /// As you can see, this also makes the code more readable. @@ -100,6 +114,8 @@ But what if that isn't possible? For instance, you might have the following func /// tab | Python 3.11 and above + + ```py import numpy as np import numpy.typing as npt @@ -110,6 +126,8 @@ NT = TypeVar("NT", bound=npt.NBitBase) def f(x: np.complexfloating[NT]) -> np.floating[NT]: ... ``` + + /// /// tab | Python 3.12 and above select: True @@ -123,6 +141,8 @@ def f[NT: npt.NBitBase](x: np.complexfloating[NT]) -> np.floating[NT]: ... /// + + In that case, you can rewrite it by using [`#!py typing.overload`](https://typing.python.org/en/latest/spec/overload.html): @@ -178,7 +198,7 @@ In NumType, the stubs correctly reflect this runtime behaviour. ## Removed `number.__floordiv__` The abstract `numpy.number` type represents a scalar that's either integer, float, or complex. -But the builtin "floordiv" operator, `//` is only supported for integer and floating scalars. +But the builtin "floordiv" operator, `//` is only supported for integer and floating scalars. Complex numpy scalars will raise an error. But in NumPy, type-checkers will allow you to write the following type-unsafe code: diff --git a/lefthook.yml b/lefthook.yml index 8b312227..757a30f1 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -4,49 +4,49 @@ templates: pre-commit: parallel: true jobs: - - name: ruff - glob: "*.{py,pyi}" - stage_fixed: true - group: - piped: true - jobs: - - name: check - run: uv {run} ruff check --fix {staged_files} - - - name: format - run: uv {run} ruff format {staged_files} - - - name: format_ignores - glob: "*.{py,pyi}" - stage_fixed: true - run: uv {run} tool/format_ignores.py {staged_files} - exclude: - - "tool/test/test_format_ignores.py" - - - name: dprint - glob: "*.{json,jsonc,md,toml,yaml,yml}" - stage_fixed: true - run: uv {run} dprint fmt --incremental=false - - - name: basedpyright - glob: "*.{py,pyi}" - run: uv {run} basedpyright --threads=3 {staged_files} - - - name: mkdocs - glob: - - "docs/**" - - "CONTRIBUTING.md" - - "mkdocs.yml" - - "uv.lock" - run: uv {run} mkdocs build + - name: ruff + glob: "*.{py,pyi}" + stage_fixed: true + group: + piped: true + jobs: + - name: check + run: uv {run} ruff check --fix {staged_files} + + - name: format + run: uv {run} ruff format {staged_files} + + - name: format_ignores + glob: "*.{py,pyi}" + stage_fixed: true + run: uv {run} tool/format_ignores.py {staged_files} + exclude: + - "tool/test/test_format_ignores.py" + + - name: dprint + glob: "*.{json,jsonc,md,toml,yaml,yml}" + stage_fixed: true + run: uv {run} dprint fmt --incremental=false + + - name: basedpyright + glob: "*.{py,pyi}" + run: uv {run} basedpyright --threads=3 {staged_files} + + - name: mkdocs + glob: + - "docs/**" + - "CONTRIBUTING.md" + - "mkdocs.yml" + - "uv.lock" + run: uv {run} mkdocs build post-checkout: jobs: - - run: uv sync - glob: uv.lock + - run: uv sync + glob: uv.lock post-merge: files: "git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD" jobs: - - run: uv sync - glob: uv.lock + - run: uv sync + glob: uv.lock diff --git a/mkdocs.yml b/mkdocs.yml index 3f0055c2..57fa58c8 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -12,87 +12,87 @@ repo_name: numpy/numtype edit_uri: blob/main/docs/ plugins: - # https://github.com/mkdocstrings/autorefs - - autorefs: - resolve_closest: true - - # https://lukasgeiter.github.io/mkdocs-awesome-nav/ - - awesome-nav: - filename: .nav.yml - - # https://github.com/mondeja/mkdocs-include-markdown-plugin - - include-markdown: - - # https://github.com/byrnereese/mkdocs-minify-plugin - - minify: - minify_html: true - enabled: !ENV [CI, false] - - # https://github.com/mkdocstrings/mkdocstrings - # https://github.com/mkdocstrings/python - - mkdocstrings: - handlers: - python: - inventories: - - url: https://docs.python.org/3/objects.inv - - url: https://numpy.org/doc/stable/objects.inv - - url: https://docs.scipy.org/doc/scipy/objects.inv - options: - docstring_section_style: list - members_order: source - show_root_heading: true - show_source: false - show_signature_annotations: true - - # https://squidfunk.github.io/mkdocs-material/plugins/privacy/ - - privacy: - enabled: !ENV [CI, false] - - # https://squidfunk.github.io/mkdocs-material/plugins/search/ - - search +# https://github.com/mkdocstrings/autorefs +- autorefs: + resolve_closest: true + +# https://lukasgeiter.github.io/mkdocs-awesome-nav/ +- awesome-nav: + filename: .nav.yml + +# https://github.com/mondeja/mkdocs-include-markdown-plugin +- include-markdown: + +# https://github.com/byrnereese/mkdocs-minify-plugin +- minify: + minify_html: true + enabled: !ENV [CI, false] + +# https://github.com/mkdocstrings/mkdocstrings +# https://github.com/mkdocstrings/python +- mkdocstrings: + handlers: + python: + inventories: + - url: https://docs.python.org/3/objects.inv + - url: https://numpy.org/doc/stable/objects.inv + - url: https://docs.scipy.org/doc/scipy/objects.inv + options: + docstring_section_style: list + members_order: source + show_root_heading: true + show_source: false + show_signature_annotations: true + +# https://squidfunk.github.io/mkdocs-material/plugins/privacy/ +- privacy: + enabled: !ENV [CI, false] + +# https://squidfunk.github.io/mkdocs-material/plugins/search/ +- search markdown_extensions: - # https://squidfunk.github.io/mkdocs-material/setup/extensions/python-markdown/ - - abbr - - attr_list - - def_list - - footnotes - - md_in_html - - toc: - permalink: "#" - - # https://github.com/oprypin/markdown-callouts - - callouts - - # https://facelessuser.github.io/pymdown-extensions/extensions/betterem/ - - pymdownx.betterem: - smart_enable: asterisk - - - pymdownx.blocks.tab: - alternate_style: true - - # https://facelessuser.github.io/pymdown-extensions/extensions/emoji/ - - pymdownx.emoji: - emoji_index: !!python/name:material.extensions.emoji.twemoji - emoji_generator: !!python/name:material.extensions.emoji.to_svg - - # https://facelessuser.github.io/pymdown-extensions/extensions/highlight/ - - pymdownx.highlight: - anchor_linenums: true - use_pygments: true - - pymdownx.inlinehilite - - pymdownx.superfences - - # https://facelessuser.github.io/pymdown-extensions/extensions/magiclink/ - - pymdownx.magiclink: - repo_url_shortener: true - repo_url_shorthand: true - provider: github - user: numpy - repo: numtype - - # https://facelessuser.github.io/pymdown-extensions/extensions/saneheaders/ - - pymdownx.saneheaders: +# https://squidfunk.github.io/mkdocs-material/setup/extensions/python-markdown/ +- abbr +- attr_list +- def_list +- footnotes +- md_in_html +- toc: + permalink: "#" + +# https://github.com/oprypin/markdown-callouts +- callouts + +# https://facelessuser.github.io/pymdown-extensions/extensions/betterem/ +- pymdownx.betterem: + smart_enable: asterisk + +- pymdownx.blocks.tab: + alternate_style: true + +# https://facelessuser.github.io/pymdown-extensions/extensions/emoji/ +- pymdownx.emoji: + emoji_index: !!python/name:material.extensions.emoji.twemoji + emoji_generator: !!python/name:material.extensions.emoji.to_svg + +# https://facelessuser.github.io/pymdown-extensions/extensions/highlight/ +- pymdownx.highlight: + anchor_linenums: true + use_pygments: true +- pymdownx.inlinehilite +- pymdownx.superfences + +# https://facelessuser.github.io/pymdown-extensions/extensions/magiclink/ +- pymdownx.magiclink: + repo_url_shortener: true + repo_url_shorthand: true + provider: github + user: numpy + repo: numtype + +# https://facelessuser.github.io/pymdown-extensions/extensions/saneheaders/ +- pymdownx.saneheaders: theme: name: material @@ -101,42 +101,42 @@ theme: logo: theme/img/icon.svg features: - - content.tabs.link - - content.tooltips - - navigation.path - - navigation.indexes - - navigation.prune - - navigation.sections - - navigation.tabs - - navigation.top - - navigation.tracking - - search.highlight - - search.share - - search.suggest - - toc.follow + - content.tabs.link + - content.tooltips + - navigation.path + - navigation.indexes + - navigation.prune + - navigation.sections + - navigation.tabs + - navigation.top + - navigation.tracking + - search.highlight + - search.share + - search.suggest + - toc.follow palette: - - media: "(prefers-color-scheme)" - toggle: - icon: fontawesome/solid/circle-half-stroke - name: Switch to light mode - - media: "(prefers-color-scheme: light)" - scheme: default - primary: custom - toggle: - icon: fontawesome/regular/moon - name: Switch to dark mode - - media: "(prefers-color-scheme: dark)" - scheme: slate - primary: custom - toggle: - icon: fontawesome/regular/sun - name: Switch to system preference + - media: "(prefers-color-scheme)" + toggle: + icon: fontawesome/solid/circle-half-stroke + name: Switch to light mode + - media: "(prefers-color-scheme: light)" + scheme: default + primary: custom + toggle: + icon: fontawesome/regular/moon + name: Switch to dark mode + - media: "(prefers-color-scheme: dark)" + scheme: slate + primary: custom + toggle: + icon: fontawesome/regular/sun + name: Switch to system preference extra_css: - - theme/style/color.css - - theme/style/font.css - - theme/style/overrides.css - - theme/style/theme.css +- theme/style/color.css +- theme/style/font.css +- theme/style/overrides.css +- theme/style/theme.css copyright: "© Copyright 2025, NumPy Developers." diff --git a/pyproject.toml b/pyproject.toml index 4b5a73d1..9f87b23a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,112 +2,108 @@ requires = ["hatchling"] build-backend = "hatchling.build" - [project] name = "numtype" version = "2.3.2.0.dev0" description = "Experimental Typing Stubs for NumPy" readme = "README.md" -authors = [{name = "Joren Hammudoglu", email = "jhammudoglu@gmail.com"}] -maintainers = [{name = "NumPy Developers", email = "numpy-discussion@python.org"}] +authors = [{ name = "Joren Hammudoglu", email = "jhammudoglu@gmail.com" }] +maintainers = [{ name = "NumPy Developers", email = "numpy-discussion@python.org" }] license = "BSD-3-Clause" keywords = ["numpy", "typing", "stubs"] classifiers = [ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.13", - "Programming Language :: Python :: 3.14", - "Typing :: Stubs Only", - "Typing :: Typed", + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", + "Typing :: Stubs Only", + "Typing :: Typed", ] packages = [ - {include = "src/_numtype"}, - {include = "src/numpy-stubs"}, - {include = "src/numtype"}, + { include = "src/_numtype" }, + { include = "src/numpy-stubs" }, + { include = "src/numtype" }, ] requires-python = ">=3.11" dependencies = [] - [project.optional-dependencies] - numpy = ["numpy>=2.3.2,<2.4"] - - [project.urls] - Homepage = "https://numpy.org/" - Repository = "https://github.com/numpy/numtype/" - Issues = "https://github.com/numpy/numtype/issues" - Changelog = "https://github.com/numpy/numtype/releases" +[project.optional-dependencies] +numpy = ["numpy>=2.3.2,<2.4"] +[project.urls] +Homepage = "https://numpy.org/" +Repository = "https://github.com/numpy/numtype/" +Issues = "https://github.com/numpy/numtype/issues" +Changelog = "https://github.com/numpy/numtype/releases" [dependency-groups] numpy = ["numtype[numpy]"] lint = [ - "dprint-py>=0.50.1.4", - "ruff>=0.12.7", + "dprint-py>=0.50.1.4", + "ruff>=0.12.7", ] pytest = [ - {include-group = "numpy"}, - "pytest>=8.4.1", - "typing_extensions>=4.14.1", + { include-group = "numpy" }, + "pytest>=8.4.1", + "typing_extensions>=4.14.1", ] list_and_test = [ - {include-group = "lint"}, - {include-group = "pytest"}, + { include-group = "lint" }, + { include-group = "pytest" }, ] types = [ - {include-group = "pytest"}, - "types-setuptools>=80.9.0.20250801", - "types-tabulate>=0.9.0.20241207", + { include-group = "pytest" }, + "types-setuptools>=80.9.0.20250801", + "types-tabulate>=0.9.0.20241207", ] basedpyright = [ - {include-group = "numpy"}, - {include-group = "types"}, - "basedpyright>=1.31.1", + { include-group = "numpy" }, + { include-group = "types" }, + "basedpyright>=1.31.1", ] mypy = [ - {include-group = "types"}, - "mypy[faster-cache]>=1.17.1", + { include-group = "types" }, + "mypy[faster-cache]>=1.17.1", ] typecheck = [ - {include-group = "basedpyright"}, - {include-group = "mypy"}, + { include-group = "basedpyright" }, + { include-group = "mypy" }, ] docs = [ - "mkdocs-material>=9.6.16", - "pydantic>=2.12.0a1; python_version >= '3.14'", # needed for mkdocs-awesome-nav - "mkdocs-awesome-nav>=3.1.2", - "markdown-callouts>=0.4.0", - "mkdocs-include-markdown-plugin>=7.1.6", - "mkdocs-minify-plugin>=0.8.0", - "mkdocstrings[python]>=0.30.0", - "pygments>=2.19.2", + "mkdocs-material>=9.6.16", + "pydantic>=2.12.0a1; python_version >= '3.14'", # needed for mkdocs-awesome-nav + "mkdocs-awesome-nav>=3.1.2", + "markdown-callouts>=0.4.0", + "mkdocs-include-markdown-plugin>=7.1.6", + "mkdocs-minify-plugin>=0.8.0", + "mkdocstrings[python]>=0.30.0", + "pygments>=2.19.2", ] dev = [ - {include-group = "list_and_test"}, - {include-group = "typecheck"}, - {include-group = "docs"}, + { include-group = "list_and_test" }, + { include-group = "typecheck" }, + { include-group = "docs" }, ] - [tool.hatch.build] exclude = [ - "**/@test", - "**/*.yml", - "**/.*", - "/docs", - "/tool", - "CONTRIBUTING.md", - "uv.lock", + "**/@test", + "**/*.yml", + "**/.*", + "/docs", + "/tool", + "CONTRIBUTING.md", + "uv.lock", ] skip-excluded-dirs = true - [tool.hatch.build.targets.wheel] - packages = ["src/_numtype", "src/numtype", "src/numpy-stubs"] - +[tool.hatch.build.targets.wheel] +packages = ["src/_numtype", "src/numtype", "src/numpy-stubs"] [tool.mypy] mypy_path = "src" @@ -119,21 +115,20 @@ local_partial_types = true warn_incomplete_stub = true warn_unreachable = false - [tool.pyright] include = ["src", "tool"] ignore = [".venv"] exclude = [ - ".cache", - ".git", - ".github", - ".mypy_cache", - ".pytest_cache", - ".ruff_cache", - ".tox", - ".vscode", - "docs", - "site", + ".cache", + ".git", + ".github", + ".mypy_cache", + ".pytest_cache", + ".ruff_cache", + ".tox", + ".vscode", + "docs", + "site", ] stubPath = "src" pythonPlatform = "All" @@ -146,12 +141,12 @@ enableReachabilityAnalysis = false reportCallInDefaultInitializer = true reportImportCycles = true reportImplicitOverride = true -reportInvalidStubStatement = false # required for type-testing +reportInvalidStubStatement = false # required for type-testing reportMissingSuperCall = false reportPrivateUsage = false reportPropertyTypeMismatch = false reportSelfClsParameterName = false -reportShadowedImports = false # causes a ~35% slowdown +reportShadowedImports = false # causes a ~35% slowdown reportUninitializedInstanceVariable = true reportUnnecessaryTypeIgnoreComment = true reportUnusedExpression = false @@ -170,7 +165,6 @@ reportPrivateLocalImportUsage = true reportUnannotatedClassAttribute = false strictGenericNarrowing = true - [tool.ruff] src = ["src", "tool"] extend-exclude = [".git", ".mypy_cache", ".tox", ".venv"] @@ -178,58 +172,57 @@ force-exclude = true line-length = 120 preview = true - [tool.ruff.format] - line-ending = "lf" - skip-magic-trailing-comma = true - - [tool.ruff.lint] - select = ["ALL"] - ignore = ["CPY", "FIX002", "COM812"] - - [tool.ruff.lint.per-file-ignores] - "*.pyi" = [ - "N", # pep8-naming - "TD", # flake8-todo - "COM812", # flake8-commas: missing-trailing-comma - "PLC2701", # pylint/C: import-private-name - ] - - [tool.ruff.lint.flake8-builtins] - builtins-allowed-modules = ["random"] - - [tool.ruff.lint.flake8-import-conventions] - banned-from = [ - "abc", - "basedtyping", - "ctypes", - "datetime", - "os", - "sys", - "numpy", - "numpy.typing", - "_numtype", - ] - [tool.ruff.lint.flake8-import-conventions.extend-aliases] - "ctypes" = "ct" - "datetime" = "dt" - "numpy" = "np" - "numpy.typing" = "npt" - "numtype" = "nt" - "_numtype" = "_nt" - - [tool.ruff.lint.isort] - case-sensitive = true - combine-as-imports = true - extra-standard-library = ["_typeshed", "typing_extensions"] - known-first-party = ["numpy", "numtype", "_numtype"] - split-on-trailing-comma = false +[tool.ruff.format] +line-ending = "lf" +skip-magic-trailing-comma = true - [tool.ruff.lint.pydocstyle] - convention = "numpy" +[tool.ruff.lint] +select = ["ALL"] +ignore = ["CPY", "FIX002", "COM812"] - [tool.ruff.lint.pylint] - allow-dunder-method-names = ["__array__", "__array_ufunc__"] +[tool.ruff.lint.per-file-ignores] +"*.pyi" = [ + "N", # pep8-naming + "TD", # flake8-todo + "COM812", # flake8-commas: missing-trailing-comma + "PLC2701", # pylint/C: import-private-name +] +[tool.ruff.lint.flake8-builtins] +builtins-allowed-modules = ["random"] + +[tool.ruff.lint.flake8-import-conventions] +banned-from = [ + "abc", + "basedtyping", + "ctypes", + "datetime", + "os", + "sys", + "numpy", + "numpy.typing", + "_numtype", +] +[tool.ruff.lint.flake8-import-conventions.extend-aliases] +"ctypes" = "ct" +"datetime" = "dt" +"numpy" = "np" +"numpy.typing" = "npt" +"numtype" = "nt" +"_numtype" = "_nt" + +[tool.ruff.lint.isort] +case-sensitive = true +combine-as-imports = true +extra-standard-library = ["_typeshed", "typing_extensions"] +known-first-party = ["numpy", "numtype", "_numtype"] +split-on-trailing-comma = false + +[tool.ruff.lint.pydocstyle] +convention = "numpy" + +[tool.ruff.lint.pylint] +allow-dunder-method-names = ["__array__", "__array_ufunc__"] [tool.pytest.ini_options] minversion = "8.0" @@ -238,76 +231,74 @@ filterwarnings = ["error"] log_cli_level = "INFO" xfail_strict = true - # install tox with `uv tool install tox --with tox-uv --upgrade` # and run with `uvx tox p` [tool.tox] min_version = "4" requires = ["tox-uv>=1"] env_list = [ - "ruff", - "pytest", - "basedpyright", - "mypy", - "3.11", - "3.12", - "3.13", - "3.14", + "ruff", + "pytest", + "basedpyright", + "mypy", + "3.11", + "3.12", + "3.13", + "3.14", ] - [tool.tox.env_run_base] - description = "stubtest ({base_python})" - commands = [ - [ - "uv", - "run", - "-q", - "-p={base_python}", - "--active", - "tool/stubtest.py", - "--concise", - ], - ] - - [tool.tox.env.ruff] - description = "ruff" - runner = "uv-venv-lock-runner" - dependency_groups = ["dev"] - commands = [ - ["ruff", "check", "--show-fixes"], - ["ruff", "format", "--check"], - ] - - [tool.tox.env.pytest] - description = "pytest" - runner = "uv-venv-lock-runner" - dependency_groups = ["dev", "numpy"] - commands = [["pytest"]] - - [tool.tox.env.basedpyright] - description = "basedpyright" - runner = "uv-venv-lock-runner" - dependency_groups = ["dev"] - commands = [["basedpyright", {replace = "posargs", default = [], extend = true}]] +[tool.tox.env_run_base] +description = "stubtest ({base_python})" +commands = [ + [ + "uv", + "run", + "-q", + "-p={base_python}", + "--active", + "tool/stubtest.py", + "--concise", + ], +] - [tool.tox.env.mypy] - description = "mypy" - runner = "uv-venv-lock-runner" - dependency_groups = ["dev", "types"] - commands = [ - [ - "mypy", - "--no-incremental", - "--cache-dir=/dev/null", - {replace = "posargs", default = ["."], extend = true}, - ], - ] +[tool.tox.env.ruff] +description = "ruff" +runner = "uv-venv-lock-runner" +dependency_groups = ["dev"] +commands = [ + ["ruff", "check", "--show-fixes"], + ["ruff", "format", "--check"], +] +[tool.tox.env.pytest] +description = "pytest" +runner = "uv-venv-lock-runner" +dependency_groups = ["dev", "numpy"] +commands = [["pytest"]] + +[tool.tox.env.basedpyright] +description = "basedpyright" +runner = "uv-venv-lock-runner" +dependency_groups = ["dev"] +commands = [["basedpyright", { replace = "posargs", default = [], extend = true }]] + +[tool.tox.env.mypy] +description = "mypy" +runner = "uv-venv-lock-runner" +dependency_groups = ["dev", "types"] +commands = [ + [ + "mypy", + "--no-incremental", + "--cache-dir=/dev/null", + { replace = "posargs", default = ["."], extend = true }, + ], +] [tool.typos] - [tool.typos.default] - extend-ignore-identifiers-re = ['ND|nd|nin|NIN|TYP'] +[tool.typos.default] +extend-ignore-identifiers-re = ['ND|nd|nin|NIN|TYP'] - [tool.typos.files] - extend-exclude = ["*.pyi", ".mypyignore"] +[tool.typos.files] +extend-exclude = ["*.pyi", ".mypyignore"] diff --git a/src/_numtype/@test/.ruff.toml b/src/_numtype/@test/.ruff.toml index a54cb369..7e0016ae 100644 --- a/src/_numtype/@test/.ruff.toml +++ b/src/_numtype/@test/.ruff.toml @@ -2,6 +2,6 @@ extend = "../.ruff.toml" [lint] extend-ignore = [ - "PYI015", # flake8-pyi: assignment-default-in-stub - "PYI017", # flake8-pyi: complex-assignment-in-stub + "PYI015", # flake8-pyi: assignment-default-in-stub + "PYI017", # flake8-pyi: complex-assignment-in-stub ] diff --git a/src/numpy-stubs/.ruff.toml b/src/numpy-stubs/.ruff.toml index 5fe450f9..9b35118f 100644 --- a/src/numpy-stubs/.ruff.toml +++ b/src/numpy-stubs/.ruff.toml @@ -3,8 +3,8 @@ line-length = 120 [lint] extend-ignore = [ - "A", # flake8-builtins - "ANN401", # flake8-annotations: any-type - "SLF001", # flake8-self: private-member-access - "PLR2044", # pylint/R: empty-comment + "A", # flake8-builtins + "ANN401", # flake8-annotations: any-type + "SLF001", # flake8-self: private-member-access + "PLR2044", # pylint/R: empty-comment ] diff --git a/src/numpy-stubs/@test/.ruff.toml b/src/numpy-stubs/@test/.ruff.toml index 7c97cb0d..0285bcd7 100644 --- a/src/numpy-stubs/@test/.ruff.toml +++ b/src/numpy-stubs/@test/.ruff.toml @@ -3,7 +3,7 @@ line-length = 88 [lint] extend-ignore = [ - "D", # pydocstyle - "FBT", # flake8-boolean-trap - "PYI054", # flake8-pyi: numeric-literal-too-long + "D", # pydocstyle + "FBT", # flake8-boolean-trap + "PYI054", # flake8-pyi: numeric-literal-too-long ] diff --git a/src/numpy-stubs/@test/generated/.ruff.toml b/src/numpy-stubs/@test/generated/.ruff.toml index 0f5f526b..763a41f8 100644 --- a/src/numpy-stubs/@test/generated/.ruff.toml +++ b/src/numpy-stubs/@test/generated/.ruff.toml @@ -3,7 +3,7 @@ line-length = 120 [lint] extend-ignore = [ - "B018", # flake8-bugbear useless-expression - "PLR0124", # pylint/R: comparison-with-itself - "PLC2801", # pylint/C: unnecessary-dunder-call + "B018", # flake8-bugbear useless-expression + "PLR0124", # pylint/R: comparison-with-itself + "PLC2801", # pylint/C: unnecessary-dunder-call ] diff --git a/src/numpy-stubs/@test/runtime/.ruff.toml b/src/numpy-stubs/@test/runtime/.ruff.toml index 8b6c63e6..0ab1673a 100644 --- a/src/numpy-stubs/@test/runtime/.ruff.toml +++ b/src/numpy-stubs/@test/runtime/.ruff.toml @@ -1,9 +1,8 @@ extend = "../.ruff.toml" - [lint] extend-ignore = [ - "ARG", # flake8-unused-arguments - "B015", # flake8-bugbear: useless-comparison - "B018", # flake8-bugbear: useless-expression + "ARG", # flake8-unused-arguments + "B015", # flake8-bugbear: useless-comparison + "B018", # flake8-bugbear: useless-expression ] diff --git a/src/numpy-stubs/@test/static/.ruff.toml b/src/numpy-stubs/@test/static/.ruff.toml index ad4d6982..8858a31a 100644 --- a/src/numpy-stubs/@test/static/.ruff.toml +++ b/src/numpy-stubs/@test/static/.ruff.toml @@ -3,8 +3,8 @@ line-length = 120 [lint] extend-ignore = [ - "PYI015", # flake8-pyi: assignment-default-in-stub - "PYI017", # flake8-pyi: complex-assignment-in-stub - "SLF001", # flake8-self: private-member-access - "PTH123", # flake8-use-pathlib: builtin-open + "PYI015", # flake8-pyi: assignment-default-in-stub + "PYI017", # flake8-pyi: complex-assignment-in-stub + "SLF001", # flake8-self: private-member-access + "PTH123", # flake8-use-pathlib: builtin-open ] diff --git a/src/numtype/@test/.ruff.toml b/src/numtype/@test/.ruff.toml index 61059cb8..899b75e0 100644 --- a/src/numtype/@test/.ruff.toml +++ b/src/numtype/@test/.ruff.toml @@ -2,6 +2,6 @@ extend = "../.ruff.toml" [lint] extend-ignore = [ - "D", # pydocstyle - "S101", # flake8-bandit: assert + "D", # pydocstyle + "S101", # flake8-bandit: assert ] diff --git a/tool/.ruff.toml b/tool/.ruff.toml index 64cde455..069beaa6 100644 --- a/tool/.ruff.toml +++ b/tool/.ruff.toml @@ -3,12 +3,12 @@ line-length = 88 [lint] extend-ignore = [ - "TRY003", # tryceratops: raise-vanilla-args - "TD003", # flake8-todos: missing-todo-link - "S101", # flake8-bandit: assert - "S404", # flake8-bandit: suspicious-subprocess-import - "S603", # flake8-bandit: subprocess-without-shell-equals-true - "EM", # flake8-errmsg - "T201", # flake8-print: print - "PLR2004", # pylint/refactor: magic-value-comparison + "TRY003", # tryceratops: raise-vanilla-args + "TD003", # flake8-todos: missing-todo-link + "S101", # flake8-bandit: assert + "S404", # flake8-bandit: suspicious-subprocess-import + "S603", # flake8-bandit: subprocess-without-shell-equals-true + "EM", # flake8-errmsg + "T201", # flake8-print: print + "PLR2004", # pylint/refactor: magic-value-comparison ] From 961369602e3cea1d486e495f90c4af2aff689880 Mon Sep 17 00:00:00 2001 From: jorenham Date: Thu, 7 Aug 2025 00:05:05 +0200 Subject: [PATCH 4/7] =?UTF-8?q?=F0=9F=94=A5=20remove=20markdownlint=20and?= =?UTF-8?q?=20taplo=20in=20favor=20of=20dprint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/labeler.yml | 4 ++-- .github/workflows/ci.yml | 24 +++++------------------- .taplo.toml | 24 ------------------------ .vscode/extensions.json | 6 ++---- .vscode/settings.json | 14 ++++++-------- docs/.markdownlint.yaml | 17 ----------------- docs/dev/index.md | 4 ++-- 7 files changed, 17 insertions(+), 76 deletions(-) delete mode 100644 .taplo.toml delete mode 100644 docs/.markdownlint.yaml diff --git a/.github/labeler.yml b/.github/labeler.yml index 5dd0a1ee..177b71aa 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -150,5 +150,5 @@ "topic: code style": - changed-files: - any-glob-to-any-file: - - .taplo.toml - - **/.ruff.toml + - "**/.dprint.jsonc" + - "**/.ruff.toml" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 96d51cfd..d3850706 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,36 +28,22 @@ jobs: - name: typos uses: crate-ci/typos@v1.35.1 - - name: markdownlint - uses: DavidAnson/markdownlint-cli2-action@v20.0.0 - with: - config: "docs/.markdownlint.yaml" - globs: "**/*.md" - - - uses: uncenter/setup-taplo@v1.0.8 - with: - version: "0.9.3" - - name: taplo - run: | - taplo validate --colors never --no-schema - taplo fmt --colors never --check - - uses: astral-sh/setup-uv@v6.4.3 + - name: dprint + run: uv run --no-sync dprint check + - name: ruff run: | uv run ruff check --output-format=github uv run ruff format --check - - name: dprint - run: uv run --no-sync dprint check + - name: format-ignores + run: uv run tool/format_ignores.py --check - name: pytest run: uv run pytest - - name: format-ignores - run: uv run tool/format_ignores.py --check - # NOTE: Static typing only differs between `python<3.12` and otherwise, # so there's no need to run the type-checkers on all Python versions. diff --git a/.taplo.toml b/.taplo.toml deleted file mode 100644 index b721b65e..00000000 --- a/.taplo.toml +++ /dev/null @@ -1,24 +0,0 @@ -# https://taplo.tamasfe.dev/configuration/file.html -include = ["*.toml", "src/**/*.toml", "test/**/*.toml", "tool/**/*.toml"] - -[formatting] -# https://taplo.tamasfe.dev/configuration/formatter-options.html -align_entries = false -align_comments = true -allowed_blank_lines = 2 -array_auto_collapse = false -array_auto_expand = true -array_trailing_comma = true -column_width = 88 -compact_arrays = true -compact_inline_tables = true -crlf = false -indent_string = " " # 4 spaces -indent_tables = true -reorder_keys = false -reorder_arrays = false -reorder_inline_tables = false -trailingNewline = true - -[schema] -enabled = false diff --git a/.vscode/extensions.json b/.vscode/extensions.json index c158c57f..b180d09d 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,14 +1,12 @@ { "recommendations": [ "charliermarsh.ruff", - "davidanson.vscode-markdownlint", "detachhead.basedpyright", + "dprint.dprint", "ms-python.mypy-type-checker", "ms-python.python", - "redhat.vscode-yaml", "seatonjiang.gitmoji-vscode", - "tamasfe.even-better-toml", - "dprint.dprint", + "github.vscode-pull-request-github", ], "unwantedRecommendations": ["ms-pyright.pyright", "ms-python.vscode-pylance"], } diff --git a/.vscode/settings.json b/.vscode/settings.json index dd588a7c..4ba2af2e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,19 +1,17 @@ { - "[markdown]": { + "[json][jsonc][markdown][toml][yaml]": { + "editor.defaultFormatter": "dprint.dprint", "editor.rulers": [88], + "editor.tabSize": 2, }, "[python]": { + "editor.defaultFormatter": "charliermarsh.ruff", "editor.rulers": [88, 120], }, - "[toml]": { - "editor.rulers": [88], - }, - "evenBetterToml.schema.enabled": false, - "evenBetterToml.taplo.configFile.path": ".taplo.toml", "files.readonlyInclude": { "**/generated/*.pyi": true, }, + "editor.formatOnSave": true, "git.branchProtection": ["main"], - "markdownlint.configFile": "docs/.markdownlint.yaml", - "mypy-type-checker.path": ["uv", "run", "--no-editable", "--no-sync", "mypy"], + "mypy-type-checker.path": [".venv/bin/mypy"], } diff --git a/docs/.markdownlint.yaml b/docs/.markdownlint.yaml deleted file mode 100644 index 785f592e..00000000 --- a/docs/.markdownlint.yaml +++ /dev/null @@ -1,17 +0,0 @@ -default: true -no-hard-tabs: true - -MD007: - indent: 2 -MD013: - line_length: 120 -MD031: - list_items: false -MD033: - allowed_elements: - - h1 - - img - - a - - div -MD036: false -MD041: false diff --git a/docs/dev/index.md b/docs/dev/index.md index 7af13af5..f6be67f6 100644 --- a/docs/dev/index.md +++ b/docs/dev/index.md @@ -173,7 +173,7 @@ See for more information. The documentation lives in `docs/`, the `README.md`, and `CONTRIBUTING.md`. Please read it carefully before proposing any changes. -Ensure that the markdown is formatted correctly with [markdownlint]. +Ensure that the markdown is formatted correctly with [dprint][dprint]. ### Previewing Documentation Site @@ -215,7 +215,7 @@ See the [NumType style guide](style.md) for more. [basedpyright]: https://github.com/detachhead/basedpyright [gitmoji]: https://gitmoji.dev/ [lefthook]: https://lefthook.dev/ -[markdownlint]: https://github.com/DavidAnson/markdownlint/tree/main +[dprint]: https://dprint.dev/ [mkdocs]: https://www.mkdocs.org/ [mypy]: https://github.com/python/mypy [numpy-commit-style]: https://numpy.org/devdocs/dev/development_workflow.html#writing-the-commit-message From 944307c0ad1725393d64bd1f2b5db34a02748ca5 Mon Sep 17 00:00:00 2001 From: jorenham Date: Thu, 7 Aug 2025 00:05:49 +0200 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20only=20?= =?UTF-8?q?run=20dprint=20on=20staged=20files=20pre-commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 5 +---- lefthook.yml | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d3850706..df75915b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,5 @@ name: CI +permissions: read-all on: push: @@ -10,10 +11,6 @@ concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true -permissions: - contents: read - pull-requests: write - env: UV_LOCKED: 1 diff --git a/lefthook.yml b/lefthook.yml index 757a30f1..231595bf 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -18,15 +18,15 @@ pre-commit: - name: format_ignores glob: "*.{py,pyi}" + exclude: + - tool/test/test_format_ignores.py stage_fixed: true run: uv {run} tool/format_ignores.py {staged_files} - exclude: - - "tool/test/test_format_ignores.py" - name: dprint glob: "*.{json,jsonc,md,toml,yaml,yml}" stage_fixed: true - run: uv {run} dprint fmt --incremental=false + run: uv {run} dprint fmt {staged_files} - name: basedpyright glob: "*.{py,pyi}" From eb4d5ccf057791213f865893f47ecdcd3ceabd0e Mon Sep 17 00:00:00 2001 From: jorenham Date: Thu, 7 Aug 2025 00:07:45 +0200 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=92=9A=20uv's=20gotta=20sync=20to=20`?= =?UTF-8?q?dprint`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df75915b..4bfb6d13 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: - uses: astral-sh/setup-uv@v6.4.3 - name: dprint - run: uv run --no-sync dprint check + run: uv run dprint check - name: ruff run: | From 6adb645849874a193db65acb5151ff74bb2323e3 Mon Sep 17 00:00:00 2001 From: jorenham Date: Thu, 7 Aug 2025 00:17:51 +0200 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=A4=96=20auto-label=20PR's=20with=20`?= =?UTF-8?q?tool:=20dprint`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/labeler.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/labeler.yml b/.github/labeler.yml index 177b71aa..cf295ef3 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -129,6 +129,16 @@ - any-glob-to-any-file: - .github/workflows/** +"tool: lefthook": +- changed-files: + - any-glob-to-any-file: + - lefthook.yml + +"tool: dprint": +- changed-files: + - any-glob-to-any-file: + - .dprint.jsonc + "topic: dependencies": - changed-files: - any-glob-to-any-file: @@ -150,5 +160,5 @@ "topic: code style": - changed-files: - any-glob-to-any-file: - - "**/.dprint.jsonc" + - .dprint.jsonc - "**/.ruff.toml"