Skip to content

Commit 5567e7c

Browse files
Use uv consistently throughout the documentation (#15302)
## Summary Closes #15301 (comment).
1 parent 95294e6 commit 5567e7c

File tree

5 files changed

+104
-41
lines changed

5 files changed

+104
-41
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,21 @@ For more, see the [documentation](https://docs.astral.sh/ruff/).
116116

117117
### Installation
118118

119-
Ruff is available as [`ruff`](https://pypi.org/project/ruff/) on PyPI:
119+
Ruff is available as [`ruff`](https://pypi.org/project/ruff/) on PyPI.
120+
121+
Invoke Ruff directly with [`uvx`](https://docs.astral.sh/uv/):
122+
123+
```shell
124+
uvx ruff check # Lint all files in the current directory.
125+
uvx ruff format # Format all files in the current directory.
126+
```
127+
128+
Or install Ruff with `uv` (recommended), `pip`, or `pipx`:
120129

121130
```shell
122131
# With uv.
123-
uv add --dev ruff # to add ruff to your project
124-
uv tool install ruff # to install ruff globally
132+
uv tool install ruff@latest # Install Ruff globally.
133+
uv add --dev ruff # Or add Ruff to your project.
125134

126135
# With pip.
127136
pip install ruff

docs/faq.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,39 @@ Ruff is installable under any Python version from 3.7 onwards.
220220

221221
## Do I need to install Rust to use Ruff?
222222

223-
Nope! Ruff is available as [`ruff`](https://pypi.org/project/ruff/) on PyPI:
223+
Nope! Ruff is available as [`ruff`](https://pypi.org/project/ruff/) on PyPI. We recommend installing Ruff with [uv](https://docs.astral.sh/uv/),
224+
though it's also installable with `pip`, `pipx`, and a [variety of other package managers](installation.md):
224225

225226
```console
226-
# With uv.
227-
$ uv add --dev ruff # to add ruff to your project
228-
$ uv tool install ruff # to install ruff globally
227+
$ # Install Ruff globally.
228+
$ uv tool install ruff@latest
229229

230-
# With pip
230+
$ # Or add Ruff to your project.
231+
$ uv add --dev ruff
232+
233+
$ # With pip.
231234
$ pip install ruff
235+
236+
$ # With pipx.
237+
$ pipx install ruff
238+
```
239+
240+
Starting with version `0.5.0`, Ruff can also be installed with our standalone installers:
241+
242+
```console
243+
$ # On macOS and Linux.
244+
$ curl -LsSf https://astral.sh/ruff/install.sh | sh
245+
246+
$ # On Windows.
247+
$ powershell -c "irm https://astral.sh/ruff/install.ps1 | iex"
248+
249+
$ # For a specific version.
250+
$ curl -LsSf https://astral.sh/ruff/0.5.0/install.sh | sh
251+
$ powershell -c "irm https://astral.sh/ruff/0.5.0/install.ps1 | iex"
232252
```
233253

234-
Ruff ships with wheels for all major platforms, which enables `pip` to install Ruff without relying
235-
on Rust at all.
254+
Ruff ships with wheels for all major platforms, which enables `uv`, `pip`, and other tools to install Ruff without
255+
relying on a Rust toolchain at all.
236256

237257
## Can I write my own linter plugins for Ruff?
238258

docs/installation.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
# Installing Ruff
22

3-
Ruff is available as [`ruff`](https://pypi.org/project/ruff/) on PyPI:
3+
Ruff is available as [`ruff`](https://pypi.org/project/ruff/) on PyPI.
4+
5+
Ruff can be invoked directly with [`uvx`](https://docs.astral.sh/uv/):
6+
7+
```shell
8+
uvx ruff check # Lint all files in the current directory.
9+
uvx ruff format # Format all files in the current directory.
10+
```
11+
12+
Or installed with `uv` (recommended), `pip`, or `pipx`:
413

514
```console
15+
$ # Install Ruff globally.
16+
$ uv tool install ruff@latest
17+
18+
$ # Or add Ruff to your project.
19+
$ uv add --dev ruff
20+
21+
$ # With pip.
622
$ pip install ruff
23+
24+
$ # With pipx.
25+
$ pipx install ruff
726
```
827

928
Once installed, you can run Ruff from the command line:
@@ -13,7 +32,7 @@ $ ruff check # Lint all files in the current directory.
1332
$ ruff format # Format all files in the current directory.
1433
```
1534

16-
Starting with version `0.5.0`, Ruff can be installed with our standalone installers:
35+
Starting with version `0.5.0`, Ruff can also be installed with our standalone installers:
1736

1837
```console
1938
$ # On macOS and Linux.

docs/tutorial.md

Lines changed: 42 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@ your project. For a more detailed overview, see [_Configuring Ruff_](configurati
55

66
## Getting Started
77

8-
To start, we'll install Ruff through PyPI (or with your [preferred package manager](installation.md)):
8+
To start, we'll initialize a project using [uv](https://docs.astral.sh/uv/):
99

1010
```console
11-
$ pip install ruff
11+
$ uv init numbers
1212
```
1313

14-
Let's then assume that our project structure looks like:
14+
This command creates a Python project with the following structure:
1515

1616
```text
1717
numbers
18-
├── __init__.py
19-
└── numbers.py
18+
├── pyproject.toml
19+
└── src
20+
└── numbers
21+
├── __init__.py
22+
└── py.typed
2023
```
2124

22-
...where `numbers.py` contains the following code:
25+
We'll then replace the contents of `src/numbers/__init__.py` with the following code:
2326

2427
```python
2528
from typing import Iterable
@@ -35,28 +38,40 @@ def sum_even_numbers(numbers: Iterable[int]) -> int:
3538
)
3639
```
3740

38-
We can run the Ruff linter over our project via `ruff check`:
41+
Next, we'll add Ruff to our project:
3942

4043
```console
41-
$ ruff check
42-
numbers/numbers.py:3:8: F401 [*] `os` imported but unused
44+
$ uv add --dev ruff
45+
```
46+
47+
We can then run the Ruff linter over our project via `uv run ruff check`:
48+
49+
```console
50+
$ uv run ruff check
51+
src/numbers/__init__.py:3:8: F401 [*] `os` imported but unused
4352
Found 1 error.
4453
[*] 1 fixable with the `--fix` option.
4554
```
4655

56+
!!! note
57+
58+
As an alternative to `uv run`, you can also run Ruff by activating the project's virtual
59+
environment (`source .venv/bin/active` on Linux and macOS, or `.venv\Scripts\activate` on
60+
Windows) and running `ruff check` directly.
61+
4762
Ruff identified an unused import, which is a common error in Python code. Ruff considers this a
4863
"fixable" error, so we can resolve the issue automatically by running `ruff check --fix`:
4964

5065
```console
51-
$ ruff check --fix
66+
$ uv run ruff check --fix
5267
Found 1 error (1 fixed, 0 remaining).
5368
```
5469

5570
Running `git diff` shows the following:
5671

5772
```diff
58-
--- a/numbers/numbers.py
59-
+++ b/numbers/numbers.py
73+
--- a/src/numbers/__init__.py
74+
+++ b/src/numbers/__init__.py
6075
@@ -1,7 +1,5 @@
6176
from typing import Iterable
6277

@@ -74,13 +89,13 @@ def sum_even_numbers(numbers: Iterable[int]) -> int:
7489
Note Ruff runs in the current directory by default, but you can pass specific paths to check:
7590

7691
```console
77-
$ ruff check numbers/numbers.py
92+
$ uv run ruff check src/numbers/__init__.py
7893
```
7994

8095
Now that our project is passing `ruff check`, we can run the Ruff formatter via `ruff format`:
8196

8297
```console
83-
$ ruff format
98+
$ uv run ruff format
8499
1 file reformatted
85100
```
86101

@@ -109,7 +124,7 @@ Ruff's behavior.
109124
To determine the appropriate settings for each Python file, Ruff looks for the first
110125
`pyproject.toml`, `ruff.toml`, or `.ruff.toml` file in the file's directory or any parent directory.
111126

112-
To configure Ruff, let's create a configuration file in our project's root directory:
127+
To configure Ruff, we'll add the following to the configuration file in our project's root directory:
113128

114129
=== "pyproject.toml"
115130

@@ -141,8 +156,8 @@ To configure Ruff, let's create a configuration file in our project's root direc
141156
Running Ruff again, we see that it now enforces a maximum line width, with a limit of 79:
142157

143158
```console
144-
$ ruff check
145-
numbers/numbers.py:5:80: E501 Line too long (90 > 79)
159+
$ uv run ruff check
160+
src/numbers/__init__.py:5:80: E501 Line too long (90 > 79)
146161
Found 1 error.
147162
```
148163

@@ -223,8 +238,8 @@ If we run Ruff again, we'll see that it now enforces the pyupgrade rules. In par
223238
the use of the deprecated `typing.Iterable` instead of `collections.abc.Iterable`:
224239

225240
```console
226-
$ ruff check
227-
numbers/numbers.py:1:1: UP035 [*] Import from `collections.abc` instead: `Iterable`
241+
$ uv run ruff check
242+
src/numbers/__init__.py:1:1: UP035 [*] Import from `collections.abc` instead: `Iterable`
228243
Found 1 error.
229244
[*] 1 fixable with the `--fix` option.
230245
```
@@ -266,10 +281,10 @@ all functions have docstrings:
266281
If we run Ruff again, we'll see that it now enforces the pydocstyle rules:
267282

268283
```console
269-
$ ruff check
284+
$ uv run ruff check
270285
numbers/__init__.py:1:1: D104 Missing docstring in public package
271-
numbers/numbers.py:1:1: UP035 [*] Import from `collections.abc` instead: `Iterable`
272-
numbers/numbers.py:1:1: D100 Missing docstring in public module
286+
src/numbers/__init__.py:1:1: UP035 [*] Import from `collections.abc` instead: `Iterable`
287+
src/numbers/__init__.py:1:1: D100 Missing docstring in public module
273288
Found 3 errors.
274289
[*] 1 fixable with the `--fix` option.
275290
```
@@ -291,9 +306,9 @@ def sum_even_numbers(numbers: Iterable[int]) -> int:
291306
Running `ruff check` again, we'll see that it no longer flags the `Iterable` import:
292307

293308
```console
294-
$ ruff check
309+
$ uv run ruff check
295310
numbers/__init__.py:1:1: D104 Missing docstring in public package
296-
numbers/numbers.py:1:1: D100 Missing docstring in public module
311+
src/numbers/__init__.py:1:1: D100 Missing docstring in public module
297312
Found 3 errors.
298313
```
299314

@@ -322,7 +337,7 @@ line based on its existing violations. We can combine `--add-noqa` with the `--s
322337
flag to add `# noqa` directives to all existing `UP035` violations:
323338

324339
```console
325-
$ ruff check --select UP035 --add-noqa .
340+
$ uv run ruff check --select UP035 --add-noqa .
326341
Added 1 noqa directive.
327342
```
328343

@@ -331,8 +346,8 @@ Running `git diff` shows the following:
331346
```diff
332347
diff --git a/tutorial/src/main.py b/tutorial/src/main.py
333348
index b9291c5ca..b9f15b8c1 100644
334-
--- a/numbers/numbers.py
335-
+++ b/numbers/numbers.py
349+
--- a/src/numbers/__init__.py
350+
+++ b/src/numbers/__init__.py
336351
@@ -1,4 +1,4 @@
337352
-from typing import Iterable
338353
+from typing import Iterable # noqa: UP035

python/ruff-ecosystem/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Compare lint and format results for two different ruff versions (e.g. main and a
44

55
## Installation
66

7-
From the Ruff project root, install with `pip`:
7+
From the Ruff project root, install with [uv](https://docs.astral.sh/uv/):
88

99
```shell
10-
pip install -e ./python/ruff-ecosystem
10+
uv tool install -e ./python/ruff-ecosystem
1111
```
1212

1313
## Usage

0 commit comments

Comments
 (0)