Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ defaults:
env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
CARGO_PROFILE_DEV_LTO: "false"
CARGO_PROFILE_DEV_OPT_LEVEL: 0
Comment on lines +22 to +23

@MichaReiser MichaReiser Aug 7, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. How do we make sure we don't forget to add these to other new workflows? Should we have a CI profile? Is there a way that cargo can automatically pick up a profile based on the presence of an env variable?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a CI profile but we'd then have to thread it through to all jobs (there's no environment variable at present), and it turns out some jobs don't allow you to configure the profile (e.g., cargo publish --dry-run).

CARGO_TERM_COLOR: always
RUSTUP_MAX_RETRIES: 10
PACKAGE_NAME: ruff
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/daily_fuzz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ env:
RUSTUP_MAX_RETRIES: 10
# Line-tables-only debug info: faster builds, backtraces still work.
CARGO_PROFILE_DEV_DEBUG: line-tables-only
CARGO_PROFILE_DEV_LTO: "false"
CARGO_PROFILE_DEV_OPT_LEVEL: 0
PACKAGE_NAME: ruff
FORCE_COLOR: 1

Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ on:
permissions:
contents: read

env:
CARGO_PROFILE_DEV_LTO: "false"
CARGO_PROFILE_DEV_OPT_LEVEL: 0

jobs:
mkdocs:
environment:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish-playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ on:
env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
CARGO_PROFILE_DEV_LTO: "false"
CARGO_PROFILE_DEV_OPT_LEVEL: 0
CARGO_TERM_COLOR: always
RUSTUP_MAX_RETRIES: 10

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish-ty-playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ concurrency:
env:
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
CARGO_PROFILE_DEV_LTO: "false"
CARGO_PROFILE_DEV_OPT_LEVEL: 0
CARGO_TERM_COLOR: always
RUSTUP_MAX_RETRIES: 10

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/sync_typeshed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ env:

CARGO_NET_RETRY: 10
CARGO_PROFILE_DEV_DEBUG: line-tables-only
CARGO_PROFILE_DEV_LTO: "false"
CARGO_PROFILE_DEV_OPT_LEVEL: 0
CARGO_TERM_COLOR: always
NEXTEST_PROFILE: "ci"
RUSTUP_MAX_RETRIES: 10
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/typing_conformance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ env:
RUST_BACKTRACE: 1
# Line-tables-only debug info: faster builds, backtraces still work.
CARGO_PROFILE_DEV_DEBUG: line-tables-only
CARGO_PROFILE_DEV_LTO: "false"
CARGO_PROFILE_DEV_OPT_LEVEL: 0
CONFORMANCE_SUITE_COMMIT: f4f2952f3ac94d7af819c5c71b60a50a100370e0
PYTHON_VERSION: 3.12

Expand Down
24 changes: 12 additions & 12 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@ instructions to PR authors or flag unrelated pre-existing issues.
Run all tests (using `nextest` for faster execution and setting `INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1` to ensure all snapshots are updated):

```sh
CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_LTO=off INSTA_FORCE_PASS=1 INSTA_UPDATE=always CARGO_PROFILE_DEV_DEBUG="line-tables-only" MDTEST_UPDATE_SNAPSHOTS=1 cargo nextest run
INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo nextest run
```

Run tests for a specific crate:

```sh
CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_LTO=off INSTA_FORCE_PASS=1 INSTA_UPDATE=always CARGO_PROFILE_DEV_DEBUG="line-tables-only" MDTEST_UPDATE_SNAPSHOTS=1 cargo nextest run -p ty_python_semantic
INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo nextest run -p ty_python_semantic
```

Run a single mdtest file. The path to the mdtest file should be relative to the `crates/ty_python_semantic/resources/mdtest` folder. Include `--test mdtest` to avoid building unrelated test binaries:

```sh
CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_LTO=off INSTA_FORCE_PASS=1 INSTA_UPDATE=always CARGO_PROFILE_DEV_DEBUG="line-tables-only" MDTEST_UPDATE_SNAPSHOTS=1 cargo nextest run -p ty_python_semantic --test mdtest -- mdtest::<path/to/mdtest_file.md>
INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo nextest run -p ty_python_semantic --test mdtest -- mdtest::<path/to/mdtest_file.md>
```

To run a specific mdtest within a file, use a substring of the Markdown header text as `MDTEST_TEST_FILTER`. Only use this if it's necessary to isolate a single test case:

```sh
MDTEST_TEST_FILTER="<filter>" CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_LTO=off INSTA_FORCE_PASS=1 INSTA_UPDATE=always CARGO_PROFILE_DEV_DEBUG="line-tables-only" MDTEST_UPDATE_SNAPSHOTS=1 cargo nextest run -p ty_python_semantic --test mdtest -- mdtest::<path/to/mdtest_file.md>
MDTEST_TEST_FILTER="<filter>" INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo nextest run -p ty_python_semantic --test mdtest -- mdtest::<path/to/mdtest_file.md>
```

### Fallback without nextest
Expand All @@ -48,16 +48,16 @@ If `cargo nextest` is not available, use `cargo test` with the same environment

```sh
# Run all tests.
CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_LTO=off INSTA_FORCE_PASS=1 INSTA_UPDATE=always CARGO_PROFILE_DEV_DEBUG="line-tables-only" MDTEST_UPDATE_SNAPSHOTS=1 cargo test
INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo test

# Run tests for a specific crate.
CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_LTO=off INSTA_FORCE_PASS=1 INSTA_UPDATE=always CARGO_PROFILE_DEV_DEBUG="line-tables-only" MDTEST_UPDATE_SNAPSHOTS=1 cargo test -p ty_python_semantic
INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo test -p ty_python_semantic

# Run a single mdtest file.
CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_LTO=off INSTA_FORCE_PASS=1 INSTA_UPDATE=always CARGO_PROFILE_DEV_DEBUG="line-tables-only" MDTEST_UPDATE_SNAPSHOTS=1 cargo test -p ty_python_semantic --test mdtest -- <path/to/mdtest_file.md>
INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo test -p ty_python_semantic --test mdtest -- <path/to/mdtest_file.md>

# Run a specific mdtest within a file.
MDTEST_TEST_FILTER="<filter>" CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_LTO=off INSTA_FORCE_PASS=1 INSTA_UPDATE=always CARGO_PROFILE_DEV_DEBUG="line-tables-only" MDTEST_UPDATE_SNAPSHOTS=1 cargo test -p ty_python_semantic --test mdtest -- <path/to/mdtest_file.md>
MDTEST_TEST_FILTER="<filter>" INSTA_FORCE_PASS=1 INSTA_UPDATE=always MDTEST_UPDATE_SNAPSHOTS=1 cargo test -p ty_python_semantic --test mdtest -- <path/to/mdtest_file.md>
```

### Snapshot updates
Expand All @@ -80,7 +80,7 @@ Never edit snapshot files or inline snapshot bodies manually. Regenerate them by
## Running Clippy

```sh
CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_LTO=off CARGO_PROFILE_DEV_DEBUG="line-tables-only" cargo clippy --workspace --all-targets --all-features -- -D warnings
cargo clippy --workspace --all-targets --all-features -- -D warnings
```

## Running Debug Builds
Expand All @@ -90,13 +90,13 @@ Use debug builds (not `--release`) when developing, as release builds lack debug
Run Ruff:

```sh
CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_LTO=off CARGO_PROFILE_DEV_DEBUG="line-tables-only" cargo run --bin ruff -- check path/to/file.py
cargo run --bin ruff -- check path/to/file.py
```

Run ty:

```sh
CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_LTO=off CARGO_PROFILE_DEV_DEBUG="line-tables-only" cargo run --bin ty -- check path/to/file.py
cargo run --bin ty -- check path/to/file.py
```

## Working on ty
Expand Down Expand Up @@ -162,7 +162,7 @@ Parts of `.github/workflows/release.yml` are generated by cargo-dist from `dist-
- Prefer let chains (`if let` combined with `&&`) and let guards (`PAT if let ... =>`) over nested `if let` statements to reduce indentation and improve readability. At the end of a task, always check your work to see if you missed opportunities to use `let` chains or `let` guards.
- If you _have_ to suppress a Clippy lint, prefer to use `#[expect()]` over `[allow()]`, where possible. But if a lint is complaining about unused/dead code, it's usually best to just delete the unused code.
- Don't use comments to narrate code, but do use them to explain invariants and why something unusual was done a particular way. Make sure that a comment will make sense to somebody who's reading the code for the first time. Prefer plain language, avoid jargon, and don't be afraid to be more verbose if it's necessary to explain something well. Giving examples of the kind of Python code we're trying to model at this particular point in Ruff or ty can often be very helpful for future readers of the code.
- Run `CARGO_PROFILE_DEV_OPT_LEVEL=1 CARGO_PROFILE_DEV_LTO=off CARGO_PROFILE_DEV_DEBUG="line-tables-only" cargo dev generate-all` after changing configuration options, CLI arguments, lint rules, or environment variable definitions, as these changes require regeneration of schemas, docs, and CLI references.
- Run `cargo dev generate-all` after changing configuration options, CLI arguments, lint rules, or environment variable definitions, as these changes require regeneration of schemas, docs, and CLI references.
- Don't prefix tests with `test_`.
- Don't separate struct definitions from their `impl` blocks unless the `impl` is deliberately placed in a separate file, as for large structs.
- Avoid running `uv run` for any scripts from the repository root unless you use `--no-project`, `--script` or similar. Using `uv run` from the Ruff repo root without these flags will build Ruff from source, which is very slow and usually unnecessary.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ inherits = "release"
opt-level = "z"
codegen-units = 1

[profile.dev]
opt-level = 1
debug = "line-tables-only"
# Avoid the local ThinLTO that Cargo enables at nonzero optimization levels.
lto = "off"

[profile.dev.package.insta]
opt-level = 3

Expand Down
Loading