Repository: cowlicks/hyperbee (language: python)

Issue:
Move `.print` and `.height` into a `debug` feature.
These are methods just used for debugging, they don't exist in the JS HB API. So they should be hidden.


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cf5c862..f1141f9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Removed
 
+- `Hyperbee::print` and `Hyperbee::height` are removed from the default API. They can still be accessed by enabling the `debug` feature.
 - `CoreMem` trait and all usage of it.
 
 
diff --git a/Cargo.toml b/Cargo.toml
index 9d8ee81..c0a81bc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -29,6 +29,7 @@ required-features = ["ffi"]
 default = ["ffi"]
 clib = ["tokio/rt-multi-thread", "dep:libc"]
 ffi = ["clib", "dep:uniffi"]
+debug = []
 
 [dependencies]
 async-trait = "0.1.77"
diff --git a/src/hb.rs b/src/hb.rs
index b811d0a..bcc630b 100644
--- a/src/hb.rs
+++ b/src/hb.rs
@@ -43,11 +43,13 @@ impl Hyperbee {
         self.tree.read().await.create_header(metadata).await
     }
 
+    #[cfg(feature = "debug")]
     /// The number of levels in the tree
     pub async fn height(&self) -> Result<usize, HyperbeeError> {
         self.tree.read().await.height().await
     }
 
+    #[cfg(feature = "debug")]
     /// Returs a string representing the structure of the tree showing the keys in each node
     pub async fn print(&self) -> Result<String, HyperbeeError> {
         self.tree.read().await.print().await
diff --git a/src/lib.rs b/src/lib.rs
index 111304e..0bc1e59 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -195,6 +195,7 @@ impl Node {
         self.n_children().await == 0
     }
 
+    #[cfg(feature = "debug")]
     /// The number of children between this node and a leaf + 1
     pub async fn height(&self) -> Result<usize, HyperbeeError> {
         if self.is_leaf().await {
diff --git a/src/put.rs b/src/put.rs
index 412c214..d0bd6c2 100644
--- a/src/put.rs
+++ b/src/put.rs
@@ -288,6 +288,7 @@ mod test {
         Ok(())
     }
 
+    #[cfg(feature = "debug")]
     #[tokio::test]
     async fn print_put() -> Result<(), Box<dyn std::error::Error>> {
         let hb = Tree::from_ram().await?;
@@ -317,7 +318,6 @@ mod test {
             let val = Some(key.clone());
             hb.put(&key, val.as_deref()).await?;
             hb = check_tree(hb).await?;
-            let _ = hb.print().await?;
 
             for j in 0..(i + 1) {
                 let js = j.to_string();
@@ -352,7 +352,6 @@ mod test {
             }
 
             hb = check_tree(hb).await?;
-            let _ = hb.print().await?;
         }
         Ok(())
     }
diff --git a/src/traverse.rs b/src/traverse.rs
index a8c549e..b83a54f 100644
--- a/src/traverse.rs
+++ b/src/traverse.rs
@@ -447,8 +447,10 @@ impl<'a> Stream for Traverse<'a> {
     }
 }
 
+#[cfg(feature = "debug")]
 static LEADER: &str = "\t";
 
+#[cfg(feature = "debug")]
 /// Print the keys of the provided node and it's descendents as a tree
 pub(crate) async fn print(node: SharedNode) -> Result<String, HyperbeeError> {
     let starting_height = node.read().await.height().await?;
diff --git a/src/tree.rs b/src/tree.rs
index 6d79942..0c4fc22 100644
--- a/src/tree.rs
+++ b/src/tree.rs
@@ -8,7 +8,7 @@ use crate::{
     error::HyperbeeError,
     messages::{header::Metadata, Header},
     nearest_node,
-    traverse::{self, KeyDataResult, Traverse, TraverseConfig},
+    traverse::{KeyDataResult, Traverse, TraverseConfig},
     Node, Shared, PROTOCOL,
 };
 use std::{
@@ -57,6 +57,7 @@ impl Tree {
         Ok(Some(root))
     }
 
+    #[cfg(feature = "debug")]
     pub async fn height(&self) -> Result<usize, HyperbeeError> {
         let Some(root) = self.get_root(false).await? else {
             // When there is no root, return zero.
@@ -119,13 +120,14 @@ impl Tree {
         self.blocks.read().await.append(&buf).await
     }
 
+    #[cfg(feature = "debug")]
     /// Returs a string representing the structure of the tree showing the keys in each node
     pub async fn print(&self) -> Result<String, HyperbeeError> {
         let root = self
             .get_root(false)
             .await?
             .ok_or(HyperbeeError::NoRootError)?;
-        let out = traverse::print(root).await?;
+        let out = crate::traverse::print(root).await?;
         Ok(out)
     }
 
@@ -183,6 +185,7 @@ impl Clone for Tree {
     }
 }
 
+#[cfg(feature = "debug")]
 #[cfg(test)]
 mod test {
     use super::*;


Test patch:
diff --git a/tests/basic.rs b/tests/basic.rs
index 2799a44..04ad50e 100644
--- a/tests/basic.rs
+++ b/tests/basic.rs
@@ -5,8 +5,6 @@ use hyperbee::{traverse::TraverseConfig, Hyperbee};
 
 use crate::common::js::require_js_data;
 static BASIC_TEST_DATA_STORAGE: &str = "basic";
-static MORE_HEIGHT_TEST_DATA_STORAGE: &str = "more_height";
-static SMALL_TEST_DATA_STORAGE: &str = "alphabet";
 
 #[tokio::test]
 async fn basic_integration() -> Result<()> {
@@ -65,6 +63,10 @@ async fn stream() -> Result<()> {
     Ok(())
 }
 
+#[cfg(feature = "debug")]
+static MORE_HEIGHT_TEST_DATA_STORAGE: &str = "more_height";
+
+#[cfg(feature = "debug")]
 #[tokio::test]
 async fn height() -> Result<()> {
     require_js_data()?;
@@ -75,6 +77,10 @@ async fn height() -> Result<()> {
     Ok(())
 }
 
+#[cfg(feature = "debug")]
+static SMALL_TEST_DATA_STORAGE: &str = "alphabet";
+
+#[cfg(feature = "debug")]
 #[tokio::test]
 async fn print() -> Result<()> {
     require_js_data()?;
diff --git a/tests/disk.rs b/tests/disk.rs
index 978ff1c..d367c34 100644
--- a/tests/disk.rs
+++ b/tests/disk.rs
@@ -180,9 +180,12 @@ async fn order_via_depth_first_search() -> Result<()> {
         last_i
     );
     let (hb, jsdir, rsdir) = put_rs_and_js_range!(keys.clone().into_iter(), extra_js);
-    let jshb = Hyperbee::from_storage_dir(&jsdir).await?;
     hb.put(&last, Some(&last)).await?;
-    assert_eq!(hb.print().await?, jshb.print().await?);
+    #[cfg(feature = "debug")]
+    {
+        let jshb = Hyperbee::from_storage_dir(&jsdir).await?;
+        assert_eq!(hb.print().await?, jshb.print().await?);
+    }
 
     diff_dirs(&jsdir, &rsdir)?;
     Ok(())
@@ -222,8 +225,12 @@ async fn big_random_test() -> Result<()> {
         hb.del(&key).await?;
     }
 
-    let jshb = Hyperbee::from_storage_dir(&jsdir).await?;
-    assert_eq!(hb.print().await?, jshb.print().await?);
+    #[cfg(feature = "debug")]
+    {
+        let jshb = Hyperbee::from_storage_dir(&jsdir).await?;
+        assert_eq!(hb.print().await?, jshb.print().await?);
+    }
+
     diff_dirs(&jsdir, &rsdir)?;
     Ok(())
 }