Repository: alugowski/fast_matrix_market (language: python)

Issue:
Python: fix clash with scipy 1.12's version of FMM
```
  ../venv/lib/python3.9/site-packages/scipy/io/_fast_matrix_market/__init__.py:354: in mmread
      cursor, stream_to_close = _get_read_cursor(source)
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  
  source = <_io.StringIO object at 0x7f5e158cbee0>, parallelism = None
  
      def _get_read_cursor(source, parallelism=None):
          """
          Open file for reading.
          """
  >       from . import _fmm_core
  E       ImportError: generic_type: type "header" is already registered!
```


Discussion / hints:
See the module local section of https://pybind11.readthedocs.io/en/stable/advanced/classes.html

Fix patch:
diff --git a/python/src/fast_matrix_market/_fmm_core.cpp b/python/src/fast_matrix_market/_fmm_core.cpp
index 46af352..0791560 100644
--- a/python/src/fast_matrix_market/_fmm_core.cpp
+++ b/python/src/fast_matrix_market/_fmm_core.cpp
@@ -195,7 +195,7 @@ PYBIND11_MODULE(_fmm_core, m) {
         }
     });
 
-    py::class_<fmm::matrix_market_header>(m, "header")
+    py::class_<fmm::matrix_market_header>(m, "header", py::module_local())
 #ifndef FMM_SCIPY_PRUNE
     .def(py::init<>())
     .def(py::init<int64_t, int64_t>())
@@ -224,7 +224,7 @@ PYBIND11_MODULE(_fmm_core, m) {
 #endif
     ///////////////////////////////
     // Read methods
-    py::class_<read_cursor>(m, "_read_cursor")
+    py::class_<read_cursor>(m, "_read_cursor", py::module_local())
     .def_readonly("header", &read_cursor::header)
     .def("close", &read_cursor::close);
 
@@ -236,7 +236,7 @@ PYBIND11_MODULE(_fmm_core, m) {
 
     ///////////////////////////////
     // Write methods
-    py::class_<write_cursor>(m, "_write_cursor")
+    py::class_<write_cursor>(m, "_write_cursor", py::module_local())
 #ifndef FMM_SCIPY_PRUNE
     .def_readwrite("header", &write_cursor::header)
 #endif


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 3e85dc4..06ece58 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -148,11 +148,13 @@ jobs:
 
       - name: Install NumPy
         # --only-binary disables compiling the package from source if a binary wheel is not available, such as some versions of PyPy
-        run: pip install --only-binary ":all:" numpy || true
+        # `--pre` to test against RCs, if any
+        run: pip install --pre --only-binary ":all:" numpy || true
 
       - name: Install SciPy
         # --only-binary disables compiling the package from source if a binary wheel is not available, such as PyPy
-        run: pip install --only-binary ":all:" scipy || true
+        # `--pre` to test against RCs, if any
+        run: pip install --pre --only-binary ":all:" scipy || true
 
       - name: Python Test
         working-directory: python/tests
diff --git a/python/tests/test_scipy.py b/python/tests/test_scipy.py
index 139f35d..c4cdd90 100644
--- a/python/tests/test_scipy.py
+++ b/python/tests/test_scipy.py
@@ -132,6 +132,8 @@ def test_read_array_or_coo(self):
 
                 self.assertMatrixEqual(m, m_fmm)
 
+    @unittest.skipIf(scipy is None or not scipy.__version__.startswith("1.11"),
+                     "SciPy 1.12 ships FMM so this no longer crashes.")
     def test_scipy_crashes(self):
         for mtx in sorted(list((matrices / "scipy_crashes").glob("*.mtx*"))):
             with self.subTest(msg=mtx.stem):