Move flake8-to-ruff to a separate crate (#528)

This commit is contained in:
Charlie Marsh 2022-10-31 14:22:07 -04:00 committed by GitHub
parent 7e5e03fb15
commit f3f010cdf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 3096 additions and 23 deletions

View file

@ -27,7 +27,7 @@ jobs:
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- run: cargo build --release
- run: cargo build --all --release
cargo_fmt:
name: "cargo fmt"
@ -49,7 +49,7 @@ jobs:
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- run: cargo fmt --check
- run: cargo fmt --all --check
cargo_clippy:
name: "cargo clippy"
@ -71,7 +71,7 @@ jobs:
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- run: cargo clippy -- -D warnings
- run: cargo clippy --all -- -D warnings
cargo_test:
name: "cargo test"
@ -93,7 +93,7 @@ jobs:
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- run: cargo test
- run: cargo test --all
maturin_build:
name: "maturin build"

16
Cargo.lock generated
View file

@ -918,6 +918,21 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "flate2"
version = "1.0.24"
@ -2208,7 +2223,6 @@ dependencies = [
"codegen",
"colored",
"common-path",
"configparser",
"criterion",
"dirs 4.0.0",
"fern",

View file

@ -1,3 +1,8 @@
[workspace]
members = [
"crates/flake8_to_ruff",
]
[package]
name = "ruff"
version = "0.0.93"
@ -13,7 +18,6 @@ chrono = { version = "0.4.21" }
clap = { version = "4.0.1", features = ["derive"] }
colored = { version = "2.0.0" }
common-path = { version = "1.0.0" }
configparser = { version = "3.0.2" }
dirs = { version = "4.0.0" }
fern = { version = "0.6.1" }
filetime = { version = "0.2.17" }

2964
crates/flake8_to_ruff/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View 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]

View 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).

View 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

View file

@ -1,13 +1,11 @@
//! Utility to generate Ruff's pyproject.toml section from a Flake8 INI file.
use std::collections::HashMap;
use anyhow::Result;
use crate::settings::options::Options;
use crate::settings::pyproject::Pyproject;
use ruff::settings::options::Options;
use ruff::settings::pyproject::Pyproject;
mod parser;
use crate::parser;
pub fn convert(config: HashMap<String, HashMap<String, Option<String>>>) -> Result<Pyproject> {
// Extract the Flake8 section.

View file

@ -0,0 +1,4 @@
#![allow(clippy::collapsible_if, clippy::collapsible_else_if)]
pub mod converter;
mod parser;

View file

@ -6,11 +6,11 @@ use anyhow::Result;
use clap::Parser;
use configparser::ini::Ini;
use ruff::flake8_to_ruff;
use flake8_to_ruff::converter;
#[derive(Parser)]
#[command(
about = "Convert an existing Flake8 configuration to Ruff.",
about = "Convert existing Flake8 configuration to Ruff.",
long_about = None
)]
struct Cli {
@ -28,7 +28,7 @@ fn main() -> Result<()> {
let config = ini.load(cli.file).map_err(|msg| anyhow::anyhow!(msg))?;
// Create the pyproject.toml.
let pyproject = flake8_to_ruff::convert(config)?;
let pyproject = converter::convert(config)?;
println!("{}", toml::to_string(&pyproject)?);
Ok(())

View file

@ -4,8 +4,8 @@ use anyhow::Result;
use once_cell::sync::Lazy;
use regex::Regex;
use crate::checks_gen::CheckCodePrefix;
use crate::settings::types::StrCheckCodePair;
use ruff::checks_gen::CheckCodePrefix;
use ruff::settings::types::StrCheckCodePair;
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 {
use anyhow::Result;
use crate::checks_gen::CheckCodePrefix;
use crate::flake8_to_ruff::parser::{
parse_files_to_codes_mapping, parse_prefix_codes, parse_strings,
};
use crate::settings::types::StrCheckCodePair;
use ruff::checks_gen::CheckCodePrefix;
use ruff::settings::types::StrCheckCodePair;
use crate::parser::{parse_files_to_codes_mapping, parse_prefix_codes, parse_strings};
#[test]
fn it_parses_prefix_codes() {

View file

@ -21,7 +21,7 @@ pub mod check_ast;
mod check_lines;
mod check_tokens;
pub mod checks;
mod checks_gen;
pub mod checks_gen;
pub mod cli;
pub mod code_gen;
mod cst;
@ -31,7 +31,6 @@ mod flake8_builtins;
mod flake8_comprehensions;
mod flake8_print;
mod flake8_quotes;
pub mod flake8_to_ruff;
pub mod fs;
pub mod linter;
pub mod logging;