Fix capitol image#880
Conversation
|
closes #879 |
corranwebster
left a comment
There was a problem hiding this comment.
This breaks on 3.7 and 3.8.
See https://github.com/enthought/pyface/blob/0fb8373b4dbb5e104d3120e88590dbf964865245/pyface/tests/test_pil_image.py#L14-L20 for an example of how to handle this sort of use of importlib across many Python versions
| from importlib import resources | ||
|
|
||
| filename = os.path.join("..", "..", "demo", "basic", "capitol.jpg") | ||
| filename = resources.files( |
There was a problem hiding this comment.
resources.files is only available on Python 3.9 or later, so this will break on 3.7 and 3.8 which we still want to support.
The fix is to use importlib_resources package which provides the newer API on older versions of Python
There was a problem hiding this comment.
Thanks for the tip, just add both importlibs
| filename = files( | ||
| 'chaco.examples.demo.basic' | ||
| ).joinpath('capitol.jpg') | ||
| image_source = ImageData.fromfile(filename) |
There was a problem hiding this comment.
Typically you want to have this in a with statement something like:
resource = files(...)
with as_file(resource) as filename:
...
corranwebster
left a comment
There was a problem hiding this comment.
Can you please add an appropriate dependency to importlib_resources for Python < 3.9 here: https://github.com/enthought/chaco/blob/main/chaco/__init__.py#L19
Also a usage issue for importlib.resources.files.
Got it, just add a "check python3.9 then install importlib_resources" there. |
Meaning it should be used in a This should be good to merge. |
Thanks Corran! The merge is still block by the ci test, the good old RuntimeError Numpy... Is there anyway we can get around it? |
After the capitol.jpg moved, chaco/examples/user_guide/plot_types/create_plot_snapshots is broken, use importlib.resources to find the image for loading to fix this