Skip to main content

Pantsbuild plugin for basedpyright type checking

Project description

pants-basedpyright

PyPI - Version PyPI - License

basedpyright is a fast type checker for Python, forked from Pyright. Unlike Pyright, however, it does not depend on an active Node.js installation. This makes it simpler to integrate Pyright-compatible type checking into pure Python projects without depending on a separate JavaScript runtime.

basedpyright also provides several other benefits like baseline support.

This repo contains a plugin for the Pants monorepo build system to integrate basedpyright into Pants's type checking workflow.

Supports Pants versions v2.27 and v2.28.

Features

  • Runs basedpyright type checking during $ pants check goal against appropriate Python targets.
  • No dependency on Node.js, making it easier to integrate pyright checks into monorepos that don't want to manage Node.js environments and dependencies for Python tooling.
  • Automatic config file detection in the workspace root (pyrightconfig.json as well as the [tool.basedpyright] or [tool.pyright] sections of a pyproject.toml file).
  • Explicit config file path support via [basedpyright].config section of pants.toml or CLI arguments , e.g. $ pants check --basedpyright-config="path/to/config.<json|toml>" ::.
  • Supports installation from resolves

Installation

Add pants-basedpyright to your plugins list in pants.toml:

[GLOBAL]
plugins = [
    "pants-basedpyright==0.2.0",
]

Then enable the backend in your pants.toml:

[GLOBAL]
backend_packages = [
    # ...other backends...
    "pants_basedpyright",
]

Configuration

Config File Discovery

By default, the plugin will look for a pyrightconfig.json or pyproject.toml file in the workspace root.

A pyproject.toml will be considered a config file candidate if it contains a [tool.basedpyright] or [tool.pyright] section, as basedpyright supports both formats for backwards compatibility with pyright.

If both files are present, basedpyright will give precedence to pyrightconfig.json.

Explicit Config File Path

You can also specify a custom config file path in your pants.toml that will take precedence over the default discovery behavior:

[basedpyright]
config = "path/to/your/pyproject.toml"  # or "path/to/your/pyrightconfig.json"

Or via the CLI (taking precedence over the pants.toml setting, if it exists):

pants check --basedpyright-config="path/to/your/pyproject.toml" ::  # or "path/to/your/pyrightconfig.json"

See the Pants options docs for more details on general option setting.

Usage

Run basedpyright checks:

pants check ::  # Check all targets

Advanced

Installing basedpyright from a Resolve

Pants resolves provide a mechanism to manage multiple sets of third-party dependencies.

Using resolves, you can install a different version of basedpyright than the default version specified by the plugin.

It's also possible to install basedpyright from a resolve so the tool is version-locked alongside your other Python dependencies. See Lockfiles for tools for more details.

  1. To install basedpyright itself from a particular Pants Python resolve, first ensure resolves are enabled in your pants.toml:
[python]
# ...other python settings...
enable_resolves = true
default_resolve = "python-default"  # Optional, this is the default if not set

[python.resolves]
python-default = "3rdparty/python/python-default.lock"
custom-resolve-with-basedpyright = "path/to/your/custom-resolve.lock"
  1. Run pants generate-lockfiles to create the lockfile if you haven't already. See Lockfiles for tools for an example BUILD and requirements file that generate-lockfiles will use to create a resolve that includes pytest a tool dependency.

  2. Specify the resolve from which to install basedpyright in the [basedpyright] section of your pants.toml:

[basedpyright]
install_from_resolve = "custom-resolve-with-basedpyright"

Now when you run pants check, the plugin will use the basedpyright version installed from the specified resolve.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pants_basedpyright-0.2.0.tar.gz (44.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pants_basedpyright-0.2.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file pants_basedpyright-0.2.0.tar.gz.

File metadata

  • Download URL: pants_basedpyright-0.2.0.tar.gz
  • Upload date:
  • Size: 44.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.15

File hashes

Hashes for pants_basedpyright-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e188df765f36c7249557186cafe9daecf1ee66c0feb21e9b2d1ac704407d7a93
MD5 46a3469faf03c41b053da2e39f30b0e3
BLAKE2b-256 9494218231cbdcdd268f0d2cbf7784679065d2f26ce30acd222efb7831d76ac5

See more details on using hashes here.

File details

Details for the file pants_basedpyright-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pants_basedpyright-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e1c271e3bc63b7c827452ffee515642a40af4455de388452e49666fa719354e0
MD5 a00b785b6b4c28cd39e569bee3479305
BLAKE2b-256 6f14473f8ad4501459d8d9016d0ab4b00b9b9029e809cdce2ca0472df41ec0a7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page