Skip to content

Commit

Permalink
Rename ruff_cli crate to ruff (#9557)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
charliermarsh authored Jan 16, 2024
1 parent 45d374d commit 8118d29
Show file tree
Hide file tree
Showing 64 changed files with 84 additions and 87 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/.*|
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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),
Expand Down
70 changes: 35 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions crates/ruff_cli/Cargo.toml → crates/ruff/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "ruff_cli"
name = "ruff"
version = "0.1.13"
publish = false
authors = { workspace = true }
Expand All @@ -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" }
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion crates/ruff_cli/src/args.rs → crates/ruff/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions crates/ruff_cli/src/bin/ruff.rs → crates/ruff/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: crates/ruff/src/version.rs
expression: version
---
0.0.0
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: crates/ruff_cli/src/version.rs
source: crates/ruff/src/version.rs
expression: version
---
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: crates/ruff_cli/tests/integration_test.rs
source: crates/ruff/tests/integration_test.rs
info:
program: ruff
args:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: crates/ruff_cli/tests/integration_test.rs
source: crates/ruff/tests/integration_test.rs
info:
program: ruff
args:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: crates/ruff_cli/tests/show_settings.rs
source: crates/ruff/tests/show_settings.rs
info:
program: ruff
args:
Expand All @@ -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
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions crates/ruff_dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
10 changes: 5 additions & 5 deletions crates/ruff_dev/src/format_dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_dev/src/generate_cli_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit 8118d29

Please sign in to comment.