Repository: deshaw/nbstripout-fast (language: python)

Issue:
Add OSX Wheels
We should [add back](https://github.com/deshaw/nbstripout-fast/pull/3/commits/9128e178b8227078c44b354024ec89437cc6d689) the OSX wheels after https://github.com/PyO3/maturin/issues/1080#issuecomment-1330000265 is fixed.


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml
index 9505d20..b3e4464 100644
--- a/.github/workflows/wheels.yml
+++ b/.github/workflows/wheels.yml
@@ -53,7 +53,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        os: [ubuntu, windows]
+        os: [ubuntu, windows, macos]
         python-version: ['cp311', 'cp310', 'cp39']
         include:
           - os: ubuntu
@@ -102,7 +102,7 @@ jobs:
         CIBW_SKIP: '*-musllinux_i686'
         # we build for matrix.arch (only exists on macos), else 'auto'
         CIBW_ARCHS: ${{ matrix.arch || 'auto' }}
-        CIBW_ENVIRONMENT: 'PATH="$HOME/.cargo/bin:$PATH" CARGO_TERM_COLOR="always" MATURIN_PEP517_ARGS="--no-default-features"'
+        CIBW_ENVIRONMENT: 'PATH="$HOME/.cargo/bin:$PATH" CARGO_TERM_COLOR="always"'
         CIBW_ENVIRONMENT_WINDOWS: 'PATH="$UserProfile\.cargo\bin;$PATH"'
         CIBW_BEFORE_BUILD: rustup show
         # Linux wheels are built in manylinux containers; set up rust toolchain here
diff --git a/Cargo.toml b/Cargo.toml
index 88eb66a..d09ab21 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,7 +9,7 @@ name = "nbstripout_fast"
 crate-type = ["cdylib", "rlib"]
 
 [dependencies]
-pyo3 = { version = "0.16.5", features = ["extension-module"] }
+pyo3 = { version = "0.16.5", features = ["extension-module"], optional = true }
 serde = { version = "1.0.104", features = ["derive"] }
 serde_json = {version = "1.0.48",  features = [
   "float_roundtrip",
@@ -22,4 +22,4 @@ env_logger = "0.8.4"
 
 [features]
 default = ["extension-module"]
-extension-module = ["pyo3/extension-module"]
+extension-module = ["pyo3"]
diff --git a/pyproject.toml b/pyproject.toml
index b42dbc7..09fdef4 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -41,3 +41,4 @@ test = [
 
 [tool.maturin]
 bindings = "bin"
+no-default-features = true
\ No newline at end of file
diff --git a/src/lib.rs b/src/lib.rs
index c873d9e..e3c0f5d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,44 +1,50 @@
-use pyo3::exceptions::PyRuntimeError;
-use pyo3::prelude::*;
-use serde_json;
-
 mod stripoutlib;
 
-/// Strips output from a notebook (string) and returns back a notebook (string)
-#[pyfunction]
-fn stripout(
-    contents: String,
-    keep_output: bool,
-    keep_count: bool,
-    extra_keys: Vec<String>,
-    drop_empty_cells: bool,
-) -> PyResult<String> {
-    // If rust ever comes up with a PyObject to serde we should accept a
-    // notebook object instead. This is cheap and mostly used for testing
-    let mut nb: serde_json::Value = serde_json::from_str(&contents)
-        .map_err(|e| PyRuntimeError::new_err(format!("JSON was not well-formatted: {:?}", e)))?;
-
-    stripoutlib::strip_output(
-        &mut nb,
-        keep_output,
-        keep_count,
-        &extra_keys,
-        drop_empty_cells,
-    )
-    .map_err(PyRuntimeError::new_err)?;
-
-    let cleaned_contents = serde_json::to_string_pretty(&nb).map_err(|e| {
-        PyRuntimeError::new_err(format!("JSON output was not well-formatted: {:?}", e))
-    })?;
-
-    Ok(cleaned_contents)
-}
+#[cfg(feature = "extension-module")]
+mod python {
+    use pyo3::exceptions::PyRuntimeError;
+    use pyo3::prelude::*;
+    use serde_json;
+
+    use super::stripoutlib;
+
+    /// Strips output from a notebook (string) and returns back a notebook (string)
+    #[pyfunction]
+    fn stripout(
+        contents: String,
+        keep_output: bool,
+        keep_count: bool,
+        extra_keys: Vec<String>,
+        drop_empty_cells: bool,
+    ) -> PyResult<String> {
+        // If rust ever comes up with a PyObject to serde we should accept a
+        // notebook object instead. This is cheap and mostly used for testing
+        let mut nb: serde_json::Value = serde_json::from_str(&contents).map_err(|e| {
+            PyRuntimeError::new_err(format!("JSON was not well-formatted: {:?}", e))
+        })?;
+
+        stripoutlib::strip_output(
+            &mut nb,
+            keep_output,
+            keep_count,
+            &extra_keys,
+            drop_empty_cells,
+        )
+        .map_err(PyRuntimeError::new_err)?;
+
+        let cleaned_contents = serde_json::to_string_pretty(&nb).map_err(|e| {
+            PyRuntimeError::new_err(format!("JSON output was not well-formatted: {:?}", e))
+        })?;
+
+        Ok(cleaned_contents)
+    }
 
-/// nbstripout, but in rust!
-#[pymodule]
-fn nbstripout_fast(_py: Python, m: &PyModule) -> PyResult<()> {
-    env_logger::init();
+    /// nbstripout, but in rust!
+    #[pymodule]
+    fn nbstripout_fast(_py: Python, m: &PyModule) -> PyResult<()> {
+        env_logger::init();
 
-    m.add_function(wrap_pyfunction!(stripout, m)?)?;
-    Ok(())
+        m.add_function(wrap_pyfunction!(stripout, m)?)?;
+        Ok(())
+    }
 }


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index c4b28d4..6bdc7a5 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -33,7 +33,7 @@ jobs:
     # we need to find it directly.
     - name: Install python bindings for nbstripout-fast
       run: |
-        maturin build -b pyo3 --out wheel
+        maturin build -b pyo3 --features extension-module --out wheel
         pip install $(find ./wheel -name '*.whl' | head -n 1)
 
     - name: Run tests