mirror of https://github.com/astral-sh/ruff
Merge branch 'main' into struct_output
This commit is contained in:
commit
b7fdc76578
|
|
@ -1,12 +1,6 @@
|
|||
[tool.poetry]
|
||||
name = "autobot-ml"
|
||||
version = "0.0.1"
|
||||
description = "An automated code refactoring tool powered by GPT-3."
|
||||
authors = ["Charlie Marsh <charlie.r.marsh@gmail.com>"]
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/charliermarsh/autobot"
|
||||
keywords = ["automation", "refactor", "GPT-3"]
|
||||
[project]
|
||||
name = "ruff"
|
||||
keywords = ["automation", "flake8", "pycodestyle", "pyflakes", "pylint", "clippy"]
|
||||
classifiers = [
|
||||
"Development Status :: 3 - Alpha",
|
||||
"Environment :: Console",
|
||||
|
|
@ -23,35 +17,19 @@ classifiers = [
|
|||
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||
"Topic :: Software Development :: Quality Assurance",
|
||||
]
|
||||
packages = [{ include = "autobot" }]
|
||||
author = "Charlie Marsh"
|
||||
author_email = "charlie.r.marsh@gmail.com"
|
||||
description = "An extremely fast Python linter, written in Rust."
|
||||
requires-python = ">=3.7"
|
||||
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">=3.7,<3.11"
|
||||
openai = "^0.23.0"
|
||||
python-dotenv = "^0.21.0"
|
||||
colorama = "^0.4.5"
|
||||
patch = "^1.16"
|
||||
rich = "^12.5.1"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
mypy = "^0.971"
|
||||
black = "^22.8.0"
|
||||
isort = "^5.10.1"
|
||||
|
||||
[tool.poetry.scripts]
|
||||
autobot = "autobot.main:main"
|
||||
[project.urls]
|
||||
repository = "https://github.com/charliermarsh/ruff"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
requires = ["maturin>=0.13,<0.14"]
|
||||
build-backend = "maturin"
|
||||
|
||||
[tool.black]
|
||||
line-length = 88
|
||||
target-version = ["py310"]
|
||||
extend-exclude = "schematics"
|
||||
preview = true
|
||||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
extend_skip = "schematics"
|
||||
[tool.maturin]
|
||||
bindings = "bin"
|
||||
sdist-include = ["Cargo.lock"]
|
||||
strip = true
|
||||
|
|
|
|||
|
|
@ -143,9 +143,8 @@ fn inner_main() -> Result<ExitCode> {
|
|||
// TODO(charlie): Can we avoid this cast?
|
||||
let paths: Vec<&Path> = cli.files.iter().map(PathBuf::as_path).collect();
|
||||
let mut settings = Settings::from_paths(paths)?;
|
||||
|
||||
let mut printer = Printer::new(BufWriter::new(stdout()), cli.format);
|
||||
|
||||
|
||||
if !cli.select.is_empty() {
|
||||
settings.select(cli.select);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use serde::Deserialize;
|
|||
use crate::checks::CheckCode;
|
||||
use crate::fs;
|
||||
|
||||
pub fn load_config<'a>(paths: impl IntoIterator<Item = &'a Path>) -> Result<(PathBuf, Config)> {
|
||||
pub fn load_config(paths: &[PathBuf]) -> (PathBuf, Config) {
|
||||
match find_project_root(paths) {
|
||||
Some(project_root) => match find_pyproject_toml(&project_root) {
|
||||
Some(path) => {
|
||||
|
|
@ -19,18 +19,18 @@ pub fn load_config<'a>(paths: impl IntoIterator<Item = &'a Path>) -> Result<(Pat
|
|||
.tool
|
||||
.and_then(|tool| tool.ruff)
|
||||
.unwrap_or_default();
|
||||
Ok((project_root, config))
|
||||
(project_root, config)
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Failed to load pyproject.toml: {:?}", e);
|
||||
println!("Falling back to default configuration...");
|
||||
Ok(Default::default())
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
None => Ok(Default::default()),
|
||||
None => Default::default(),
|
||||
},
|
||||
None => Ok(Default::default()),
|
||||
None => Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -70,8 +70,8 @@ fn find_user_pyproject_toml() -> Option<PathBuf> {
|
|||
dirs::home_dir().map(|path| path.join(".ruff"))
|
||||
}
|
||||
|
||||
fn find_project_root<'a>(sources: impl IntoIterator<Item = &'a Path>) -> Option<PathBuf> {
|
||||
if let Some(prefix) = common_path_all(sources) {
|
||||
fn find_project_root(sources: &[PathBuf]) -> Option<PathBuf> {
|
||||
if let Some(prefix) = common_path_all(sources.iter().map(PathBuf::as_path)) {
|
||||
for directory in prefix.ancestors() {
|
||||
if directory.join(".git").is_dir() {
|
||||
return Some(directory.to_path_buf());
|
||||
|
|
@ -90,7 +90,7 @@ fn find_project_root<'a>(sources: impl IntoIterator<Item = &'a Path>) -> Option<
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
|
|
@ -238,8 +238,9 @@ other-attribute = 1
|
|||
|
||||
#[test]
|
||||
fn find_and_parse_pyproject_toml() -> Result<()> {
|
||||
let project_root = find_project_root([Path::new("resources/test/fixtures/__init__.py")])
|
||||
.expect("Unable to find project root.");
|
||||
let project_root =
|
||||
find_project_root(&[PathBuf::from("resources/test/fixtures/__init__.py")])
|
||||
.expect("Unable to find project root.");
|
||||
assert_eq!(project_root, Path::new("resources/test/fixtures"));
|
||||
|
||||
let path = find_pyproject_toml(&project_root).expect("Unable to find pyproject.toml.");
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
use std::collections::BTreeSet;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::Result;
|
||||
use glob::Pattern;
|
||||
|
||||
use crate::checks::CheckCode;
|
||||
|
|
@ -25,8 +24,8 @@ impl Hash for Settings {
|
|||
}
|
||||
|
||||
impl Settings {
|
||||
pub fn from_paths<'a>(paths: impl IntoIterator<Item = &'a Path>) -> Result<Self> {
|
||||
let (project_root, config) = load_config(paths)?;
|
||||
pub fn from_paths(paths: &[PathBuf]) -> Self {
|
||||
let (project_root, config) = load_config(paths);
|
||||
let mut settings = Settings {
|
||||
line_length: config.line_length.unwrap_or(88),
|
||||
exclude: config
|
||||
|
|
@ -89,7 +88,7 @@ impl Settings {
|
|||
if let Some(ignore) = &config.ignore {
|
||||
settings.ignore(ignore);
|
||||
}
|
||||
Ok(settings)
|
||||
settings
|
||||
}
|
||||
|
||||
pub fn select(&mut self, codes: Vec<CheckCode>) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue