Rename ruff_cli crate to ruff (#9557)

## Summary

Long ago, we had a single `ruff` crate. We started to break that up, and
at some point, we wanted to separate the CLI from the core library. So
we created `ruff_cli`, which created a `ruff` binary. Later, the `ruff`
crate was renamed to `ruff_linter` and further broken up into additional
crates.

(This is all from memory -- I didn't bother to look through the history
to ensure that this is 100% correct :))

Now that `ruff` no longer exists, this PR renames `ruff_cli` to `ruff`.
The primary benefit is that the binary target and the crate name are now
the same, which helps with downstream tooling like `cargo-dist`, and
also removes some complexity from the crate and `Cargo.toml` itself.

## Test Plan

- Ran `rm -rf target/release`.
- Ran `cargo build --release`.
- Verified that `./target/release/ruff` was created.
This commit is contained in:
Charlie Marsh 2024-01-16 17:47:01 -05:00 committed by GitHub
parent 45d374d838
commit 8118d29419
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
64 changed files with 84 additions and 87 deletions

View file

@ -4,7 +4,7 @@ exclude: |
(?x)^(
crates/ruff_linter/resources/.*|
crates/ruff_linter/src/rules/.*/snapshots/.*|
crates/ruff_cli/resources/.*|
crates/ruff/resources/.*|
crates/ruff_python_formatter/resources/.*|
crates/ruff_python_formatter/tests/snapshots/.*|
crates/ruff_python_resolver/resources/.*|

View file

@ -81,7 +81,7 @@ pre-commit install
After cloning the repository, run Ruff locally from the repository root with:
```shell
cargo run -p ruff_cli -- check /path/to/file.py --no-cache
cargo run -p ruff -- check /path/to/file.py --no-cache
```
Prior to opening a pull request, ensure that your code has been auto-formatted,
@ -120,7 +120,7 @@ At the time of writing, the repository includes the following crates:
If you're working on a rule, this is the crate for you.
- `crates/ruff_benchmark`: binary crate for running micro-benchmarks.
- `crates/ruff_cache`: library crate for caching lint results.
- `crates/ruff_cli`: binary crate containing Ruff's command-line interface.
- `crates/ruff`: binary crate containing Ruff's command-line interface.
- `crates/ruff_dev`: binary crate containing utilities used in the development of Ruff itself (e.g.,
`cargo dev generate-all`), see the [`cargo dev`](#cargo-dev) section below.
- `crates/ruff_diagnostics`: library crate for the rule-independent abstractions in the lint
@ -231,7 +231,7 @@ Once you've completed the code for the rule itself, you can define tests with th
For example, if you're adding a new rule named `E402`, you would run:
```shell
cargo run -p ruff_cli -- check crates/ruff_linter/resources/test/fixtures/pycodestyle/E402.py --no-cache --select E402
cargo run -p ruff -- check crates/ruff_linter/resources/test/fixtures/pycodestyle/E402.py --no-cache --select E402
```
**Note:** Only a subset of rules are enabled by default. When testing a new rule, ensure that
@ -252,7 +252,7 @@ Once you've completed the code for the rule itself, you can define tests with th
Ruff's user-facing settings live in a few different places.
First, the command-line options are defined via the `Args` struct in `crates/ruff_cli/src/args.rs`.
First, the command-line options are defined via the `Args` struct in `crates/ruff/src/args.rs`.
Second, the `pyproject.toml` options are defined in `crates/ruff_workspace/src/options.rs` (via the
`Options` struct), `crates/ruff_workspace/src/configuration.rs` (via the `Configuration` struct),

70
Cargo.lock generated
View file

@ -2003,40 +2003,7 @@ dependencies = [
]
[[package]]
name = "ruff_benchmark"
version = "0.0.0"
dependencies = [
"codspeed-criterion-compat",
"criterion",
"mimalloc",
"once_cell",
"ruff_linter",
"ruff_python_ast",
"ruff_python_formatter",
"ruff_python_index",
"ruff_python_parser",
"serde",
"serde_json",
"tikv-jemallocator",
"ureq",
"url",
]
[[package]]
name = "ruff_cache"
version = "0.0.0"
dependencies = [
"filetime",
"glob",
"globset",
"itertools 0.12.0",
"regex",
"ruff_macros",
"seahash",
]
[[package]]
name = "ruff_cli"
name = "ruff"
version = "0.1.13"
dependencies = [
"anyhow",
@ -2086,6 +2053,39 @@ dependencies = [
"wild",
]
[[package]]
name = "ruff_benchmark"
version = "0.0.0"
dependencies = [
"codspeed-criterion-compat",
"criterion",
"mimalloc",
"once_cell",
"ruff_linter",
"ruff_python_ast",
"ruff_python_formatter",
"ruff_python_index",
"ruff_python_parser",
"serde",
"serde_json",
"tikv-jemallocator",
"ureq",
"url",
]
[[package]]
name = "ruff_cache"
version = "0.0.0"
dependencies = [
"filetime",
"glob",
"globset",
"itertools 0.12.0",
"regex",
"ruff_macros",
"seahash",
]
[[package]]
name = "ruff_dev"
version = "0.0.0"
@ -2102,7 +2102,7 @@ dependencies = [
"pretty_assertions",
"rayon",
"regex",
"ruff_cli",
"ruff",
"ruff_diagnostics",
"ruff_formatter",
"ruff_linter",

View file

@ -1,5 +1,5 @@
[package]
name = "ruff_cli"
name = "ruff"
version = "0.1.13"
publish = false
authors = { workspace = true }
@ -11,9 +11,6 @@ repository = { workspace = true }
license = { workspace = true }
readme = "../../README.md"
[[bin]]
name = "ruff"
[dependencies]
ruff_cache = { path = "../ruff_cache" }
ruff_diagnostics = { path = "../ruff_diagnostics" }

View file

@ -83,7 +83,7 @@ pub enum Command {
},
}
// The `Parser` derive is for ruff_dev, for ruff_cli `Args` would be sufficient
// The `Parser` derive is for ruff_dev, for ruff `Args` would be sufficient
#[derive(Clone, Debug, clap::Parser)]
#[allow(clippy::struct_excessive_bools)]
pub struct CheckCommand {

View file

@ -1,5 +1,5 @@
---
source: crates/ruff_cli/src/commands/check.rs
source: crates/ruff/src/commands/check.rs
---
/home/ferris/project/code.py:1:1: E902 Permission denied (os error 13)
/home/ferris/project/notebook.ipynb:1:1: E902 Permission denied (os error 13)

View file

@ -3,8 +3,8 @@ use std::process::ExitCode;
use clap::{Parser, Subcommand};
use colored::Colorize;
use ruff_cli::args::{Args, Command};
use ruff_cli::{run, ExitStatus};
use ruff::args::{Args, Command};
use ruff::{run, ExitStatus};
#[cfg(target_os = "windows")]
#[global_allocator]

View file

@ -0,0 +1,5 @@
---
source: crates/ruff/src/version.rs
expression: version
---
0.0.0

View file

@ -1,5 +1,5 @@
---
source: crates/ruff_cli/src/version.rs
source: crates/ruff/src/version.rs
expression: version
---
0.0.0 (53b0f5d92 2023-10-19)

View file

@ -1,5 +1,5 @@
---
source: crates/ruff_cli/src/version.rs
source: crates/ruff/src/version.rs
expression: version
---
0.0.0+24 (53b0f5d92 2023-10-19)

View file

@ -1,5 +1,5 @@
---
source: crates/ruff_cli/src/version.rs
source: crates/ruff/src/version.rs
expression: version
---
{

View file

@ -20,9 +20,9 @@ use path_absolutize::path_dedot;
use tempfile::TempDir;
#[cfg(unix)]
use ruff_cli::args::Args;
use ruff::args::Args;
#[cfg(unix)]
use ruff_cli::run;
use ruff::run;
const BIN_NAME: &str = "ruff";

View file

@ -1,5 +1,5 @@
---
source: crates/ruff_cli/tests/integration_test.rs
source: crates/ruff/tests/integration_test.rs
info:
program: ruff
args:

View file

@ -1,5 +1,5 @@
---
source: crates/ruff_cli/tests/integration_test.rs
source: crates/ruff/tests/integration_test.rs
info:
program: ruff
args:

View file

@ -1,5 +1,5 @@
---
source: crates/ruff_cli/tests/show_settings.rs
source: crates/ruff/tests/show_settings.rs
info:
program: ruff
args:
@ -10,7 +10,7 @@ info:
success: true
exit_code: 0
----- stdout -----
Resolved settings for: "[BASEPATH]/crates/ruff_cli/resources/test/fixtures/unformatted.py"
Resolved settings for: "[BASEPATH]/crates/ruff/resources/test/fixtures/unformatted.py"
Settings path: "[BASEPATH]/pyproject.toml"
# General Settings

View file

@ -1,5 +0,0 @@
---
source: crates/ruff_cli/src/version.rs
expression: version
---
0.0.0

View file

@ -11,14 +11,14 @@ repository = { workspace = true }
license = { workspace = true }
[dependencies]
ruff_linter = { path = "../ruff_linter", features = ["schemars"] }
ruff_cli = { path = "../ruff_cli" }
ruff = { path = "../ruff" }
ruff_diagnostics = { path = "../ruff_diagnostics" }
ruff_formatter = { path = "../ruff_formatter" }
ruff_linter = { path = "../ruff_linter", features = ["schemars"] }
ruff_notebook = { path = "../ruff_notebook" }
ruff_python_ast = { path = "../ruff_python_ast" }
ruff_python_codegen = { path = "../ruff_python_codegen" }
ruff_python_formatter = { path = "../ruff_python_formatter" }
ruff_notebook = { path = "../ruff_notebook" }
ruff_python_parser = { path = "../ruff_python_parser" }
ruff_python_stdlib = { path = "../ruff_python_stdlib" }
ruff_python_trivia = { path = "../ruff_python_trivia" }

View file

@ -27,8 +27,8 @@ use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::EnvFilter;
use ruff_cli::args::{CliOverrides, FormatArguments, FormatCommand, LogLevelArgs};
use ruff_cli::resolve::resolve;
use ruff::args::{CliOverrides, FormatArguments, FormatCommand, LogLevelArgs};
use ruff::resolve::resolve;
use ruff_formatter::{FormatError, LineWidth, PrintError};
use ruff_linter::logging::LogLevel;
use ruff_linter::settings::types::{FilePattern, FilePatternSet};
@ -67,7 +67,7 @@ fn find_pyproject_config(
Ok(pyproject_config)
}
/// Find files that ruff would check so we can format them. Adapted from `ruff_cli`.
/// Find files that ruff would check so we can format them. Adapted from `ruff`.
#[allow(clippy::type_complexity)]
fn ruff_check_paths<'a>(
pyproject_config: &'a PyprojectConfig,
@ -287,7 +287,7 @@ fn setup_logging(log_level_args: &LogLevelArgs, log_file: Option<&Path>) -> io::
LogLevel::Quiet => tracing::Level::WARN,
LogLevel::Silent => tracing::Level::ERROR,
};
// 1. `RUST_LOG=`, 2. explicit CLI log level, 3. info, the ruff_cli default
// 1. `RUST_LOG=`, 2. explicit CLI log level, 3. info, the ruff default
let filter_layer = EnvFilter::try_from_default_env().unwrap_or_else(|_| {
EnvFilter::builder()
.with_default_directive(log_level.into())
@ -461,7 +461,7 @@ fn format_dev_project(
// TODO(konstin): Respect black's excludes.
// Find files to check (or in this case, format twice). Adapted from ruff_cli
// Find files to check (or in this case, format twice). Adapted from ruff
// First argument is ignored
let (cli, overrides) = parse_cli(files)?;
let pyproject_config = find_pyproject_config(&cli, &overrides)?;

View file

@ -8,7 +8,7 @@ use anyhow::{bail, Context, Result};
use clap::CommandFactory;
use pretty_assertions::StrComparison;
use ruff_cli::args;
use ruff::args;
use crate::generate_all::{Mode, REGENERATE_ALL_COMMAND};
use crate::ROOT_DIR;

View file

@ -4,7 +4,7 @@
use anyhow::Result;
use clap::{Parser, Subcommand};
use ruff_cli::check;
use ruff::check;
use ruff_linter::logging::{set_up_logging, LogLevel};
use std::process::ExitCode;
@ -56,9 +56,9 @@ enum Command {
/// Run a ruff command n times for profiling/benchmarking
Repeat {
#[clap(flatten)]
args: ruff_cli::args::CheckCommand,
args: ruff::args::CheckCommand,
#[clap(flatten)]
log_level_args: ruff_cli::args::LogLevelArgs,
log_level_args: ruff::args::LogLevelArgs,
/// Run this many times
#[clap(long)]
repeat: usize,

View file

@ -8,7 +8,7 @@ behaviors.
Running from the repo root should pick up and enforce the appropriate settings for each package:
```console
∴ cargo run -p ruff_cli -- check crates/ruff_linter/resources/test/project/
∴ cargo run -p ruff -- check crates/ruff_linter/resources/test/project/
crates/ruff_linter/resources/test/project/examples/.dotfiles/script.py:1:1: I001 [*] Import block is un-sorted or un-formatted
crates/ruff_linter/resources/test/project/examples/.dotfiles/script.py:1:8: F401 [*] `numpy` imported but unused
crates/ruff_linter/resources/test/project/examples/.dotfiles/script.py:2:17: F401 [*] `app.app_file` imported but unused
@ -23,7 +23,7 @@ Found 7 errors.
Running from the project directory itself should exhibit the same behavior:
```console
∴ (cd crates/ruff_linter/resources/test/project/ && cargo run -p ruff_cli -- check .)
∴ (cd crates/ruff_linter/resources/test/project/ && cargo run -p ruff -- check .)
examples/.dotfiles/script.py:1:1: I001 [*] Import block is un-sorted or un-formatted
examples/.dotfiles/script.py:1:8: F401 [*] `numpy` imported but unused
examples/.dotfiles/script.py:2:17: F401 [*] `app.app_file` imported but unused
@ -39,7 +39,7 @@ Running from the sub-package directory should exhibit the same behavior, but omi
files:
```console
∴ (cd crates/ruff_linter/resources/test/project/examples/docs && cargo run -p ruff_cli -- check .)
∴ (cd crates/ruff_linter/resources/test/project/examples/docs && cargo run -p ruff -- check .)
docs/file.py:1:1: I001 [*] Import block is un-sorted or un-formatted
docs/file.py:8:5: F841 [*] Local variable `x` is assigned to but never used
Found 2 errors.
@ -50,7 +50,7 @@ Found 2 errors.
file paths from the current working directory:
```console
∴ (cargo run -p ruff_cli -- check --config=crates/ruff_linter/resources/test/project/pyproject.toml crates/ruff_linter/resources/test/project/)
∴ (cargo run -p ruff -- check --config=crates/ruff_linter/resources/test/project/pyproject.toml crates/ruff_linter/resources/test/project/)
crates/ruff_linter/resources/test/project/examples/.dotfiles/script.py:1:8: F401 [*] `numpy` imported but unused
crates/ruff_linter/resources/test/project/examples/.dotfiles/script.py:2:17: F401 [*] `app.app_file` imported but unused
crates/ruff_linter/resources/test/project/examples/docs/docs/concepts/file.py:1:8: F401 [*] `os` imported but unused
@ -68,7 +68,7 @@ Running from a parent directory should "ignore" the `exclude` (hence, `concepts/
included in the output):
```console
∴ (cd crates/ruff_linter/resources/test/project/examples && cargo run -p ruff_cli -- check --config=docs/ruff.toml .)
∴ (cd crates/ruff_linter/resources/test/project/examples && cargo run -p ruff -- check --config=docs/ruff.toml .)
docs/docs/concepts/file.py:5:5: F841 [*] Local variable `x` is assigned to but never used
docs/docs/file.py:1:1: I001 [*] Import block is un-sorted or un-formatted
docs/docs/file.py:8:5: F841 [*] Local variable `x` is assigned to but never used
@ -80,7 +80,7 @@ Found 4 errors.
Passing an excluded directory directly should report errors in the contained files:
```console
∴ cargo run -p ruff_cli -- check crates/ruff_linter/resources/test/project/examples/excluded/
∴ cargo run -p ruff -- check crates/ruff_linter/resources/test/project/examples/excluded/
crates/ruff_linter/resources/test/project/examples/excluded/script.py:1:8: F401 [*] `os` imported but unused
Found 1 error.
[*] 1 potentially fixable with the --fix option.
@ -89,8 +89,8 @@ Found 1 error.
Unless we `--force-exclude`:
```console
∴ cargo run -p ruff_cli -- check crates/ruff_linter/resources/test/project/examples/excluded/ --force-exclude
∴ cargo run -p ruff -- check crates/ruff_linter/resources/test/project/examples/excluded/ --force-exclude
warning: No Python files found under the given path(s)
∴ cargo run -p ruff_cli -- check crates/ruff_linter/resources/test/project/examples/excluded/script.py --force-exclude
∴ cargo run -p ruff -- check crates/ruff_linter/resources/test/project/examples/excluded/script.py --force-exclude
warning: No Python files found under the given path(s)
```

View file

@ -108,7 +108,7 @@ pub(crate) fn is_single_rule_selector(prefix: &RuleCodePrefix) -> bool {
pub enum ParseError {
#[error("Unknown rule selector: `{0}`")]
// TODO(martin): tell the user how to discover rule codes via the CLI once such a command is
// implemented (but that should of course be done only in ruff_cli and not here)
// implemented (but that should of course be done only in ruff and not here)
Unknown(String),
}

View file

@ -895,7 +895,7 @@ impl LintConfiguration {
}
for (from, target) in redirects {
// TODO(martin): This belongs into the ruff_cli crate.
// TODO(martin): This belongs into the ruff crate.
warn_user_once_by_id!(
from,
"`{from}` has been remapped to `{}{}`.",

View file

@ -44,7 +44,7 @@ Changelog = "https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md"
[tool.maturin]
bindings = "bin"
manifest-path = "crates/ruff_cli/Cargo.toml"
manifest-path = "crates/ruff/Cargo.toml"
module-name = "ruff"
python-source = "python"
strip = true
@ -93,7 +93,7 @@ changelog_contributors = false
version_files = [
"README.md",
"docs/integrations.md",
"crates/ruff_cli/Cargo.toml",
"crates/ruff/Cargo.toml",
"crates/ruff_linter/Cargo.toml",
"crates/ruff_shrinking/Cargo.toml",
"scripts/benchmarks/pyproject.toml",

View file

@ -149,7 +149,7 @@ def main() -> None:
"cargo",
"run",
"-p",
"ruff_cli",
"ruff",
"--",
"rule",
"--all",