-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix capitol image #880
Fix capitol image #880
Conversation
closes #879 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
|
||
filename = os.path.join("..", "..", "demo", "basic", "capitol.jpg") | ||
filename = resources.files( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tip, just add both importlibs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
filename = files( | ||
'chaco.examples.demo.basic' | ||
).joinpath('capitol.jpg') | ||
image_source = ImageData.fromfile(filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically you want to have this in a with statement something like:
resource = files(...)
with as_file(resource) as filename:
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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