Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull in RustPython parser #6099

Merged
merged 4 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Prev Previous commit
Next Next commit
Pull in RustPython parser
  • Loading branch information
MichaReiser committed Jul 27, 2023
commit 8849ad2d1b37a506e75fc3a9a46a6b81512c84c0
345 changes: 251 additions & 94 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 1 addition & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ wsl = { version = "0.1.0" }
# v1.0.1
libcst = { git = "https://github.com/Instagram/LibCST.git", rev = "3cacca1a1029f05707e50703b49fe3dd860aa839", default-features = false }

ruff_text_size = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "593b46be5e0336fe01917f8ef400bd12d81df8c1" }
rustpython-ast = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "593b46be5e0336fe01917f8ef400bd12d81df8c1" }
rustpython-format = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "593b46be5e0336fe01917f8ef400bd12d81df8c1" }
rustpython-literal = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "593b46be5e0336fe01917f8ef400bd12d81df8c1" }
rustpython-parser = { git = "https://github.com/astral-sh/RustPython-Parser.git", rev = "593b46be5e0336fe01917f8ef400bd12d81df8c1" }

[profile.release]
lto = "fat"
codegen-units = 1
Expand All @@ -69,7 +63,7 @@ opt-level = 3

# Reduce complexity of a parser function that would trigger a locals limit in a wasm tool.
# https://github.com/bytecodealliance/wasm-tools/blob/b5c3d98e40590512a3b12470ef358d5c7b983b15/crates/wasmparser/src/limits.rs#L29
[profile.dev.package.rustpython-parser]
[profile.dev.package.ruff_python_parser]
opt-level = 1

# Use the `--profile release-debug` flag to show symbols in release mode.
Expand Down
8 changes: 4 additions & 4 deletions crates/ruff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ ruff_macros = { path = "../ruff_macros" }
ruff_python_ast = { path = "../ruff_python_ast", features = ["serde"] }
ruff_python_codegen = { path = "../ruff_python_codegen" }
ruff_python_index = { path = "../ruff_python_index" }
ruff_python_literal = { path = "../ruff_python_literal" }
ruff_python_semantic = { path = "../ruff_python_semantic" }
ruff_python_stdlib = { path = "../ruff_python_stdlib" }
ruff_python_trivia = { path = "../ruff_python_trivia" }
ruff_python_parser = { path = "../ruff_python_parser" }
ruff_source_file = { path = "../ruff_source_file", features = ["serde"] }
ruff_text_size = { workspace = true }
ruff_text_size = { path = "../ruff_text_size" }

annotate-snippets = { version = "0.9.1", features = ["color"] }
anyhow = { workspace = true }
Expand Down Expand Up @@ -61,9 +62,8 @@ quick-junit = { version = "0.3.2" }
regex = { workspace = true }
result-like = { version = "0.4.6" }
rustc-hash = { workspace = true }
rustpython-format = { workspace = true }
rustpython-parser = { workspace = true }
rustpython-ast = { workspace = true }


schemars = { workspace = true, optional = true }
semver = { version = "1.0.16" }
serde = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/autofix/codemods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{bail, Result};
use libcst_native::{
Codegen, CodegenState, ImportNames, ParenthesizableWhitespace, SmallStatement, Statement,
};
use rustpython_ast::{Ranged, Stmt};
use ruff_python_ast::{Ranged, Stmt};

use ruff_python_codegen::Stylist;
use ruff_source_file::Locator;
Expand Down
8 changes: 4 additions & 4 deletions crates/ruff/src/autofix/edits.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Interface for generating autofix edits from higher-level actions (e.g., "remove an argument").
use anyhow::{bail, Result};
use ruff_python_ast::{self as ast, ExceptHandler, Expr, Keyword, Ranged, Stmt};
use ruff_python_parser::{lexer, Mode};
use ruff_text_size::{TextLen, TextRange, TextSize};
use rustpython_ast::{self as ast, ExceptHandler, Expr, Keyword, Ranged, Stmt};
use rustpython_parser::{lexer, Mode};

use ruff_diagnostics::Edit;
use ruff_python_codegen::Stylist;
Expand Down Expand Up @@ -294,9 +294,9 @@ fn next_stmt_break(semicolon: TextSize, locator: &Locator) -> TextSize {
#[cfg(test)]
mod tests {
use anyhow::Result;
use ruff_python_ast::{Ranged, Suite};
use ruff_python_parser::Parse;
use ruff_text_size::TextSize;
use rustpython_ast::{Ranged, Suite};
use rustpython_parser::Parse;

use ruff_source_file::Locator;

Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast/analyze/argument.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustpython_ast::{Arg, Ranged};
use ruff_python_ast::{Arg, Ranged};

use crate::checkers::ast::Checker;
use crate::codes::Rule;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast/analyze/arguments.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustpython_ast::Arguments;
use ruff_python_ast::Arguments;

use crate::checkers::ast::Checker;
use crate::codes::Rule;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast/analyze/comprehension.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustpython_ast::Comprehension;
use ruff_python_ast::Comprehension;

use crate::checkers::ast::Checker;
use crate::codes::Rule;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast/analyze/deferred_for_loops.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustpython_ast::{self as ast, Stmt};
use ruff_python_ast::{self as ast, Stmt};

use crate::checkers::ast::Checker;
use crate::codes::Rule;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast/analyze/definitions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ruff_python_ast::str::raw_contents_range;
use ruff_python_ast::Ranged;
use ruff_text_size::TextRange;
use rustpython_ast::Ranged;

use ruff_python_semantic::{BindingKind, ContextualizedDefinition, Export};

Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast/analyze/except_handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustpython_ast::{self as ast, ExceptHandler, Ranged};
use ruff_python_ast::{self as ast, ExceptHandler, Ranged};

use crate::checkers::ast::Checker;
use crate::registry::Rule;
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/checkers/ast/analyze/expression.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustpython_ast::{self as ast, Constant, Expr, ExprContext, Operator, Ranged};
use rustpython_format::cformat::{CFormatError, CFormatErrorType};
use ruff_python_ast::{self as ast, Constant, Expr, ExprContext, Operator, Ranged};
use ruff_python_literal::cformat::{CFormatError, CFormatErrorType};

use ruff_diagnostics::Diagnostic;

Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast/analyze/module.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustpython_ast::Suite;
use ruff_python_ast::Suite;

use crate::checkers::ast::Checker;
use crate::codes::Rule;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast/analyze/statement.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustpython_ast::{self as ast, Expr, Ranged, Stmt};
use ruff_python_ast::{self as ast, Expr, Ranged, Stmt};

use ruff_diagnostics::Diagnostic;
use ruff_python_ast::helpers;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast/analyze/suite.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustpython_ast::Stmt;
use ruff_python_ast::Stmt;

use crate::checkers::ast::Checker;
use crate::codes::Rule;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/ast/deferred.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ruff_python_ast::Expr;
use ruff_text_size::TextRange;
use rustpython_ast::Expr;

use ruff_python_semantic::{ScopeId, Snapshot};

Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ use std::path::Path;

use itertools::Itertools;
use log::error;
use ruff_text_size::{TextRange, TextSize};
use rustpython_ast::{
use ruff_python_ast::{
self as ast, Arg, ArgWithDefault, Arguments, Comprehension, Constant, ElifElseClause,
ExceptHandler, Expr, ExprContext, Keyword, Pattern, Ranged, Stmt, Suite, UnaryOp,
};
use ruff_text_size::{TextRange, TextSize};

use ruff_diagnostics::{Diagnostic, IsolationLevel};
use ruff_python_ast::all::{extract_all_names, DunderAllFlags};
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::borrow::Cow;
use std::path::Path;

use rustpython_ast::{self as ast, Ranged, Stmt, Suite};
use ruff_python_ast::{self as ast, Ranged, Stmt, Suite};

use ruff_diagnostics::Diagnostic;
use ruff_python_ast::helpers::to_module_path;
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/checkers/logical_lines.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use ruff_python_parser::lexer::LexResult;
use ruff_text_size::TextRange;
use rustpython_parser::lexer::LexResult;

use ruff_diagnostics::{Diagnostic, DiagnosticKind};
use ruff_python_codegen::Stylist;
use ruff_python_parser::token_kind::TokenKind;
use ruff_python_parser::TokenKind;
use ruff_source_file::Locator;

use crate::registry::{AsRule, Rule};
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/checkers/noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use std::path::Path;

use itertools::Itertools;
use ruff_python_ast::Ranged;
use ruff_text_size::{TextLen, TextRange, TextSize};
use rustpython_ast::Ranged;

use ruff_diagnostics::{Diagnostic, Edit, Fix};
use ruff_source_file::Locator;
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/checkers/physical_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ pub(crate) fn check_physical_lines(

#[cfg(test)]
mod tests {
use rustpython_parser::lexer::lex;
use rustpython_parser::Mode;
use ruff_python_parser::lexer::lex;
use ruff_python_parser::Mode;

use ruff_python_codegen::Stylist;
use ruff_python_index::Indexer;
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/checkers/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use std::path::Path;

use rustpython_parser::lexer::LexResult;
use rustpython_parser::Tok;
use ruff_python_parser::lexer::LexResult;
use ruff_python_parser::Tok;

use ruff_diagnostics::Diagnostic;
use ruff_python_index::Indexer;
Expand Down
8 changes: 4 additions & 4 deletions crates/ruff/src/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use std::str::FromStr;

use bitflags::bitflags;
use ruff_python_parser::lexer::LexResult;
use ruff_python_parser::Tok;
use ruff_text_size::{TextLen, TextRange, TextSize};
use rustpython_parser::lexer::LexResult;
use rustpython_parser::Tok;

use ruff_python_index::Indexer;
use ruff_source_file::Locator;
Expand Down Expand Up @@ -349,9 +349,9 @@ impl TodoDirectiveKind {

#[cfg(test)]
mod tests {
use ruff_python_parser::lexer::LexResult;
use ruff_python_parser::{lexer, Mode};
use ruff_text_size::{TextLen, TextRange, TextSize};
use rustpython_parser::lexer::LexResult;
use rustpython_parser::{lexer, Mode};

use ruff_python_index::Indexer;
use ruff_source_file::Locator;
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff/src/doc_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

use std::iter::FusedIterator;

use ruff_python_ast::{self as ast, Constant, Expr, Ranged, Stmt, Suite};
use ruff_python_parser::lexer::LexResult;
use ruff_python_parser::Tok;
use ruff_text_size::TextSize;
use rustpython_ast::{self as ast, Constant, Expr, Ranged, Stmt, Suite};
use rustpython_parser::lexer::LexResult;
use rustpython_parser::Tok;

use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor};
use ruff_source_file::{Locator, UniversalNewlineIterator};
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/docstrings/extraction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Extract docstrings from an AST.

use rustpython_ast::{self as ast, Constant, Expr, Stmt};
use ruff_python_ast::{self as ast, Constant, Expr, Stmt};

use ruff_python_semantic::{Definition, DefinitionId, Definitions, Member, MemberKind};

Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/docstrings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::fmt::{Debug, Formatter};
use std::ops::Deref;

use ruff_python_ast::{Expr, Ranged};
use ruff_text_size::{TextRange, TextSize};
use rustpython_ast::{Expr, Ranged};

use ruff_python_semantic::Definition;

Expand Down
10 changes: 5 additions & 5 deletions crates/ruff/src/importer/insertion.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Insert statements into Python code.
use std::ops::Add;

use ruff_python_ast::{Ranged, Stmt};
use ruff_python_parser::{lexer, Mode, Tok};
use ruff_text_size::TextSize;
use rustpython_ast::{Ranged, Stmt};
use rustpython_parser::{lexer, Mode, Tok};

use ruff_diagnostics::Edit;
use ruff_python_ast::helpers::is_docstring_stmt;
Expand Down Expand Up @@ -299,10 +299,10 @@ fn match_leading_semicolon(s: &str) -> Option<TextSize> {
#[cfg(test)]
mod tests {
use anyhow::Result;
use ruff_python_ast::Suite;
use ruff_python_parser::lexer::LexResult;
use ruff_python_parser::Parse;
use ruff_text_size::TextSize;
use rustpython_ast::Suite;
use rustpython_parser::lexer::LexResult;
use rustpython_parser::Parse;

use ruff_python_codegen::Stylist;
use ruff_source_file::{LineEnding, Locator};
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/importer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use std::error::Error;

use anyhow::Result;
use libcst_native::{ImportAlias, Name, NameOrAttribute};
use ruff_python_ast::{self as ast, Ranged, Stmt, Suite};
use ruff_text_size::TextSize;
use rustpython_ast::{self as ast, Ranged, Stmt, Suite};

use ruff_diagnostics::Edit;
use ruff_python_ast::imports::{AnyImport, Import, ImportFrom};
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/jupyter/notebook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use serde::Serialize;
use serde_json::error::Category;

use ruff_diagnostics::Diagnostic;
use ruff_python_parser::lexer::lex;
use ruff_python_parser::Mode;
use ruff_source_file::{NewlineWithTrailingNewline, UniversalNewlineIterator};
use ruff_text_size::{TextRange, TextSize};
use rustpython_parser::lexer::lex;
use rustpython_parser::Mode;

use crate::autofix::source_map::{SourceMap, SourceMarker};
use crate::jupyter::index::JupyterIndex;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/lex/docstring_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//!
//! TODO(charlie): Consolidate with the existing AST-based docstring extraction.

use rustpython_parser::Tok;
use ruff_python_parser::Tok;

#[derive(Default, Copy, Clone)]
enum State {
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use anyhow::{anyhow, Result};
use colored::Colorize;
use itertools::Itertools;
use log::error;
use ruff_python_parser::lexer::LexResult;
use ruff_python_parser::ParseError;
use rustc_hash::FxHashMap;
use rustpython_parser::lexer::LexResult;
use rustpython_parser::ParseError;

use ruff_diagnostics::Diagnostic;
use ruff_python_ast::imports::ImportMap;
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use colored::Colorize;
use fern;
use log::Level;
use once_cell::sync::Lazy;
use rustpython_parser::{ParseError, ParseErrorType};
use ruff_python_parser::{ParseError, ParseErrorType};

use ruff_source_file::{OneIndexed, SourceCode, SourceLocation};

Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/noqa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use std::path::Path;
use anyhow::Result;
use itertools::Itertools;
use log::warn;
use ruff_python_ast::Ranged;
use ruff_text_size::{TextLen, TextRange, TextSize};
use rustpython_ast::Ranged;

use ruff_diagnostics::Diagnostic;
use ruff_source_file::{LineEnding, Locator};
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff/src/rules/airflow/rules/task_variable_name.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use rustpython_ast::{Expr, Ranged};
use rustpython_parser::ast;
use ruff_python_ast as ast;
use ruff_python_ast::{Expr, Ranged};

use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::find_keyword;
use rustpython_ast::Constant;
use ruff_python_ast::Constant;

use crate::checkers::ast::Checker;

Expand Down
4 changes: 2 additions & 2 deletions crates/ruff/src/rules/eradicate/detection.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// See: [eradicate.py](https://github.com/myint/eradicate/blob/98f199940979c94447a461d50d27862b118b282d/eradicate.py)
use once_cell::sync::Lazy;
use regex::Regex;
use rustpython_ast::Suite;
use rustpython_parser::Parse;
use ruff_python_ast::Suite;
use ruff_python_parser::Parse;

static ALLOWLIST_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/flake8_2020/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustpython_ast::Expr;
use ruff_python_ast::Expr;

use ruff_python_semantic::SemanticModel;

Expand Down
Loading