8

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?

Jeremy
  • 1
  • 85
  • 340
  • 366

1 Answers1

15

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.

Jeremy
  • 1
  • 85
  • 340
  • 366
Jorge Leitao
  • 19,085
  • 19
  • 85
  • 121
  • 1
    Can you post your `pyrightconfig.json` along with the answer? – Vasantha Ganesh Mar 26 '19 at 13:38
  • ...why would they implement a python linting tool using typescript – fafrd Nov 10 '21 at 22:53
  • Well, I would definitely prefer having a Python linter written in C++ or Rust; for large projects it is much faster and can multithread more easily. Now typescript... the only reason I can think of is that it does not need a Python environment to run it (e.g. a linter running on a web-based client like web VS code(?) – Jorge Leitao Nov 11 '21 at 14:46