mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 22:55:08 +00:00
Add cargo +nightly dev generate-all (#1404)
This commit is contained in:
parent
9106d5338b
commit
b4dbe62da0
11 changed files with 60 additions and 24 deletions
8
.github/workflows/ci.yaml
vendored
8
.github/workflows/ci.yaml
vendored
|
@ -38,15 +38,15 @@ jobs:
|
||||||
- run: cargo build --all --release
|
- run: cargo build --all --release
|
||||||
- run: ./target/release/ruff_dev generate-rules-table
|
- run: ./target/release/ruff_dev generate-rules-table
|
||||||
- run: ./target/release/ruff_dev generate-options
|
- run: ./target/release/ruff_dev generate-options
|
||||||
- run: git diff --quiet README.md || echo "::error file=README.md::This file is outdated. You may have to rerun 'cargo dev generate-options' and/or 'cargo dev generate-rules-table'."
|
- run: git diff --quiet README.md || echo "::error file=README.md::This file is outdated. Run 'cargo +nightly dev generate-all'."
|
||||||
- run: ./target/release/ruff_dev generate-check-code-prefix
|
- run: ./target/release/ruff_dev generate-check-code-prefix
|
||||||
- run: git diff --quiet src/checks_gen.rs || echo "::error file=src/checks_gen.rs::This file is outdated. You may have to rerun 'cargo dev generate-check-code-prefix'."
|
- run: git diff --quiet src/checks_gen.rs || echo "::error file=src/checks_gen.rs::This file is outdated. Run 'cargo +nightly dev generate-all'."
|
||||||
- run: git diff --exit-code -- README.md src/checks_gen.rs
|
- run: git diff --exit-code -- README.md src/checks_gen.rs
|
||||||
- run: ./target/release/ruff_dev generate-json-schema
|
- run: ./target/release/ruff_dev generate-json-schema
|
||||||
- run: git diff --quiet ruff.schema.json || echo "::error file=ruff.schema.json::This file is outdated. You may have to rerun 'cargo dev generate-json-schema'."
|
- run: git diff --quiet ruff.schema.json || echo "::error file=ruff.schema.json::This file is outdated. Run 'cargo +nightly dev generate-all'."
|
||||||
- run: git diff --exit-code -- ruff.schema.json
|
- run: git diff --exit-code -- ruff.schema.json
|
||||||
- run: ./target/release/ruff_dev generate-playground-options
|
- run: ./target/release/ruff_dev generate-playground-options
|
||||||
- run: git diff --quiet playground/src/ruff_options.rs || echo "::error file=playground/src/ruff_options.ts::This file is outdated. You may have to rerun 'cargo dev generate-playground-options'."
|
- run: git diff --quiet playground/src/ruff_options.rs || echo "::error file=playground/src/ruff_options.ts::This file is outdated. Run 'cargo +nightly dev generate-all'."
|
||||||
- run: git diff --exit-code -- README.md src/checks_gen.rs playground/src/ruff_options.ts
|
- run: git diff --exit-code -- README.md src/checks_gen.rs playground/src/ruff_options.ts
|
||||||
|
|
||||||
cargo-fmt:
|
cargo-fmt:
|
||||||
|
|
|
@ -59,9 +59,9 @@ pattern implemented therein.
|
||||||
|
|
||||||
To trigger the rule, you'll likely want to augment the logic in `src/check_ast.rs`, which defines
|
To trigger the rule, you'll likely want to augment the logic in `src/check_ast.rs`, which defines
|
||||||
the Python AST visitor, responsible for iterating over the abstract syntax tree and collecting
|
the Python AST visitor, responsible for iterating over the abstract syntax tree and collecting
|
||||||
lint-rule violations as it goes. If you need to inspect the AST, you can run `cargo dev print-ast`
|
lint-rule violations as it goes. If you need to inspect the AST, you can run
|
||||||
with a Python file. Grep for the `Check::new` invocations to understand how other, similar rules
|
`cargo +nightly dev print-ast` with a Python file. Grep for the `Check::new` invocations to
|
||||||
are implemented.
|
understand how other, similar rules are implemented.
|
||||||
|
|
||||||
To add a test fixture, create a file under `resources/test/fixtures`, named to match the `CheckCode`
|
To add a test fixture, create a file under `resources/test/fixtures`, named to match the `CheckCode`
|
||||||
you defined earlier (e.g., `E402.py`). This file should contain a variety of violations and
|
you defined earlier (e.g., `E402.py`). This file should contain a variety of violations and
|
||||||
|
@ -79,9 +79,7 @@ Then, run `cargo test`. Your test will fail, but you'll be prompted to follow-up
|
||||||
`cargo insta review`. Accept the generated snapshot, then commit the snapshot file alongside the
|
`cargo insta review`. Accept the generated snapshot, then commit the snapshot file alongside the
|
||||||
rest of your changes.
|
rest of your changes.
|
||||||
|
|
||||||
Finally, to update the documentation, run `cargo dev generate-rules-table` from the repo root. To
|
Finally, regenerate the documentation and generated code with `cargo +nightly dev generate-all`.
|
||||||
update the generated prefix map, run `cargo +nightly dev generate-check-code-prefix`. Both of these commands
|
|
||||||
should be run whenever a new check is added to the codebase.
|
|
||||||
|
|
||||||
### Example: Adding a new configuration option
|
### Example: Adding a new configuration option
|
||||||
|
|
||||||
|
@ -105,8 +103,7 @@ You may also want to add the new configuration option to the `flake8-to-ruff` to
|
||||||
responsible for converting `flake8` configuration files to Ruff's TOML format. This logic
|
responsible for converting `flake8` configuration files to Ruff's TOML format. This logic
|
||||||
lives in `flake8_to_ruff/src/converter.rs`.
|
lives in `flake8_to_ruff/src/converter.rs`.
|
||||||
|
|
||||||
Run `cargo dev generate-options` to update the documentation for supported configuration options,
|
Finally, regenerate the documentation and generated code with `cargo +nightly dev generate-all`.
|
||||||
and `cargo dev generate-json-schema` to update the JSON schema for `tool.ruff` in `pyproject.toml`.
|
|
||||||
|
|
||||||
## Release process
|
## Release process
|
||||||
|
|
||||||
|
|
35
ruff_dev/src/generate_all.rs
Normal file
35
ruff_dev/src/generate_all.rs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
//! Run all code and documentation generation steps.
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use clap::Args;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
generate_check_code_prefix, generate_json_schema, generate_options,
|
||||||
|
generate_playground_options, generate_rules_table,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[derive(Args)]
|
||||||
|
pub struct Cli {
|
||||||
|
/// Write the generated artifacts to stdout (rather than to the filesystem).
|
||||||
|
#[arg(long)]
|
||||||
|
dry_run: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main(cli: &Cli) -> Result<()> {
|
||||||
|
generate_check_code_prefix::main(&generate_check_code_prefix::Cli {
|
||||||
|
dry_run: cli.dry_run,
|
||||||
|
})?;
|
||||||
|
generate_json_schema::main(&generate_json_schema::Cli {
|
||||||
|
dry_run: cli.dry_run,
|
||||||
|
})?;
|
||||||
|
generate_rules_table::main(&generate_rules_table::Cli {
|
||||||
|
dry_run: cli.dry_run,
|
||||||
|
})?;
|
||||||
|
generate_options::main(&generate_options::Cli {
|
||||||
|
dry_run: cli.dry_run,
|
||||||
|
})?;
|
||||||
|
generate_playground_options::main(&generate_playground_options::Cli {
|
||||||
|
dry_run: cli.dry_run,
|
||||||
|
})?;
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ pub struct Cli {
|
||||||
/// Write the generated source code to stdout (rather than to
|
/// Write the generated source code to stdout (rather than to
|
||||||
/// `src/checks_gen.rs`).
|
/// `src/checks_gen.rs`).
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
dry_run: bool,
|
pub(crate) dry_run: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main(cli: &Cli) -> Result<()> {
|
pub fn main(cli: &Cli) -> Result<()> {
|
||||||
|
|
|
@ -10,7 +10,7 @@ use schemars::schema_for;
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
/// Write the generated table to stdout (rather than to `ruff.schema.json`).
|
/// Write the generated table to stdout (rather than to `ruff.schema.json`).
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
dry_run: bool,
|
pub(crate) dry_run: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main(cli: &Cli) -> Result<()> {
|
pub fn main(cli: &Cli) -> Result<()> {
|
||||||
|
|
|
@ -18,7 +18,7 @@ const END_PRAGMA: &str = "<!-- End auto-generated options sections. -->";
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
/// Write the generated table to stdout (rather than to `README.md`).
|
/// Write the generated table to stdout (rather than to `README.md`).
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
dry_run: bool,
|
pub(crate) dry_run: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_field(output: &mut String, field: &OptionField, group_name: Option<&str>) {
|
fn emit_field(output: &mut String, field: &OptionField, group_name: Option<&str>) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ use ruff::settings::options_base::{ConfigurationOptions, OptionEntry, OptionFiel
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
/// Write the generated table to stdout (rather than to `TODO`).
|
/// Write the generated table to stdout (rather than to `TODO`).
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
dry_run: bool,
|
pub(crate) dry_run: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn emit_field(output: &mut String, field: &OptionField) {
|
fn emit_field(output: &mut String, field: &OptionField) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ const TOC_END_PRAGMA: &str = "<!-- End auto-generated table of contents. -->";
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
/// Write the generated table to stdout (rather than to `README.md`).
|
/// Write the generated table to stdout (rather than to `README.md`).
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
dry_run: bool,
|
pub(crate) dry_run: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main(cli: &Cli) -> Result<()> {
|
pub fn main(cli: &Cli) -> Result<()> {
|
||||||
|
|
|
@ -11,12 +11,13 @@
|
||||||
clippy::too_many_lines
|
clippy::too_many_lines
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
pub mod generate_all;
|
||||||
pub mod generate_check_code_prefix;
|
pub mod generate_check_code_prefix;
|
||||||
pub mod generate_json_schema;
|
pub mod generate_json_schema;
|
||||||
pub mod generate_options;
|
pub mod generate_options;
|
||||||
pub mod generate_playground_options;
|
pub mod generate_playground_options;
|
||||||
pub mod generate_rules_table;
|
pub mod generate_rules_table;
|
||||||
pub mod generate_source_code;
|
|
||||||
pub mod print_ast;
|
pub mod print_ast;
|
||||||
pub mod print_cst;
|
pub mod print_cst;
|
||||||
pub mod print_tokens;
|
pub mod print_tokens;
|
||||||
|
pub mod round_trip;
|
||||||
|
|
|
@ -14,9 +14,9 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use ruff_dev::{
|
use ruff_dev::{
|
||||||
generate_check_code_prefix, generate_json_schema, generate_options,
|
generate_all, generate_check_code_prefix, generate_json_schema, generate_options,
|
||||||
generate_playground_options, generate_rules_table, generate_source_code, print_ast, print_cst,
|
generate_playground_options, generate_rules_table, print_ast, print_cst, print_tokens,
|
||||||
print_tokens,
|
round_trip,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
@ -29,6 +29,8 @@ struct Cli {
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum Commands {
|
enum Commands {
|
||||||
|
/// Run all code and documentation generation steps.
|
||||||
|
GenerateAll(generate_all::Cli),
|
||||||
/// Generate the `CheckCodePrefix` enum.
|
/// Generate the `CheckCodePrefix` enum.
|
||||||
GenerateCheckCodePrefix(generate_check_code_prefix::Cli),
|
GenerateCheckCodePrefix(generate_check_code_prefix::Cli),
|
||||||
/// Generate JSON schema for the TOML configuration file.
|
/// Generate JSON schema for the TOML configuration file.
|
||||||
|
@ -40,28 +42,29 @@ enum Commands {
|
||||||
/// Generate typescript file defining options to be used by the web
|
/// Generate typescript file defining options to be used by the web
|
||||||
/// playground.
|
/// playground.
|
||||||
GeneratePlaygroundOptions(generate_playground_options::Cli),
|
GeneratePlaygroundOptions(generate_playground_options::Cli),
|
||||||
/// Run round-trip source code generation on a given Python file.
|
|
||||||
GenerateSourceCode(generate_source_code::Cli),
|
|
||||||
/// Print the AST for a given Python file.
|
/// Print the AST for a given Python file.
|
||||||
PrintAST(print_ast::Cli),
|
PrintAST(print_ast::Cli),
|
||||||
/// Print the LibCST CST for a given Python file.
|
/// Print the LibCST CST for a given Python file.
|
||||||
PrintCST(print_cst::Cli),
|
PrintCST(print_cst::Cli),
|
||||||
/// Print the token stream for a given Python file.
|
/// Print the token stream for a given Python file.
|
||||||
PrintTokens(print_tokens::Cli),
|
PrintTokens(print_tokens::Cli),
|
||||||
|
/// Run round-trip source code generation on a given Python file.
|
||||||
|
RoundTrip(round_trip::Cli),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
match &cli.command {
|
match &cli.command {
|
||||||
|
Commands::GenerateAll(args) => generate_all::main(args)?,
|
||||||
Commands::GenerateCheckCodePrefix(args) => generate_check_code_prefix::main(args)?,
|
Commands::GenerateCheckCodePrefix(args) => generate_check_code_prefix::main(args)?,
|
||||||
Commands::GenerateJSONSchema(args) => generate_json_schema::main(args)?,
|
Commands::GenerateJSONSchema(args) => generate_json_schema::main(args)?,
|
||||||
Commands::GenerateRulesTable(args) => generate_rules_table::main(args)?,
|
Commands::GenerateRulesTable(args) => generate_rules_table::main(args)?,
|
||||||
Commands::GenerateSourceCode(args) => generate_source_code::main(args)?,
|
|
||||||
Commands::GenerateOptions(args) => generate_options::main(args)?,
|
Commands::GenerateOptions(args) => generate_options::main(args)?,
|
||||||
Commands::GeneratePlaygroundOptions(args) => generate_playground_options::main(args)?,
|
Commands::GeneratePlaygroundOptions(args) => generate_playground_options::main(args)?,
|
||||||
Commands::PrintAST(args) => print_ast::main(args)?,
|
Commands::PrintAST(args) => print_ast::main(args)?,
|
||||||
Commands::PrintCST(args) => print_cst::main(args)?,
|
Commands::PrintCST(args) => print_cst::main(args)?,
|
||||||
Commands::PrintTokens(args) => print_tokens::main(args)?,
|
Commands::PrintTokens(args) => print_tokens::main(args)?,
|
||||||
|
Commands::RoundTrip(args) => round_trip::main(args)?,
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue