How do I install and run Pyright from the CLI instead of using VS Code?

I would like to begin using Pyright with my team's projects. I have installed the Visual Studio Code plugin, and can see the type errors in my editor as I work. But I would like to be able to run it automatically as part of our test suite, including on our CI server, and a VS Code plugin can't do that. I need to install and use it as a standalone command-line tool.

Pyright's documentation said that it has a command-line interface, but the only installation and build instructions were for the Visual Studio Code extension, and installing that didn't add a pyright executable:

$ pyright
-bash: pyright: command not found

How can I install and run Pyright on my Python project from the command-line?

Upvotes: 9

Views: 16549

Answers (1)

Jorge Leitao
Jorge Leitao

Reputation: 20163

Even though it's a tool for Python programmers, Pyright is implemented in TypeScript running on Node, and the documentation tells us that it can be installed using one of the package managers for that ecosystem, such as NPM or Yarn. If you want to install it for use anywhere in the system (not just from within a particular Node project), you'll want a global installation.

npm install --global pyright

or

yarn global add pyright

This will add the pyright command-line interface.

$ pyright
Usage: pyright [options] file...

You can run this against your files by just specifying them on the command-line, but for a project you may want to create a pyrightconfig.json file identifying the files to be type-checked, and the Python interpreters, libraries, and type definitions that it should use. Some of these options can also be passed as command-line arguments, but not all of them.

Upvotes: 16

Related Questions