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?
Using the Install from VSIX command in the Extensions view command dropdown, or the Extensions: Install from VSIX command in the Command Palette, point to the .vsix file. You can also install using the VS Code --install-extension command-line switch providing the path to the .vsix file.
You can also run VS Code from the terminal by typing 'code' after adding it to the path: Launch VS Code. Open the Command Palette (Cmd+Shift+P) and type 'shell command' to find the Shell Command: Install 'code' command in PATH command.
Pyright supports configuration files that provide granular control over settings. Different “execution environments” can be associated with subdirectories within a source base. Each environment can specify different module search paths, python language versions, and platform targets.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With