mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 13:05:06 +00:00
Rename ruff_python
crate to ruff_python_stdlib
(#3354)
In hindsight, `ruff_python` is too general. A good giveaway is that it's actually a prefix of some other crates. The intent of this crate is to reimplement pieces of the Python standard library and CPython itself, so `ruff_python_stdlib` feels appropriate.
This commit is contained in:
parent
348a38d261
commit
d1c48016eb
41 changed files with 88 additions and 73 deletions
22
Cargo.lock
generated
22
Cargo.lock
generated
|
@ -2000,7 +2000,7 @@ dependencies = [
|
|||
"result-like",
|
||||
"ruff_cache",
|
||||
"ruff_macros",
|
||||
"ruff_python",
|
||||
"ruff_python_stdlib",
|
||||
"ruff_rustpython",
|
||||
"rustc-hash",
|
||||
"rustpython-common",
|
||||
|
@ -2120,15 +2120,6 @@ dependencies = [
|
|||
"textwrap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruff_python"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruff_python_formatter"
|
||||
version = "0.0.0"
|
||||
|
@ -2140,7 +2131,7 @@ dependencies = [
|
|||
"itertools",
|
||||
"once_cell",
|
||||
"ruff_formatter",
|
||||
"ruff_python",
|
||||
"ruff_python_stdlib",
|
||||
"ruff_rustpython",
|
||||
"ruff_testing_macros",
|
||||
"ruff_text_size",
|
||||
|
@ -2151,6 +2142,15 @@ dependencies = [
|
|||
"test-case",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruff_python_stdlib"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ruff_rustpython"
|
||||
version = "0.0.0"
|
||||
|
|
|
@ -5,13 +5,14 @@ edition = { workspace = true }
|
|||
rust-version = { workspace = true }
|
||||
|
||||
[dependencies]
|
||||
ruff = { path = "../ruff", default-features = false }
|
||||
|
||||
anyhow = { workspace = true }
|
||||
clap = { workspace = true }
|
||||
colored = { workspace = true }
|
||||
configparser = { version = "3.0.2" }
|
||||
once_cell = { workspace = true }
|
||||
regex = { workspace = true }
|
||||
ruff = { path = "../ruff", default-features = false }
|
||||
rustc-hash = { workspace = true }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
|
|
@ -16,10 +16,10 @@ crate-type = ["cdylib", "rlib"]
|
|||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
ruff_macros = { path = "../ruff_macros" }
|
||||
ruff_python = { path = "../ruff_python" }
|
||||
ruff_rustpython = { path = "../ruff_rustpython" }
|
||||
ruff_cache = { path = "../ruff_cache" }
|
||||
ruff_macros = { path = "../ruff_macros" }
|
||||
ruff_python_stdlib = { path = "../ruff_python_stdlib" }
|
||||
ruff_rustpython = { path = "../ruff_rustpython" }
|
||||
|
||||
anyhow = { workspace = true }
|
||||
bisection = { version = "0.1.0" }
|
||||
|
|
|
@ -5,7 +5,7 @@ use rustc_hash::FxHashMap;
|
|||
use rustpython_parser::ast::{Expr, Stmt};
|
||||
use smallvec::smallvec;
|
||||
|
||||
use ruff_python::typing::TYPING_EXTENSIONS;
|
||||
use ruff_python_stdlib::typing::TYPING_EXTENSIONS;
|
||||
|
||||
use crate::ast::helpers::{collect_call_path, from_relative_import, Exceptions};
|
||||
use crate::ast::types::{Binding, BindingKind, CallPath, ExecutionContext, RefEquality, Scope};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ruff_python::typing::{PEP_585_BUILTINS_ELIGIBLE, PEP_593_SUBSCRIPTS, SUBSCRIPTS};
|
||||
use ruff_python_stdlib::typing::{PEP_585_BUILTINS_ELIGIBLE, PEP_593_SUBSCRIPTS, SUBSCRIPTS};
|
||||
use rustpython_parser::ast::{Expr, ExprKind};
|
||||
|
||||
use crate::ast::types::CallPath;
|
||||
|
|
|
@ -13,7 +13,7 @@ use rustpython_parser::ast::{
|
|||
Suite,
|
||||
};
|
||||
|
||||
use ruff_python::builtins::{BUILTINS, MAGIC_GLOBALS};
|
||||
use ruff_python_stdlib::builtins::{BUILTINS, MAGIC_GLOBALS};
|
||||
|
||||
use crate::ast::context::Context;
|
||||
use crate::ast::helpers::{binding_range, extract_handled_exceptions, to_module_path, Exceptions};
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::identifiers::{is_identifier, is_mangled_private};
|
||||
use ruff_python::keyword::KWLIST;
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprContext, ExprKind, Location};
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_stdlib::identifiers::{is_identifier, is_mangled_private};
|
||||
use ruff_python_stdlib::keyword::KWLIST;
|
||||
|
||||
use crate::ast::helpers::unparse_expr;
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use rustpython_parser::ast::{ExprKind, Stmt};
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::str::is_lower;
|
||||
use ruff_python_stdlib::str::is_lower;
|
||||
|
||||
use crate::ast::helpers::RaiseStatementVisitor;
|
||||
use crate::ast::visitor;
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::identifiers::{is_identifier, is_mangled_private};
|
||||
use ruff_python::keyword::KWLIST;
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprContext, ExprKind, Location, Stmt, StmtKind};
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_stdlib::identifiers::{is_identifier, is_mangled_private};
|
||||
use ruff_python_stdlib::keyword::KWLIST;
|
||||
|
||||
use crate::ast::helpers::unparse_stmt;
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::builtins::BUILTINS;
|
||||
use rustpython_parser::ast::Located;
|
||||
|
||||
use super::types::ShadowingType;
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_stdlib::builtins::BUILTINS;
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::registry::{Diagnostic, DiagnosticKind};
|
||||
use crate::violation::Violation;
|
||||
|
||||
use super::types::ShadowingType;
|
||||
|
||||
/// ## What it does
|
||||
/// Checks for variable (and function) assignments that use the same name
|
||||
/// as a builtin.
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use log::error;
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::identifiers::is_identifier;
|
||||
use ruff_python::keyword::KWLIST;
|
||||
use rustc_hash::FxHashSet;
|
||||
use rustpython_parser::ast::{Boolop, Constant, Expr, ExprKind, Keyword, Stmt, StmtKind};
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_stdlib::identifiers::is_identifier;
|
||||
use ruff_python_stdlib::keyword::KWLIST;
|
||||
|
||||
use crate::ast::comparable::ComparableExpr;
|
||||
use crate::ast::helpers::{match_trailing_comment, unparse_expr};
|
||||
use crate::ast::types::{Range, RefEquality};
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use anyhow::Result;
|
||||
use libcst_native::{Codegen, CodegenState, CompOp};
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::str::{self};
|
||||
use rustpython_parser::ast::{Cmpop, Expr, ExprKind, Unaryop};
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_stdlib::str::{self};
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::cst::matchers::{match_comparison, match_expression};
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use ruff_macros::{derive_message_formats, violation, CacheKey};
|
||||
use ruff_python::identifiers::is_module_name;
|
||||
use rustpython_parser::ast::{Stmt, StmtKind};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation, CacheKey};
|
||||
use ruff_python_stdlib::identifiers::is_module_name;
|
||||
|
||||
use crate::ast::helpers::{create_stmt, from_relative_import, unparse_stmt};
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::path::{Path, PathBuf};
|
|||
|
||||
use log::debug;
|
||||
use ruff_macros::CacheKey;
|
||||
use ruff_python::sys::KNOWN_STANDARD_LIBRARY;
|
||||
use ruff_python_stdlib::sys::KNOWN_STANDARD_LIBRARY;
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum_macros::EnumIter;
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::cmp::Ordering;
|
|||
use std::collections::BTreeSet;
|
||||
|
||||
use crate::rules::isort::types::Importable;
|
||||
use ruff_python::str;
|
||||
use ruff_python_stdlib::str;
|
||||
|
||||
use super::settings::RelativeImportsOrder;
|
||||
use super::types::EitherImport::{Import, ImportFrom};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use itertools::Itertools;
|
||||
use ruff_python::str::{is_lower, is_upper};
|
||||
use ruff_python_stdlib::str::{is_lower, is_upper};
|
||||
use rustpython_parser::ast::{ExprKind, Stmt, StmtKind};
|
||||
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::str::{self};
|
||||
use rustpython_parser::ast::Stmt;
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_stdlib::str::{self};
|
||||
|
||||
use crate::ast::helpers::identifier_range;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::rules::pep8_naming::helpers;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::str::{self};
|
||||
use rustpython_parser::ast::Stmt;
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_stdlib::str::{self};
|
||||
|
||||
use crate::ast::helpers::identifier_range;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::rules::pep8_naming::helpers;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::str;
|
||||
use rustpython_parser::ast::Stmt;
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_stdlib::str;
|
||||
|
||||
use crate::ast::helpers::identifier_range;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::rules::pep8_naming::helpers;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::str;
|
||||
use rustpython_parser::ast::Stmt;
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_stdlib::str;
|
||||
|
||||
use crate::ast::helpers::identifier_range;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::source_code::Locator;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::path::Path;
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::identifiers::is_module_name;
|
||||
use ruff_python_stdlib::identifiers::is_module_name;
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::registry::Diagnostic;
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::str;
|
||||
use rustpython_parser::ast::Stmt;
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_stdlib::str;
|
||||
|
||||
use crate::ast::helpers::identifier_range;
|
||||
use crate::registry::Diagnostic;
|
||||
use crate::source_code::Locator;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::collections::BTreeSet;
|
||||
|
||||
use ruff_python::str::{
|
||||
use ruff_python_stdlib::str::{
|
||||
SINGLE_QUOTE_PREFIXES, SINGLE_QUOTE_SUFFIXES, TRIPLE_QUOTE_PREFIXES, TRIPLE_QUOTE_SUFFIXES,
|
||||
};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::str::TRIPLE_QUOTE_PREFIXES;
|
||||
use ruff_python_stdlib::str::TRIPLE_QUOTE_PREFIXES;
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::ast::whitespace::LinesWithTrailingNewline;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use anyhow::{bail, Result};
|
||||
use libcst_native::{Call, Codegen, CodegenState, Dict, DictElement, Expression};
|
||||
use ruff_python::str::strip_quotes_and_prefixes;
|
||||
use ruff_python_stdlib::str::strip_quotes_and_prefixes;
|
||||
use rustpython_parser::ast::{Excepthandler, Expr};
|
||||
use rustpython_parser::{lexer, Mode, Tok};
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use itertools::Itertools;
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::future::ALL_FEATURE_NAMES;
|
||||
use rustpython_parser::ast::Alias;
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_stdlib::future::ALL_FEATURE_NAMES;
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::checkers::ast::Checker;
|
||||
use crate::registry::Diagnostic;
|
||||
|
|
|
@ -3,8 +3,8 @@ use log::debug;
|
|||
use rustpython_parser::ast::{Constant, Expr, ExprContext, ExprKind, Keyword, Stmt, StmtKind};
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::identifiers::is_identifier;
|
||||
use ruff_python::keyword::KWLIST;
|
||||
use ruff_python_stdlib::identifiers::is_identifier;
|
||||
use ruff_python_stdlib::keyword::KWLIST;
|
||||
|
||||
use crate::ast::helpers::{create_expr, create_stmt, unparse_stmt};
|
||||
use crate::ast::types::Range;
|
||||
|
|
|
@ -3,8 +3,8 @@ use log::debug;
|
|||
use rustpython_parser::ast::{Constant, Expr, ExprContext, ExprKind, Keyword, Stmt, StmtKind};
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::identifiers::is_identifier;
|
||||
use ruff_python::keyword::KWLIST;
|
||||
use ruff_python_stdlib::identifiers::is_identifier;
|
||||
use ruff_python_stdlib::keyword::KWLIST;
|
||||
|
||||
use crate::ast::helpers::{create_expr, create_stmt, unparse_stmt};
|
||||
use crate::ast::types::Range;
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python::identifiers::is_identifier;
|
||||
use ruff_python::keyword::KWLIST;
|
||||
use rustpython_common::cformat::{
|
||||
CConversionFlags, CFormatPart, CFormatPrecision, CFormatQuantity, CFormatString,
|
||||
};
|
||||
use rustpython_parser::ast::{Constant, Expr, ExprKind, Location};
|
||||
use rustpython_parser::{lexer, Mode, Tok};
|
||||
|
||||
use ruff_macros::{derive_message_formats, violation};
|
||||
use ruff_python_stdlib::identifiers::is_identifier;
|
||||
use ruff_python_stdlib::keyword::KWLIST;
|
||||
|
||||
use crate::ast::types::Range;
|
||||
use crate::ast::whitespace::indentation;
|
||||
use crate::checkers::ast::Checker;
|
||||
|
|
|
@ -7,7 +7,7 @@ rust-version = { workspace = true }
|
|||
|
||||
[dependencies]
|
||||
ruff_formatter = { path = "../ruff_formatter" }
|
||||
ruff_python = { path = "../ruff_python" }
|
||||
ruff_python_stdlib = { path = "../ruff_python_stdlib" }
|
||||
ruff_rustpython = { path = "../ruff_rustpython" }
|
||||
ruff_text_size = { path = "../ruff_text_size" }
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@ use crate::core::types::Range;
|
|||
/// Return the leading quote for a string or byte literal (e.g., `"""`).
|
||||
pub fn leading_quote(content: &str) -> Option<&str> {
|
||||
if let Some(first_line) = content.lines().next() {
|
||||
for pattern in ruff_python::str::TRIPLE_QUOTE_PREFIXES
|
||||
for pattern in ruff_python_stdlib::str::TRIPLE_QUOTE_PREFIXES
|
||||
.iter()
|
||||
.chain(ruff_python::bytes::TRIPLE_QUOTE_PREFIXES)
|
||||
.chain(ruff_python::str::SINGLE_QUOTE_PREFIXES)
|
||||
.chain(ruff_python::bytes::SINGLE_QUOTE_PREFIXES)
|
||||
.chain(ruff_python_stdlib::bytes::TRIPLE_QUOTE_PREFIXES)
|
||||
.chain(ruff_python_stdlib::str::SINGLE_QUOTE_PREFIXES)
|
||||
.chain(ruff_python_stdlib::bytes::SINGLE_QUOTE_PREFIXES)
|
||||
{
|
||||
if first_line.starts_with(pattern) {
|
||||
return Some(pattern);
|
||||
|
@ -22,9 +22,9 @@ pub fn leading_quote(content: &str) -> Option<&str> {
|
|||
|
||||
/// Return the trailing quote string for a string or byte literal (e.g., `"""`).
|
||||
pub fn trailing_quote(content: &str) -> Option<&&str> {
|
||||
ruff_python::str::TRIPLE_QUOTE_SUFFIXES
|
||||
ruff_python_stdlib::str::TRIPLE_QUOTE_SUFFIXES
|
||||
.iter()
|
||||
.chain(ruff_python::str::SINGLE_QUOTE_SUFFIXES)
|
||||
.chain(ruff_python_stdlib::str::SINGLE_QUOTE_SUFFIXES)
|
||||
.find(|&pattern| content.ends_with(pattern))
|
||||
}
|
||||
|
||||
|
@ -160,11 +160,11 @@ pub fn is_elif(orelse: &[rustpython_parser::ast::Stmt], locator: &Locator) -> bo
|
|||
mod tests {
|
||||
#[test]
|
||||
fn test_prefixes() {
|
||||
let prefixes = ruff_python::str::TRIPLE_QUOTE_PREFIXES
|
||||
let prefixes = ruff_python_stdlib::str::TRIPLE_QUOTE_PREFIXES
|
||||
.iter()
|
||||
.chain(ruff_python::bytes::TRIPLE_QUOTE_PREFIXES)
|
||||
.chain(ruff_python::str::SINGLE_QUOTE_PREFIXES)
|
||||
.chain(ruff_python::bytes::SINGLE_QUOTE_PREFIXES)
|
||||
.chain(ruff_python_stdlib::bytes::TRIPLE_QUOTE_PREFIXES)
|
||||
.chain(ruff_python_stdlib::str::SINGLE_QUOTE_PREFIXES)
|
||||
.chain(ruff_python_stdlib::bytes::SINGLE_QUOTE_PREFIXES)
|
||||
.collect::<Vec<_>>();
|
||||
for i in 1..prefixes.len() {
|
||||
for j in 0..i - 1 {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "ruff_python"
|
||||
name = "ruff_python_stdlib"
|
||||
version = "0.0.0"
|
||||
publish = false
|
||||
edition = { workspace = true }
|
Loading…
Add table
Add a link
Reference in a new issue