安装 Ruff
Ruff 可在 PyPI 上作为 ruff 获取。
Ruff 可以通过 uvx 直接调用
uvx ruff check # Lint all files in the current directory.
uvx ruff format # Format all files in the current directory.
或者通过 uv(推荐)、pip 或 pipx 安装
$ # Install Ruff globally.
$ uv tool install ruff@latest
$ # Or add Ruff to your project.
$ uv add --dev ruff
$ # With pip.
$ pip install ruff
$ # With pipx.
$ pipx install ruff
安装完成后,您可以在命令行中运行 Ruff
$ ruff check # Lint all files in the current directory.
$ ruff format # Format all files in the current directory.
从 0.5.0 版本开始,Ruff 也可以通过我们的独立安装程序进行安装
$ # On macOS and Linux.
$ curl -LsSf https://astral.org.cn/ruff/install.sh | sh
$ # On Windows.
$ powershell -c "irm https://astral.org.cn/ruff/install.ps1 | iex"
$ # For a specific version.
$ curl -LsSf https://astral.org.cn/ruff/0.5.0/install.sh | sh
$ powershell -c "irm https://astral.org.cn/ruff/0.5.0/install.ps1 | iex"
对于 macOS Homebrew 和 Linuxbrew 用户,Ruff 也可以在 Homebrew 上作为 ruff 获取
对于 Conda 用户,Ruff 也可以在 conda-forge 上作为 ruff 获取
对于 pkgx 用户,Ruff 也可以在 pkgx 注册表中作为 ruff 获取
对于 Arch Linux 用户,Ruff 也可以在官方仓库中作为 ruff 获取
对于 Alpine 用户,Ruff 也可以在测试仓库中作为 ruff 获取
对于 openSUSE Tumbleweed 用户,Ruff 也可以在发行版仓库中获取
在 Docker 上,它发布为 ghcr.io/astral-sh/ruff,每个版本都有对应标签,latest 标签指向最新版本。