From d71e528deb02e3dbb0bdf61244f4964e7eead4fc Mon Sep 17 00:00:00 2001 From: Harsha Teja Kanna Date: Fri, 15 Dec 2023 14:03:44 -0600 Subject: [PATCH 1/3] Added num/malachite features for format crate d d --- Cargo.toml | 2 +- ast/Cargo.toml | 2 ++ format/Cargo.toml | 8 +++++++- format/src/cformat.rs | 3 +++ format/src/format.rs | 3 +++ parser/Cargo.toml | 2 +- 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 90259620..ab777709 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ rustpython-parser-vendored = { path = "vendored", version = "0.3.0" } rustpython-ast = { path = "ast", default-features = false, version = "0.3.0" } rustpython-parser-core = { path = "core", features = [], version = "0.3.0" } rustpython-literal = { path = "literal", version = "0.3.0" } -rustpython-format = { path = "format", version = "0.3.0" } +rustpython-format = { path = "format", default-features = false, version = "0.3.0" } rustpython-parser = { path = "parser", default-features = false, version = "0.3.0" } anyhow = "1.0.45" diff --git a/ast/Cargo.toml b/ast/Cargo.toml index 53efc88c..6b65398c 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -16,6 +16,8 @@ fold = [] unparse = ["rustpython-literal"] visitor = [] all-nodes-with-ranges = [] +malachite-bigint = ["dep:malachite-bigint"] +num-bigint = ["dep:num-bigint"] [dependencies] rustpython-parser-core = { workspace = true } diff --git a/format/Cargo.toml b/format/Cargo.toml index f9fd0242..c0573f81 100644 --- a/format/Cargo.toml +++ b/format/Cargo.toml @@ -8,10 +8,16 @@ repository = { workspace = true } license = { workspace = true } rust-version = { workspace = true } +[features] +default = ["malachite-bigint"] +malachite-bigint = ["dep:malachite-bigint"] +num-bigint = ["dep:num-bigint"] + [dependencies] rustpython-literal = { workspace = true } bitflags = { workspace = true } itertools = { workspace = true } -malachite-bigint = { workspace = true } +malachite-bigint = { workspace = true, optional = true } +num-bigint = { workspace = true, optional = true } num-traits = { workspace = true } diff --git a/format/src/cformat.rs b/format/src/cformat.rs index a207857e..248ad514 100644 --- a/format/src/cformat.rs +++ b/format/src/cformat.rs @@ -1,7 +1,10 @@ //! Implementation of Printf-Style string formatting //! as per the [Python Docs](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting). use bitflags::bitflags; +#[cfg(feature = "malachite-bigint")] use malachite_bigint::{BigInt, Sign}; +#[cfg(feature = "num-bigint")] +use num_bigint::{BigInt, Sign}; use num_traits::Signed; use rustpython_literal::{float, format::Case}; use std::{ diff --git a/format/src/format.rs b/format/src/format.rs index 09cc3d1a..8109f1f9 100644 --- a/format/src/format.rs +++ b/format/src/format.rs @@ -1,5 +1,8 @@ use itertools::{Itertools, PeekingNext}; +#[cfg(feature = "malachite-bigint")] use malachite_bigint::{BigInt, Sign}; +#[cfg(feature = "num-bigint")] +use num_bigint::{BigInt, Sign}; use num_traits::FromPrimitive; use num_traits::{cast::ToPrimitive, Signed}; use rustpython_literal::float; diff --git a/parser/Cargo.toml b/parser/Cargo.toml index 19a8c8e3..fc7ecd8d 100644 --- a/parser/Cargo.toml +++ b/parser/Cargo.toml @@ -24,7 +24,7 @@ phf_codegen = "0.11.1" tiny-keccak = { version = "2", features = ["sha3"] } [dependencies] -rustpython-ast = { workspace = true } +rustpython-ast = { workspace = true, default-features = false } rustpython-parser-core = { workspace = true } itertools = { workspace = true } From 635eb4516d9aa54150531fe89e90d0222dcfd536 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 28 Dec 2023 01:09:35 +0900 Subject: [PATCH 2/3] bigint module for rustpython-format --- format/src/bigint.rs | 4 ++++ format/src/cformat.rs | 5 +---- format/src/format.rs | 5 +---- format/src/lib.rs | 1 + 4 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 format/src/bigint.rs diff --git a/format/src/bigint.rs b/format/src/bigint.rs new file mode 100644 index 00000000..ed12ec44 --- /dev/null +++ b/format/src/bigint.rs @@ -0,0 +1,4 @@ +#[cfg(feature = "malachite-bigint")] +pub use malachite_bigint::{BigInt, Sign}; +#[cfg(feature = "num-bigint")] +pub use num_bigint::{BigInt, Sign}; diff --git a/format/src/cformat.rs b/format/src/cformat.rs index 248ad514..975da4be 100644 --- a/format/src/cformat.rs +++ b/format/src/cformat.rs @@ -1,10 +1,7 @@ //! Implementation of Printf-Style string formatting //! as per the [Python Docs](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting). +use crate::bigint::{BigInt, Sign}; use bitflags::bitflags; -#[cfg(feature = "malachite-bigint")] -use malachite_bigint::{BigInt, Sign}; -#[cfg(feature = "num-bigint")] -use num_bigint::{BigInt, Sign}; use num_traits::Signed; use rustpython_literal::{float, format::Case}; use std::{ diff --git a/format/src/format.rs b/format/src/format.rs index 8109f1f9..fd497b90 100644 --- a/format/src/format.rs +++ b/format/src/format.rs @@ -1,8 +1,5 @@ +use crate::bigint::{BigInt, Sign}; use itertools::{Itertools, PeekingNext}; -#[cfg(feature = "malachite-bigint")] -use malachite_bigint::{BigInt, Sign}; -#[cfg(feature = "num-bigint")] -use num_bigint::{BigInt, Sign}; use num_traits::FromPrimitive; use num_traits::{cast::ToPrimitive, Signed}; use rustpython_literal::float; diff --git a/format/src/lib.rs b/format/src/lib.rs index 3c5d8695..acf8e1b3 100644 --- a/format/src/lib.rs +++ b/format/src/lib.rs @@ -1,3 +1,4 @@ +mod bigint; pub mod cformat; mod format; From 99284e3db5ed33cae680ada6ecc9855ff768d6d3 Mon Sep 17 00:00:00 2001 From: Harsha Teja Kanna Date: Wed, 27 Dec 2023 12:09:00 -0600 Subject: [PATCH 3/3] Remove unnecessary feature flags for optional deps --- ast/Cargo.toml | 2 -- format/Cargo.toml | 2 -- 2 files changed, 4 deletions(-) diff --git a/ast/Cargo.toml b/ast/Cargo.toml index 6b65398c..53efc88c 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -16,8 +16,6 @@ fold = [] unparse = ["rustpython-literal"] visitor = [] all-nodes-with-ranges = [] -malachite-bigint = ["dep:malachite-bigint"] -num-bigint = ["dep:num-bigint"] [dependencies] rustpython-parser-core = { workspace = true } diff --git a/format/Cargo.toml b/format/Cargo.toml index c0573f81..2771f63b 100644 --- a/format/Cargo.toml +++ b/format/Cargo.toml @@ -10,8 +10,6 @@ rust-version = { workspace = true } [features] default = ["malachite-bigint"] -malachite-bigint = ["dep:malachite-bigint"] -num-bigint = ["dep:num-bigint"] [dependencies] rustpython-literal = { workspace = true }