mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:35:58 +00:00
Move flake8-to-ruff to a separate crate (#528)
This commit is contained in:
parent
7e5e03fb15
commit
f3f010cdf5
12 changed files with 3096 additions and 23 deletions
8
.github/workflows/ci.yaml
vendored
8
.github/workflows/ci.yaml
vendored
|
@ -27,7 +27,7 @@ jobs:
|
||||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||||
${{ runner.os }}-build-
|
${{ runner.os }}-build-
|
||||||
${{ runner.os }}-
|
${{ runner.os }}-
|
||||||
- run: cargo build --release
|
- run: cargo build --all --release
|
||||||
|
|
||||||
cargo_fmt:
|
cargo_fmt:
|
||||||
name: "cargo fmt"
|
name: "cargo fmt"
|
||||||
|
@ -49,7 +49,7 @@ jobs:
|
||||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||||
${{ runner.os }}-build-
|
${{ runner.os }}-build-
|
||||||
${{ runner.os }}-
|
${{ runner.os }}-
|
||||||
- run: cargo fmt --check
|
- run: cargo fmt --all --check
|
||||||
|
|
||||||
cargo_clippy:
|
cargo_clippy:
|
||||||
name: "cargo clippy"
|
name: "cargo clippy"
|
||||||
|
@ -71,7 +71,7 @@ jobs:
|
||||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||||
${{ runner.os }}-build-
|
${{ runner.os }}-build-
|
||||||
${{ runner.os }}-
|
${{ runner.os }}-
|
||||||
- run: cargo clippy -- -D warnings
|
- run: cargo clippy --all -- -D warnings
|
||||||
|
|
||||||
cargo_test:
|
cargo_test:
|
||||||
name: "cargo test"
|
name: "cargo test"
|
||||||
|
@ -93,7 +93,7 @@ jobs:
|
||||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||||
${{ runner.os }}-build-
|
${{ runner.os }}-build-
|
||||||
${{ runner.os }}-
|
${{ runner.os }}-
|
||||||
- run: cargo test
|
- run: cargo test --all
|
||||||
|
|
||||||
maturin_build:
|
maturin_build:
|
||||||
name: "maturin build"
|
name: "maturin build"
|
||||||
|
|
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -918,6 +918,21 @@ version = "0.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
|
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "flake8-to-ruff"
|
||||||
|
version = "0.0.1"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"clap 4.0.15",
|
||||||
|
"configparser",
|
||||||
|
"once_cell",
|
||||||
|
"regex",
|
||||||
|
"ruff",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"toml",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flate2"
|
name = "flate2"
|
||||||
version = "1.0.24"
|
version = "1.0.24"
|
||||||
|
@ -2208,7 +2223,6 @@ dependencies = [
|
||||||
"codegen",
|
"codegen",
|
||||||
"colored",
|
"colored",
|
||||||
"common-path",
|
"common-path",
|
||||||
"configparser",
|
|
||||||
"criterion",
|
"criterion",
|
||||||
"dirs 4.0.0",
|
"dirs 4.0.0",
|
||||||
"fern",
|
"fern",
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"crates/flake8_to_ruff",
|
||||||
|
]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "ruff"
|
name = "ruff"
|
||||||
version = "0.0.93"
|
version = "0.0.93"
|
||||||
|
@ -13,7 +18,6 @@ chrono = { version = "0.4.21" }
|
||||||
clap = { version = "4.0.1", features = ["derive"] }
|
clap = { version = "4.0.1", features = ["derive"] }
|
||||||
colored = { version = "2.0.0" }
|
colored = { version = "2.0.0" }
|
||||||
common-path = { version = "1.0.0" }
|
common-path = { version = "1.0.0" }
|
||||||
configparser = { version = "3.0.2" }
|
|
||||||
dirs = { version = "4.0.0" }
|
dirs = { version = "4.0.0" }
|
||||||
fern = { version = "0.6.1" }
|
fern = { version = "0.6.1" }
|
||||||
filetime = { version = "0.2.17" }
|
filetime = { version = "0.2.17" }
|
||||||
|
|
2964
crates/flake8_to_ruff/Cargo.lock
generated
Normal file
2964
crates/flake8_to_ruff/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
22
crates/flake8_to_ruff/Cargo.toml
Normal file
22
crates/flake8_to_ruff/Cargo.toml
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
[package]
|
||||||
|
name = "flake8-to-ruff"
|
||||||
|
version = "0.0.1"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "flake8_to_ruff"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
anyhow = { version = "1.0.60" }
|
||||||
|
clap = { version = "4.0.1", features = ["derive"] }
|
||||||
|
configparser = { version = "3.0.2" }
|
||||||
|
once_cell = { version = "1.13.1" }
|
||||||
|
regex = { version = "1.6.0" }
|
||||||
|
ruff = {path = "../.."}
|
||||||
|
serde = { version = "1.0.143", features = ["derive"] }
|
||||||
|
serde_json = { version = "1.0.83" }
|
||||||
|
toml = { version = "0.5.9" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
|
||||||
|
[features]
|
35
crates/flake8_to_ruff/README.md
Normal file
35
crates/flake8_to_ruff/README.md
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# flake8-to-ruff
|
||||||
|
|
||||||
|
Convert existing Flake8 configuration files (`setup.cfg`, `tox.ini`, or `.flake8`) for use with
|
||||||
|
[Ruff](https://github.com/charliermarsh/ruff).
|
||||||
|
|
||||||
|
Generates a Ruff-compatible `pyproject.toml` section.
|
||||||
|
|
||||||
|
## Installation and Usage
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
Available as [`flake8-to-ruff`](https://pypi.org/project/flake8-to-ruff/) on PyPI:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
pip install flake8-to-ruff
|
||||||
|
```
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
To run Ruff, try any of the following:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
flake8-to-ruff path/to/setup.cfg
|
||||||
|
flake8-to-ruff path/to/tox.ini
|
||||||
|
flake8-to-ruff path/to/.flake8
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Contributions are welcome and hugely appreciated. To get started, check out the
|
||||||
|
[contributing guidelines](https://github.com/charliermarsh/ruff/blob/main/CONTRIBUTING.md).
|
34
crates/flake8_to_ruff/pyproject.toml
Normal file
34
crates/flake8_to_ruff/pyproject.toml
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
[project]
|
||||||
|
name = "flake8-to-ruff"
|
||||||
|
keywords = ["automation", "flake8", "pycodestyle", "pyflakes", "pylint", "clippy"]
|
||||||
|
classifiers = [
|
||||||
|
"Development Status :: 3 - Alpha",
|
||||||
|
"Environment :: Console",
|
||||||
|
"Intended Audience :: Developers",
|
||||||
|
"License :: OSI Approved :: MIT License",
|
||||||
|
"Operating System :: OS Independent",
|
||||||
|
"Programming Language :: Python",
|
||||||
|
"Programming Language :: Python :: 3.7",
|
||||||
|
"Programming Language :: Python :: 3.8",
|
||||||
|
"Programming Language :: Python :: 3.9",
|
||||||
|
"Programming Language :: Python :: 3.10",
|
||||||
|
"Programming Language :: Python :: 3 :: Only",
|
||||||
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||||
|
"Topic :: Software Development :: Quality Assurance",
|
||||||
|
]
|
||||||
|
author = "Charlie Marsh"
|
||||||
|
author_email = "charlie.r.marsh@gmail.com"
|
||||||
|
description = "Convert existing Flake8 configuration to Ruff."
|
||||||
|
requires-python = ">=3.7"
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
repository = "https://github.com/charliermarsh/ruff#subdirectory=crates/flake8_to_ruff"
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["maturin>=0.13,<0.14"]
|
||||||
|
build-backend = "maturin"
|
||||||
|
|
||||||
|
[tool.maturin]
|
||||||
|
bindings = "bin"
|
||||||
|
sdist-include = ["Cargo.lock"]
|
||||||
|
strip = true
|
|
@ -1,13 +1,11 @@
|
||||||
//! Utility to generate Ruff's pyproject.toml section from a Flake8 INI file.
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use crate::settings::options::Options;
|
use ruff::settings::options::Options;
|
||||||
use crate::settings::pyproject::Pyproject;
|
use ruff::settings::pyproject::Pyproject;
|
||||||
|
|
||||||
mod parser;
|
use crate::parser;
|
||||||
|
|
||||||
pub fn convert(config: HashMap<String, HashMap<String, Option<String>>>) -> Result<Pyproject> {
|
pub fn convert(config: HashMap<String, HashMap<String, Option<String>>>) -> Result<Pyproject> {
|
||||||
// Extract the Flake8 section.
|
// Extract the Flake8 section.
|
4
crates/flake8_to_ruff/src/lib.rs
Normal file
4
crates/flake8_to_ruff/src/lib.rs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
#![allow(clippy::collapsible_if, clippy::collapsible_else_if)]
|
||||||
|
|
||||||
|
pub mod converter;
|
||||||
|
mod parser;
|
|
@ -6,11 +6,11 @@ use anyhow::Result;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use configparser::ini::Ini;
|
use configparser::ini::Ini;
|
||||||
|
|
||||||
use ruff::flake8_to_ruff;
|
use flake8_to_ruff::converter;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(
|
#[command(
|
||||||
about = "Convert an existing Flake8 configuration to Ruff.",
|
about = "Convert existing Flake8 configuration to Ruff.",
|
||||||
long_about = None
|
long_about = None
|
||||||
)]
|
)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
|
@ -28,7 +28,7 @@ fn main() -> Result<()> {
|
||||||
let config = ini.load(cli.file).map_err(|msg| anyhow::anyhow!(msg))?;
|
let config = ini.load(cli.file).map_err(|msg| anyhow::anyhow!(msg))?;
|
||||||
|
|
||||||
// Create the pyproject.toml.
|
// Create the pyproject.toml.
|
||||||
let pyproject = flake8_to_ruff::convert(config)?;
|
let pyproject = converter::convert(config)?;
|
||||||
println!("{}", toml::to_string(&pyproject)?);
|
println!("{}", toml::to_string(&pyproject)?);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
|
@ -4,8 +4,8 @@ use anyhow::Result;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use crate::checks_gen::CheckCodePrefix;
|
use ruff::checks_gen::CheckCodePrefix;
|
||||||
use crate::settings::types::StrCheckCodePair;
|
use ruff::settings::types::StrCheckCodePair;
|
||||||
|
|
||||||
static COMMA_SEPARATED_LIST_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"[,\s]").unwrap());
|
static COMMA_SEPARATED_LIST_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"[,\s]").unwrap());
|
||||||
|
|
||||||
|
@ -170,11 +170,10 @@ pub fn parse_files_to_codes_mapping(value: &str) -> Result<Vec<StrCheckCodePair>
|
||||||
mod tests {
|
mod tests {
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use crate::checks_gen::CheckCodePrefix;
|
use ruff::checks_gen::CheckCodePrefix;
|
||||||
use crate::flake8_to_ruff::parser::{
|
use ruff::settings::types::StrCheckCodePair;
|
||||||
parse_files_to_codes_mapping, parse_prefix_codes, parse_strings,
|
|
||||||
};
|
use crate::parser::{parse_files_to_codes_mapping, parse_prefix_codes, parse_strings};
|
||||||
use crate::settings::types::StrCheckCodePair;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_parses_prefix_codes() {
|
fn it_parses_prefix_codes() {
|
|
@ -21,7 +21,7 @@ pub mod check_ast;
|
||||||
mod check_lines;
|
mod check_lines;
|
||||||
mod check_tokens;
|
mod check_tokens;
|
||||||
pub mod checks;
|
pub mod checks;
|
||||||
mod checks_gen;
|
pub mod checks_gen;
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
pub mod code_gen;
|
pub mod code_gen;
|
||||||
mod cst;
|
mod cst;
|
||||||
|
@ -31,7 +31,6 @@ mod flake8_builtins;
|
||||||
mod flake8_comprehensions;
|
mod flake8_comprehensions;
|
||||||
mod flake8_print;
|
mod flake8_print;
|
||||||
mod flake8_quotes;
|
mod flake8_quotes;
|
||||||
pub mod flake8_to_ruff;
|
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
pub mod linter;
|
pub mod linter;
|
||||||
pub mod logging;
|
pub mod logging;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue