python - 如何从 CLI 安装和运行 Pyright 而不是使用 VS Code?
问题描述
我想开始在我团队的项目中使用Pyright 。我已经安装了 Visual Studio Code 插件,并且可以在我工作时在我的编辑器中看到类型错误。但我希望能够将它作为我们测试套件的一部分自动运行,包括在我们的 CI 服务器上,而 VS Code 插件无法做到这一点。我需要安装它并将其用作独立的命令行工具。
Pyright 的文档说它有一个命令行界面,但唯一的安装和构建说明是针对 Visual Studio Code 扩展的,并且安装并没有添加pyright
可执行文件:
$ pyright
-bash: pyright: command not found
如何从命令行在我的 Python 项目上安装和运行 Pyright?
解决方案
尽管它是 Python 程序员的工具,但 Pyright 是在 Node 上运行的 TypeScript 中实现的,文档告诉我们可以使用该生态系统的包管理器之一来安装它,例如NPM或Yarn。如果你想安装它以在系统的任何地方使用(不仅仅是在特定的 Node 项目中),你需要一个global
安装。
npm install --global pyright
或者
yarn global add pyright
这将添加pyright
命令行界面。
$ 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.
推荐阅读
- java - 在 clojure 中使用正则表达式实现简单的扫描器/标记器
- python - 类型错误:'collection' 对象不可调用。尝试将多个文件上传到 mlab 集合时
- react-final-form - 如何挂钩 react-final-form 更新?
- docker - 基于 docker 的应用程序的 IDE 依赖项和自动完成
- javascript - 在 React 中设置状态
- javascript - 检查未定义类型的 JSON 响应
- amazon-web-services - AWS CDK:如何从 Route53 定位 API Gateway API
- java - 使用日期对字符串 [] 进行排序
- java - 膨胀类 com.google.android.youtube.player.YouTubeThumbnailView 时出错
- javascript - Django JsonResponse 使用 JavaScript 在模板中显示而不刷新页面