Skip to content

Commit eaf4cdf

Browse files
authored
Update to ruff_python_parser 0.11 (RustPython#5615)
* Update to ruff_python_parser 0.11 * Try fix windows long paths error
2 parents 0717d5a + 948368f commit eaf4cdf

File tree

14 files changed

+85
-74
lines changed

14 files changed

+85
-74
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ jobs:
132132
- name: Set up the Windows environment
133133
shell: bash
134134
run: |
135+
git config --system core.longpaths true
135136
cargo install --target-dir=target -v cargo-vcpkg
136137
cargo vcpkg -v build
137138
if: runner.os == 'Windows'
@@ -255,6 +256,7 @@ jobs:
255256
- name: Set up the Windows environment
256257
shell: bash
257258
run: |
259+
git config --system core.longpaths true
258260
cargo install cargo-vcpkg
259261
cargo vcpkg build
260262
if: runner.os == 'Windows'

Cargo.lock

Lines changed: 40 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ rustpython-stdlib = { path = "stdlib", default-features = false, version = "0.4.
122122
rustpython-sre_engine = { path = "vm/sre_engine", version = "0.4.0" }
123123
rustpython-doc = { git = "https://github.com/RustPython/__doc__", tag = "0.3.0", version = "0.3.0" }
124124

125-
ruff_python_parser = { git = "https://github.com/astral-sh/ruff.git", tag = "v0.4.10" }
126-
ruff_python_ast = { git = "https://github.com/astral-sh/ruff.git", tag = "v0.4.10" }
127-
ruff_text_size = { git = "https://github.com/astral-sh/ruff.git", tag = "v0.4.10" }
128-
ruff_source_file = { git = "https://github.com/astral-sh/ruff.git", tag = "v0.4.10" }
129-
ruff_python_codegen = { git = "https://github.com/astral-sh/ruff.git", tag = "v0.4.10" }
125+
ruff_python_parser = { git = "https://github.com/astral-sh/ruff.git", tag = "0.11.0" }
126+
ruff_python_ast = { git = "https://github.com/astral-sh/ruff.git", tag = "0.11.0" }
127+
ruff_text_size = { git = "https://github.com/astral-sh/ruff.git", tag = "0.11.0" }
128+
ruff_source_file = { git = "https://github.com/astral-sh/ruff.git", tag = "0.11.0" }
129+
ruff_python_codegen = { git = "https://github.com/astral-sh/ruff.git", tag = "0.11.0" }
130130
# rustpython-literal = { version = "0.4.0" }
131131
# rustpython-parser-core = { version = "0.4.0" }
132132
# rustpython-parser = { version = "0.4.0" }

Lib/test/test_grammar.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,8 +1619,6 @@ def test_nested_front():
16191619
self.assertEqual(x, [('Boeing', 'Airliner'), ('Boeing', 'Engine'), ('Ford', 'Engine'),
16201620
('Macdonalds', 'Cheeseburger')])
16211621

1622-
# TODO: RUSTPYTHON
1623-
@unittest.expectedFailure
16241622
def test_genexps(self):
16251623
# generator expression tests
16261624
g = ([x for x in range(10)] for x in range(1))

compiler/codegen/src/compile.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,8 +2029,7 @@ impl Compiler<'_> {
20292029
if self.future_annotations {
20302030
// FIXME: codegen?
20312031
let ident = Default::default();
2032-
let codegen =
2033-
ruff_python_codegen::Generator::new(&ident, Default::default(), Default::default());
2032+
let codegen = ruff_python_codegen::Generator::new(&ident, Default::default());
20342033
self.emit_load_const(ConstantData::Str {
20352034
value: codegen.expr(annotation),
20362035
});
@@ -3595,18 +3594,19 @@ impl ToU32 for usize {
35953594
#[cfg(test)]
35963595
mod tests {
35973596
use super::*;
3597+
use ruff_python_ast::name::Name;
35983598
use ruff_python_ast::*;
35993599

36003600
/// Test if the compiler can correctly identify fstrings containing an `await` expression.
36013601
#[test]
36023602
fn test_fstring_contains_await() {
36033603
let range = TextRange::default();
3604-
let flags = FStringFlags::default();
3604+
let flags = FStringFlags::empty();
36053605

36063606
// f'{x}'
36073607
let expr_x = Expr::Name(ExprName {
36083608
range,
3609-
id: "x".to_owned(),
3609+
id: Name::new("x"),
36103610
ctx: ExprContext::Load,
36113611
});
36123612
let not_present = &Expr::FString(ExprFString {
@@ -3631,7 +3631,7 @@ mod tests {
36313631
range,
36323632
value: Box::new(Expr::Name(ExprName {
36333633
range,
3634-
id: "x".to_owned(),
3634+
id: Name::new("x"),
36353635
ctx: ExprContext::Load,
36363636
})),
36373637
});
@@ -3655,14 +3655,14 @@ mod tests {
36553655
// f'{x:{await y}}'
36563656
let expr_x = Expr::Name(ExprName {
36573657
range,
3658-
id: "x".to_owned(),
3658+
id: Name::new("x"),
36593659
ctx: ExprContext::Load,
36603660
});
36613661
let expr_await_y = Expr::Await(ExprAwait {
36623662
range,
36633663
value: Box::new(Expr::Name(ExprName {
36643664
range,
3665-
id: "y".to_owned(),
3665+
id: Name::new("y"),
36663666
ctx: ExprContext::Load,
36673667
})),
36683668
});

compiler/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn _compile(
119119
mode: Mode,
120120
opts: CompileOpts,
121121
) -> Result<CodeObject, CompileError> {
122-
let parsed = parser::parse(source_code.text, mode.into())
122+
let parsed = parser::parse(source_code.text, parser::Mode::from(mode).into())
123123
.map_err(|err| CompileError::from_ruff_parse_error(err, &source_code))?;
124124
let ast = parsed.into_syntax();
125125
compile::compile_top(ast, source_code, mode, opts).map_err(|e| e.into())
@@ -145,9 +145,8 @@ pub fn _compile_symtable(
145145
symboltable::SymbolTable::scan_program(&ast.into_syntax(), source_code.clone())
146146
}
147147
Mode::Eval => {
148-
let ast =
149-
ruff_python_parser::parse(source_code.text, ruff_python_parser::Mode::Expression)
150-
.map_err(|e| CompileError::from_ruff_parse_error(e, &source_code))?;
148+
let ast = ruff_python_parser::parse(source_code.text, parser::Mode::Expression.into())
149+
.map_err(|e| CompileError::from_ruff_parse_error(e, &source_code))?;
151150
symboltable::SymbolTable::scan_expr(
152151
&ast.into_syntax().expect_expression(),
153152
source_code.clone(),

src/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod helper;
22

33
use rustpython_compiler::{
4-
CompileError, ParseError, parser::ParseErrorType, parser::lexer::LexicalErrorType,
4+
CompileError, ParseError, parser::LexicalErrorType, parser::ParseErrorType,
55
};
66
use rustpython_vm::{
77
AsObject, PyResult, VirtualMachine,

vm/src/stdlib/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pub(crate) fn parse(
242242
mode: parser::Mode,
243243
) -> Result<PyObjectRef, CompileError> {
244244
let source_code = SourceCodeOwned::new("".to_owned(), source.to_owned());
245-
let top = parser::parse(source, mode)
245+
let top = parser::parse(source, mode.into())
246246
.map_err(|parse_error| ParseError {
247247
error: parse_error.error,
248248
location: text_range_to_source_range(&source_code, parse_error.location)

vm/src/stdlib/ast/constant.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ fn constant_to_ruff_expr(value: Constant) -> ruff::Expr {
255255
value: ruff::StringLiteralValue::single(ruff::StringLiteral {
256256
range,
257257
value,
258-
flags: ruff::StringLiteralFlags::default().with_prefix(prefix),
258+
flags: ruff::StringLiteralFlags::empty().with_prefix(prefix),
259259
}),
260260
})
261261
}
@@ -265,7 +265,7 @@ fn constant_to_ruff_expr(value: Constant) -> ruff::Expr {
265265
value: ruff::BytesLiteralValue::single(ruff::BytesLiteral {
266266
range,
267267
value,
268-
flags: Default::default(), // TODO
268+
flags: ruff::BytesLiteralFlags::empty(), // TODO
269269
}),
270270
})
271271
}
@@ -293,7 +293,7 @@ fn constant_to_ruff_expr(value: Constant) -> ruff::Expr {
293293
// idk lol
294294
func: Box::new(ruff::Expr::Name(ruff::ExprName {
295295
range: TextRange::default(),
296-
id: "frozenset".to_owned(),
296+
id: ruff::name::Name::new_static("frozenset"),
297297
ctx: ruff::ExprContext::Load,
298298
})),
299299
arguments: ruff::Arguments {

vm/src/stdlib/ast/expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ impl Node for ruff::ExprName {
977977
object: PyObjectRef,
978978
) -> PyResult<Self> {
979979
Ok(Self {
980-
id: get_node_field(vm, &object, "id", "Name")?.try_into_value(vm)?,
980+
id: Node::ast_from_object(vm, source_code, get_node_field(vm, &object, "id", "Name")?)?,
981981
ctx: Node::ast_from_object(
982982
vm,
983983
source_code,

0 commit comments

Comments
 (0)