diff --git a/.dprint.jsonc b/.dprint.jsonc new file mode 100644 index 0000000..fd54599 --- /dev/null +++ b/.dprint.jsonc @@ -0,0 +1,22 @@ +{ + "json": { + "lineWidth": 88, + "array.preferSingleLine": true, + }, + "markdown": { + "lineWidth": 88, + "emphasisKind": "asterisks", + }, + "yaml": { + "printWidth": 88, + "formatComments": true, + "braceSpacing": false, + }, + "excludes": ["**/*-lock.json", "**/*.lock", "**/node_modules/", "dist/"], + "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/.github/workflows/ci.yml b/.github/workflows/ci.yml index e00d663..acdb906 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,9 @@ jobs: steps: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: dprint + uses: dprint/check@9cb3a2b17a8e606d37aae341e49df3654933fc23 # v2.3 + - name: Install uv uses: astral-sh/setup-uv@bd01e18f51369d5a26f1651c3cb451d3417e3bba # v6.3.1 diff --git a/README.md b/README.md index b626a62..d79a97e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ > for working with the [Python array API standard](https://data-apis.org/array-api/latest/), but it > may change significantly in the future. - ## Installation ```bash @@ -45,6 +44,7 @@ pip install -e . # editable mode ### Quick example + ```pycon >>> import array_api_typing as xpt >>> import numpy as np @@ -56,3 +56,4 @@ pip install -e . # editable mode array([1, 2, 3]) ``` + diff --git a/lefthook.yml b/lefthook.yml index 8edf983..686aae8 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -7,6 +7,10 @@ templates: pre-commit: parallel: true jobs: + - name: dprint + glob: "*.{json,jsonc,md,toml,yaml,yml}" + stage_fixed: true + run: uv {run} dprint fmt --incremental=false - name: ruff glob: "*.{py,pyi}" stage_fixed: true diff --git a/pyproject.toml b/pyproject.toml index ee7f4b5..02118fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,158 +1,152 @@ [project] - name = "array-api-typing" - dynamic = ["version"] - description = "Static typing support for the array API standard" - readme = "README.md" - requires-python = ">=3.10" - license = "MIT" - authors = [ - { name = "Consortium for Python Data API Standards", email = "data-apis@users.noreply.github.com" }, - { name = "Joren Hammudoglu", email = "jhammudoglu@gmail.com" }, - { name = "Nathaniel Starkman", email = "nstarman@users.noreply.github.com" }, - ] - classifiers = [ - "Development Status :: 1 - Planning", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python :: 3.13", - "Programming Language :: Python", - "Topic :: Scientific/Engineering", - "Typing :: Typed", - ] - dependencies = [ - "typing-extensions>=4.14.1", - ] - - [project.urls] - Repository = "https://github.com/data-apis/array-api-typing" - Changelog = "https://github.com/data-apis/array-api-typing/releases" - +name = "array-api-typing" +dynamic = ["version"] +description = "Static typing support for the array API standard" +readme = "README.md" +requires-python = ">=3.10" +license = "MIT" +authors = [ + { name = "Consortium for Python Data API Standards", email = "data-apis@users.noreply.github.com" }, + { name = "Joren Hammudoglu", email = "jhammudoglu@gmail.com" }, + { name = "Nathaniel Starkman", email = "nstarman@users.noreply.github.com" }, +] +classifiers = [ + "Development Status :: 1 - Planning", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python", + "Topic :: Scientific/Engineering", + "Typing :: Typed", +] +dependencies = [ + "typing-extensions>=4.14.1", +] + +[project.urls] +Repository = "https://github.com/data-apis/array-api-typing" +Changelog = "https://github.com/data-apis/array-api-typing/releases" [build-system] - requires = ["hatch-vcs", "hatchling"] - build-backend = "hatchling.build" - +requires = ["hatch-vcs", "hatchling"] +build-backend = "hatchling.build" [dependency-groups] - dev = [ - { include-group = "lint" }, - { include-group = "mypy" }, - { include-group = "test_runtime" }, - { include-group = "test_numpy" }, - "lefthook==1.12.0", - "orjson>=3.11.0; python_version<'3.14'", # used by mypy - ] - lint = [ - "ruff==0.12.4", - ] - mypy = [ - "mypy==1.17.0", - ] - test_runtime = [ - "pytest==8.4.1", - "pytest-cov>=6.2.1", - "pytest-github-actions-annotate-failures==0.3.0", - "sybil==9.1.0", - ] - test_numpy = [ - "numpy>=1.25", - ] - +dev = [ + { include-group = "lint" }, + { include-group = "mypy" }, + { include-group = "test_runtime" }, + { include-group = "test_numpy" }, + "lefthook==1.12.2", + "orjson>=3.11.0; python_version<'3.14'", # used by mypy +] +lint = [ + "ruff==0.12.4", + "dprint-py>=0.50.0.0", +] +mypy = [ + "mypy==1.17.0", +] +test_runtime = [ + "pytest==8.4.1", + "pytest-cov>=6.2.1", + "pytest-github-actions-annotate-failures==0.3.0", + "sybil==9.1.0", +] +test_numpy = [ + "numpy>=1.25", +] [tool.hatch] - version.source = "vcs" +version.source = "vcs" - [tool.hatch.build.hooks.vcs] - version-file = "src/array_api_typing/_version.py" - template = ''' +[tool.hatch.build.hooks.vcs] +version-file = "src/array_api_typing/_version.py" +template = ''' # This file is automatically generated by Hatch version = {version!r} version_tuple = {version_tuple!r} ''' - [tool.coverage] - report.exclude_also = ['\.\.\.', 'if typing.TYPE_CHECKING:'] - run.source = ["array-api-typing"] - run.branch = true - +report.exclude_also = ['\.\.\.', 'if typing.TYPE_CHECKING:'] +run.source = ["array-api-typing"] +run.branch = true [tool.mypy] - mypy_path = ["src"] - namespace_packages = true - - strict = true - allow_redefinition_new = true - local_partial_types = true - enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] - warn_unreachable = true +mypy_path = ["src"] +namespace_packages = true +strict = true +allow_redefinition_new = true +local_partial_types = true +enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] +warn_unreachable = true [tool.pytest.ini_options] - addopts = [ - "--showlocals", - "--strict-config", - "--strict-markers", - "-p no:doctest", # using sybil - "-ra", - ] - filterwarnings = [ - "error", - # Sybil - "ignore:Attribute s is deprecated and will be removed in Python 3\\.14:DeprecationWarning", - "ignore:ast\\.Str is deprecated and will be removed in Python 3\\.14:DeprecationWarning", - ] - log_cli_level = "INFO" - minversion = "8.4" - testpaths = ["README.md", "src/", "tests/runtime/"] - xfail_strict = true - +addopts = [ + "--showlocals", + "--strict-config", + "--strict-markers", + "-p no:doctest", # using sybil + "-ra", +] +filterwarnings = [ + "error", + # Sybil + "ignore:Attribute s is deprecated and will be removed in Python 3\\.14:DeprecationWarning", + "ignore:ast\\.Str is deprecated and will be removed in Python 3\\.14:DeprecationWarning", +] +log_cli_level = "INFO" +minversion = "8.4" +testpaths = ["README.md", "src/", "tests/runtime/"] +xfail_strict = true [tool.ruff] - preview = true - force-exclude = true - - [tool.ruff.lint] - extend-select = ["ALL"] - ignore = [ - "COM812", # Conflicts with formatter - "CPY", # Missing copyright notice at top of file (NOTE revisit when autofixable) - "D105", # Missing docstring in magic method - "D107", # Missing docstring in __init__ - "D203", # 1 blank line required before class docstring - "D213", # Multi-line docstring summary should start at the second line - "FBT", # flake8-boolean-trap - "FIX", # flake8-fixme - "ISC001", # Conflicts with formatter - ] - - [tool.ruff.lint.pylint] - allow-dunder-method-names = [ - "__array_api_version__", - "__array_namespace__", - "__array_namespace_info__", - "__dlpack__", - "__dlpack_device__", - "__dlpack_device__", - ] - - [tool.ruff.lint.flake8-import-conventions] - banned-from = ["array_api_typing"] - - [tool.ruff.lint.flake8-import-conventions.extend-aliases] - array_api_typing = "xpt" - - [tool.ruff.lint.isort] - combine-as-imports = true - extra-standard-library = ["_typeshed", "typing_extensions"] - known-local-folder = ["array_api_typing"] - - [tool.ruff.format] - docstring-code-format = true - line-ending = "lf" +preview = true +force-exclude = true + +[tool.ruff.lint] +extend-select = ["ALL"] +ignore = [ + "COM812", # Conflicts with formatter + "CPY", # Missing copyright notice at top of file (NOTE revisit when autofixable) + "D105", # Missing docstring in magic method + "D107", # Missing docstring in __init__ + "D203", # 1 blank line required before class docstring + "D213", # Multi-line docstring summary should start at the second line + "FBT", # flake8-boolean-trap + "FIX", # flake8-fixme + "ISC001", # Conflicts with formatter +] + +[tool.ruff.lint.pylint] +allow-dunder-method-names = [ + "__array_api_version__", + "__array_namespace__", + "__array_namespace_info__", + "__dlpack__", + "__dlpack_device__", + "__dlpack_device__", +] + +[tool.ruff.lint.flake8-import-conventions] +banned-from = ["array_api_typing"] + +[tool.ruff.lint.flake8-import-conventions.extend-aliases] +array_api_typing = "xpt" + +[tool.ruff.lint.isort] +combine-as-imports = true +extra-standard-library = ["_typeshed", "typing_extensions"] +known-local-folder = ["array_api_typing"] + +[tool.ruff.format] +docstring-code-format = true +line-ending = "lf" diff --git a/tests/.ruff.toml b/tests/.ruff.toml index 1996a67..31681b5 100644 --- a/tests/.ruff.toml +++ b/tests/.ruff.toml @@ -3,7 +3,7 @@ extend = "../pyproject.toml" [lint] extend-ignore = [ "ANN201", # https://docs.astral.sh/ruff/rules/missing-return-type-undocumented-public-function/ - "D1", # https://docs.astral.sh/ruff/rules/#pydocstyle-d + "D1", # https://docs.astral.sh/ruff/rules/#pydocstyle-d "INP001", # https://docs.astral.sh/ruff/rules/implicit-namespace-package/ - "S101", # https://docs.astral.sh/ruff/rules/assert/ + "S101", # https://docs.astral.sh/ruff/rules/assert/ ] diff --git a/uv.lock b/uv.lock index 91372b7..996df8c 100644 --- a/uv.lock +++ b/uv.lock @@ -15,6 +15,7 @@ dependencies = [ [package.dev-dependencies] dev = [ + { name = "dprint-py" }, { name = "lefthook" }, { name = "mypy" }, { name = "numpy", version = "2.2.6", source = { registry = "https://pypi.org/simple" }, marker = "python_full_version < '3.11'" }, @@ -27,6 +28,7 @@ dev = [ { name = "sybil" }, ] lint = [ + { name = "dprint-py" }, { name = "ruff" }, ] mypy = [ @@ -48,7 +50,8 @@ requires-dist = [{ name = "typing-extensions", specifier = ">=4.14.1" }] [package.metadata.requires-dev] dev = [ - { name = "lefthook", specifier = "==1.12.0" }, + { name = "dprint-py", specifier = ">=0.50.0.0" }, + { name = "lefthook", specifier = "==1.12.2" }, { name = "mypy", specifier = "==1.17.0" }, { name = "numpy", specifier = ">=1.25" }, { name = "orjson", marker = "python_full_version < '3.14'", specifier = ">=3.11.0" }, @@ -58,7 +61,10 @@ dev = [ { name = "ruff", specifier = "==0.12.4" }, { name = "sybil", specifier = "==9.1.0" }, ] -lint = [{ name = "ruff", specifier = "==0.12.4" }] +lint = [ + { name = "dprint-py", specifier = ">=0.50.0.0" }, + { name = "ruff", specifier = "==0.12.4" }, +] mypy = [{ name = "mypy", specifier = "==1.17.0" }] test-numpy = [{ name = "numpy", specifier = ">=1.25" }] test-runtime = [ @@ -146,6 +152,18 @@ toml = [ { name = "tomli", marker = "python_full_version <= '3.11'" }, ] +[[package]] +name = "dprint-py" +version = "0.50.0.0" +source = { registry = "https://pypi.org/simple" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/dd/93/d86ec5ffa5ce38382b2100c40338a1452ddbac3deee65a9f14237612312d/dprint_py-0.50.0.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:70e569d2971ba3c8863073b573dcb77f2bf187b1ca4b309ac608fb5a40672e0e", size = 21333922, upload-time = "2025-05-19T01:26:44.093Z" }, + { url = "https://files.pythonhosted.org/packages/80/75/ba51567099ff5cd3ad38933c767c0c7e667b2bd5ec4c8b071d0dfa300471/dprint_py-0.50.0.0-py3-none-macosx_11_0_x86_64.whl", hash = "sha256:827a8ec8eca6b9ea88990a8848600c5c1b635717ef724ae531ccc5ba2e3b2022", size = 22516283, upload-time = "2025-05-19T01:26:46.989Z" }, + { url = "https://files.pythonhosted.org/packages/8f/be/d4aef796fad5e4a34a621905c678d7fe0124795c1c8a65c96e71137c81b5/dprint_py-0.50.0.0-py3-none-manylinux_2_17_aarch64.whl", hash = "sha256:1dfe5b4d73aeadc10116f37341c4eac4651c85254a68e8693eb83e6928ae80de", size = 23866263, upload-time = "2025-05-19T01:26:50.035Z" }, + { url = "https://files.pythonhosted.org/packages/7c/2e/a82a2de42d057a0e9713a497fdefe9729ce5d79d523a826c4a150e68ecc4/dprint_py-0.50.0.0-py3-none-manylinux_2_17_x86_64.whl", hash = "sha256:19cd159462841442f6d7431e36d29911f6fb63702163ad5fb5bb438ad04f6863", size = 24582934, upload-time = "2025-05-19T01:26:54.347Z" }, + { url = "https://files.pythonhosted.org/packages/0c/3c/57941c239eef3fa74ff44fb1452e56b04cb08ae3af39669b8b7178ff80ad/dprint_py-0.50.0.0-py3-none-win_amd64.whl", hash = "sha256:90de7885d3c9d6b13949ed609f2f2256b4ea74bf1355adcdfda0c30f7e3f9d47", size = 20785813, upload-time = "2025-05-19T01:26:57.162Z" }, +] + [[package]] name = "exceptiongroup" version = "1.3.0" @@ -169,11 +187,11 @@ wheels = [ [[package]] name = "lefthook" -version = "1.12.0" +version = "1.12.2" source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/f6/54/44fe438c96f8248da8952268b9c4ea712d2ef30a41f077d3a479d06be9e3/lefthook-1.12.0.tar.gz", hash = "sha256:25cbaff4043d93048b12218f322ff03dd6c819f62ee37149fb7e0723ce0bb822", size = 51062845, upload-time = "2025-07-08T13:07:33.603Z" } +sdist = { url = "https://files.pythonhosted.org/packages/4c/00/28d555139119488cc353860f3bfbff16c788c3a6f571eb771e81e35b89d9/lefthook-1.12.2.tar.gz", hash = "sha256:932aad5491b107b1fe770a85be4ef1e6798df084f309070d041c6a3280c56728", size = 51089410, upload-time = "2025-07-11T10:50:11.559Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/92/bd/7460c6107e49a8e250e054c459a437358932586b12d8fc95e7ab3643c966/lefthook-1.12.0-py3-none-any.whl", hash = "sha256:eb9a080dfc53fc6ae147975a87e4dbf463c5df910074a2901bd66f69d8136b52", size = 51308088, upload-time = "2025-07-08T13:07:28.955Z" }, + { url = "https://files.pythonhosted.org/packages/08/6f/6b1730419215ea204f6f1f71370e44a7775ba2db0ca8d4372c08c176e710/lefthook-1.12.2-py3-none-any.whl", hash = "sha256:59b773512cf2e5ec646b03fa2966d600452825c4cb2e5cc81277804e71616805", size = 51332387, upload-time = "2025-07-11T10:50:07.284Z" }, ] [[package]]