Repository: fujiisoup/sif_parser (language: python)

Issue:
matplotlib conflict when importing sif_parser is breaking pyplot.plot 
Unbuntu 22.04
Python 3.10.6
Minimal virtual environment

I'm getting this error...

Exception has occurred: UnicodeDecodeError
'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

This doesn't work....

import sif_parser as sif
import matplotlib.pyplot as plt
plt.plot([1,2,3,4],[1,2,1,2])
plt.show()

This does work...

#import sif_parser as sif
import matplotlib.pyplot as plt
plt.plot([1,2,3,4],[1,2,1,2])
plt.show()

Digging down a little if I comment out line 23 in the 'plugin' module of sif_parser:

#Image.register_open("SIF", SifImageFile)

then this works again


Discussion / hints:
It is wired... I can't reproduce this in my environment.
Colabo also works fine
https://colab.research.google.com/drive/1BoezvuKMFCJJDg-3smFQjDgkmpEp2hff?usp=share_link

Which environment do you use?
Pillow is imported by chance?
We have a problem with Pillow. see #14.
FIY: The error stops appearing if you do not import sif_parser and matplotlib.pyplot in the same module. I made a wrapper module for sif_parser that could be imported in the same module as matplotlib.pyplot. Perhaps you can implement such a workaround in this repo to solve the issue.
@fujiisoup Could you implement a fix using this method?
I will, but probably this weekend.  Sorry for my late response.

Fix patch:
diff --git a/.gitignore b/.gitignore
index 457d5f8..030dd46 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,3 +38,6 @@ testings/unused_examples
 
 # temporary files
 testings/public_testdata/cli/output/*
+
+# vscode
+*.code-workspace
\ No newline at end of file
diff --git a/README.md b/README.md
index 4688bcf..611ad44 100644
--- a/README.md
+++ b/README.md
@@ -177,10 +177,10 @@ sif_parser --join *pl.sif
 
 ## Use as a plugin for PIL
 
-**NOTE!!  The current version does not work as a plugin, maybe due to updates in PIL. Contributions are very welcome.**
+**NOTE!!  This feature was removed.**
 See the issue [#7](https://github.com/fujiisoup/sif_reader/issues/7)
 
-We also provide a plugin for PIL,
+Previously, we have provided a plugin for PIL,
 
 ```python
 from PIL import image
@@ -189,11 +189,6 @@ import sif_parser.plugin
 I = Image.open('/path/to/file.sif')
 ```
 
-Note that, however, it does not work for multiple-image files.
-Contribution is very welcome!
-The image mode is `'F'`, 32-bit floating-point greyscale.
-
-
 ## History
 
 This plugin is originally developed by [soemraws](https://github.com/soemraws)
diff --git a/ci/requirements/py3.10.yml b/ci/requirements/py3.10.yml
index 9ac2449..da3e9ab 100644
--- a/ci/requirements/py3.10.yml
+++ b/ci/requirements/py3.10.yml
@@ -6,4 +6,5 @@ dependencies:
   - xarray
   - pillow
   - netcdf4
-  - dask
\ No newline at end of file
+  - dask
+  - matplotlib
\ No newline at end of file
diff --git a/ci/requirements/py3.8.yml b/ci/requirements/py3.8.yml
index d9a34d8..4bd80f3 100644
--- a/ci/requirements/py3.8.yml
+++ b/ci/requirements/py3.8.yml
@@ -6,4 +6,5 @@ dependencies:
   - xarray
   - pillow
   - netcdf4
-  - dask
\ No newline at end of file
+  - dask
+  - matplotlib
\ No newline at end of file
diff --git a/ci/requirements/py3.9.yml b/ci/requirements/py3.9.yml
index c9f1b0a..9c85d14 100644
--- a/ci/requirements/py3.9.yml
+++ b/ci/requirements/py3.9.yml
@@ -6,4 +6,5 @@ dependencies:
   - xarray
   - pillow
   - netcdf4
-  - dask
\ No newline at end of file
+  - dask
+  - matplotlib
\ No newline at end of file
diff --git a/sif_parser/__init__.py b/sif_parser/__init__.py
index 952a9b0..b792744 100644
--- a/sif_parser/__init__.py
+++ b/sif_parser/__init__.py
@@ -1,4 +1,3 @@
 from ._version import __version__, __version_info__
-from .sif_open import *
-from . import plugin
+from .sif_open import np_open, xr_open, np_spool_open
 from . import utils


Test patch:
diff --git a/testings/test_cli.py b/testings/test_cli.py
index e548bd1..d8bb2c4 100644
--- a/testings/test_cli.py
+++ b/testings/test_cli.py
@@ -133,12 +133,14 @@ def test_convert_files_verbose(caplog):
     # check first message displays all files
     # first message should be "Matched [<paths>]"
     for p in paths:
-        assert p in messages[0]
+        p = p.replace('\\', '/')
+        assert p in ''.join(messages[0]).replace('\\\\', '\\').replace('\\', '/')
 
     # check each path has a converted message
     conv_msgs = map(lambda p: f'Converting {p}', paths[1:])
     for m in conv_msgs:
-        assert m in messages[1:]
+        m = m.replace('\\', '/')
+        assert m in ''.join(messages[1:]).replace('\\\\', '\\').replace('\\', '/')
 
 
 def test_get_new_join_fn():
diff --git a/testings/test_import.py b/testings/test_import.py
new file mode 100644
index 0000000..3e9d850
--- /dev/null
+++ b/testings/test_import.py
@@ -0,0 +1,5 @@
+# GH:issue(20)
+import sif_parser as sif
+import matplotlib.pyplot as plt
+
+plt.plot([1,2,3,4],[1,2,1,2])