From cbe4e8c5f3c94bc080287ec1785412a81bb27129 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 11 May 2023 04:17:56 +0900 Subject: [PATCH] Make parser location optional --- .github/workflows/ci.yaml | 2 ++ Cargo.toml | 6 ++---- ast/Cargo.toml | 4 ++-- ast/src/lib.rs | 5 +++-- core/Cargo.toml | 4 ++-- core/src/lib.rs | 2 +- parser/Cargo.toml | 3 ++- parser/src/lib.rs | 4 +++- ruff_source_location/Cargo.toml | 2 +- 9 files changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 062cf4e..e829a88 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -37,6 +37,8 @@ jobs: - uses: Swatinem/rust-cache@v2 + - name: run tests with default features + run: cargo test --all - name: run tests with embedded parser run: cargo test --all --no-default-features - name: run tests with generated parser diff --git a/Cargo.toml b/Cargo.toml index a452175..a8ce804 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,11 +16,9 @@ members = [ ] [workspace.dependencies] -rustpython-ast = { path = "ast", version = "0.2.0" } -rustpython-parser-core = { path = "core", version = "0.2.0" } +rustpython-ast = { path = "ast", version = "0.2.0", default-features = false } +rustpython-parser-core = { path = "core", version = "0.2.0", default-features = false } rustpython-literal = { path = "literal", version = "0.2.0" } -ruff_text_size = { path = "ruff_text_size" } -ruff_source_location = { path = "ruff_source_location" } ahash = "0.7.6" anyhow = "1.0.45" diff --git a/ast/Cargo.toml b/ast/Cargo.toml index 1c98911..78e90e1 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -8,9 +8,9 @@ repository = "https://github.com/RustPython/RustPython" license = "MIT" [features] -default = ["constant-optimization", "fold", "source-code"] +default = ["location"] constant-optimization = ["fold"] -source-code = ["fold"] +location = ["fold", "rustpython-parser-core/location"] fold = [] unparse = ["rustpython-literal"] visitor = [] diff --git a/ast/src/lib.rs b/ast/src/lib.rs index 2bd6fef..fbc12bd 100644 --- a/ast/src/lib.rs +++ b/ast/src/lib.rs @@ -8,7 +8,7 @@ mod generic { include!("gen/generic.rs"); } mod impls; -#[cfg(feature = "source-code")] +#[cfg(feature = "location")] mod source_locator; #[cfg(feature = "unparse")] mod unparse; @@ -32,11 +32,12 @@ mod visitor { include!("gen/visitor.rs"); } -#[cfg(feature = "source-code")] +#[cfg(feature = "location")] pub mod located { include!("gen/located.rs"); } +#[cfg(feature = "location")] pub use rustpython_parser_core::source_code; #[cfg(feature = "visitor")] pub use visitor::Visitor; diff --git a/core/Cargo.toml b/core/Cargo.toml index 8269c44..c0c31e3 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -20,5 +20,5 @@ serde = { version = "1.0.133", optional = true, default-features = false, featur lz4_flex = "0.9.2" [features] -default = ["source-code"] -source-code = ["ruff_source_location"] +default = [] +location = ["ruff_source_location"] diff --git a/core/src/lib.rs b/core/src/lib.rs index 5608dbd..06b2d3b 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -4,7 +4,7 @@ mod error; mod format; pub mod mode; -#[cfg(feature = "source-code")] +#[cfg(feature = "location")] pub mod source_code; pub use error::BaseError; diff --git a/parser/Cargo.toml b/parser/Cargo.toml index dd9cb54..8d89cf3 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -9,7 +9,8 @@ license = "MIT" edition = "2021" [features] -default = [] +default = ["location"] +location = ["rustpython-ast/location"] serde = ["dep:serde", "rustpython-parser-core/serde"] [build-dependencies] diff --git a/parser/src/lib.rs b/parser/src/lib.rs index dc5f91e..6268d07 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -113,7 +113,9 @@ #![doc(html_root_url = "https://docs.rs/rustpython-parser/")] pub use rustpython_ast as ast; -pub use rustpython_parser_core::{source_code, text_size, Mode}; +#[cfg(feature = "location")] +pub use rustpython_parser_core::source_code; +pub use rustpython_parser_core::{text_size, Mode}; mod function; // Skip flattening lexer to distinguish from full parser diff --git a/ruff_source_location/Cargo.toml b/ruff_source_location/Cargo.toml index d915169..ab602c5 100644 --- a/ruff_source_location/Cargo.toml +++ b/ruff_source_location/Cargo.toml @@ -11,7 +11,7 @@ rust-version = { workspace = true } [lib] [dependencies] -ruff_text_size = { workspace = true, features = ["serde"] } +ruff_text_size = { path = "../ruff_text_size" } memchr = "2.5.0" once_cell = { workspace = true }