Skip to content
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

Added ArrayImage to pyface.api as per #972 #997

Merged
merged 5 commits into from
Jul 22, 2021

Conversation

Palash-Vishnani
Copy link
Contributor

No description provided.

@Palash-Vishnani
Copy link
Contributor Author

@corranwebster @rahulporuri checkout this PR.

Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is almost ready. Apart from the comment below, can you also add ArrayImage to the module docstring at the top of the file? ArrayImage can be included in the "Miscellaneous" section.

pyface/api.py Outdated
@@ -112,7 +112,7 @@
from .layered_panel import LayeredPanel
from .message_dialog import error, information, warning, MessageDialog
from .progress_dialog import ProgressDialog

from .array_image import ArrayImage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The imports are sorted alphabetically in this file so can you please update the location of this import statement?

Added `ArrayImage` to the module docstring and also updated the location of it's import statement.
@Palash-Vishnani
Copy link
Contributor Author

@rahulporuri It's fine now right??

@corranwebster
Copy link
Contributor

There's a technical gotcha in this which I think @rahulporuri is the person to make a decision. Currently I think that NumPy is technically an optional dependency of Pyface with the Qt backend (it is required for Wx for various historical reasons). This change means the NumPy is required when importing pyface.api. For that reason, we should guard the import in the same way as the pieces which depend on Pygments:

pyface/pyface/api.py

Lines 118 to 123 in 997c78f

# Excuse pygments dependency (for Qt), otherwise re-raise
with _optional_import(
"pygments",
msg="PythonEditor not available due to missing pygments.",
logger=_logging.getLogger(__name__)):
from .python_editor import PythonEditor

but with numpy in the place of Pygments.

Alternatively @rahulporuri may say that depending on numpy is fine, but in that case we need to update the requirements here:

__requires__ = [
'importlib-metadata>=3.6.0; python_version<"3.8"',
'importlib-resources>=1.1.0; python_version<"3.9"',
"traits>=6.2"
]
__extras_require__ = {
"wx": ["wxpython>=4", "numpy"],

This is why I didn't put ArrayImage in the API module during the recent PR.

@Palash-Vishnani
Copy link
Contributor Author

@corranwebster @rahulporuri Soo what to do with this PR now? Do I need to do more modifications in it, or will it be merged after some time?

@rahulporuri
Copy link
Contributor

@Palash-Vishnani sorry for the delayed response but @corranwebster is right. I missed it when i first reviewed this PR. Can you make the changes that corran recommended i.e. something like this

 # Excuse pygments dependency (for Qt), otherwise re-raise 
 with _optional_import( 
         "numpy", 
         msg="ArrayImage not available due to missing numpy.", 
         logger=_logging.getLogger(__name__)): 
     from .array_image import ArrayImage

Can you please add this new import next to the other optional imports?

@Palash-Vishnani
Copy link
Contributor Author

Palash-Vishnani commented Jul 21, 2021

@rahulporuri I'll do it but should I remove this import satement from .array_image import ArrayImage from the file? And also do I need to write this statement in the Miscellaneous section of module docstrings:

"Note that the :class:~.ArrayImage is
only available if the numpy package is available in the Python
environment."

@rahulporuri
Copy link
Contributor

@rahulporuri I'll do it but should I remove this import satement from .array_image import ArrayImage from the file?

Yes. You need to replace the from .array_image import ArrayImage with the new with _optional_import(...): code.

And also do I need to write this statement in the Miscellaneous section of module docstrings: "Note that the :class:~.ArrayImage is only available if the numpy package is available in the Python environment."

Yes please. That's right. You need to add this information in the module docstring to make it clear to end users.

Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Merging now.

@rahulporuri rahulporuri merged commit 4a1db55 into enthought:master Jul 22, 2021
@rahulporuri
Copy link
Contributor

Thanks @Palash-Vishnani for the contribution!

If you're interested in doing more, you can also add the PILImage class to pyface.api. The changes there will almost be the same as this PR - except PILImage depends on the pillow python library so you need to use with _optional_import("pillow", ...). With that PR, we will be able to close the issue #972.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants