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

PKG: Declare Pillow as optional dependency #1392

Merged
merged 8 commits into from
Oct 13, 2022
Merged

PKG: Declare Pillow as optional dependency #1392

merged 8 commits into from
Oct 13, 2022

Conversation

MartinThoma
Copy link
Member

Closes #1390

@MartinThoma
Copy link
Member Author

@MasterOdin What do you think about this? I think (hope) that we don't get more dependencies, but with full people would have a clear way how to install all dependencies.

I don't see a way around the PIL / cryptodome dependencies if we want to have those features. And I think those features add enough value to justify an optional dependency.

I am uncertain about the name "full". Maybe "all" would be better?

Copy link
Member

@MasterOdin MasterOdin left a comment

Choose a reason for hiding this comment

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

Should include a link on https://github.com/py-pdf/PyPDF2/blob/main/docs/user/extract-images.md back to the installation page referencing that need to install [image].

May also want to update https://pypdf2.readthedocs.io/en/latest/modules/PageObject.html#PyPDF2._page.PageObject.images to include that reference as well?

@codecov
Copy link

codecov bot commented Oct 12, 2022

Codecov Report

Base: 94.19% // Head: 94.19% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (9d4a350) compared to base (cc55321).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1392   +/-   ##
=======================================
  Coverage   94.19%   94.19%           
=======================================
  Files          28       28           
  Lines        5082     5085    +3     
  Branches      968      968           
=======================================
+ Hits         4787     4790    +3     
  Misses        176      176           
  Partials      119      119           
Impacted Files Coverage Δ
PyPDF2/_page.py 92.16% <ø> (ø)
PyPDF2/filters.py 97.28% <100.00%> (+0.02%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@MasterOdin
Copy link
Member

MasterOdin commented Oct 12, 2022

Additionally, I think that a try/except should be added around:

https://github.com/py-pdf/PyPDF2/blob/cc553210524a8009c91409b76f05912469cfa927/PyPDF2/filters.py#L567

where we do something like:

try:
    from PIL import Image
except ImportError:
    raise DependencyError("pillow is required to do image extraction")

This is similar to what we do with PyCryptodome in _encryption.py. However, maybe also append something like ", install with pip install PyPDF2[image]" or a link to the installation guide for it?

We definitely do need to add something, as shown in the case for the user in #1390, they'll get an error about PIL import failing, and then they might try to install PIL vs pillow.

raise ImportError(
"pillow is required to do image extraction. "
"It can be installed via 'pip install PyPDF2[image]'"
)
Copy link
Member

@MasterOdin MasterOdin Oct 12, 2022

Choose a reason for hiding this comment

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

If wanted a test here, could add a test with monkeypatch.setitem modifying sys.modules to remove it from the environment. See https://stackoverflow.com/a/28361013/4616655 for an example.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's an awesome idea! Thanks for sharing it - I've written the test!

@MartinThoma MartinThoma merged commit 664ddf2 into main Oct 13, 2022
@MartinThoma MartinThoma deleted the pil-dependency branch October 13, 2022 17:16
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.

PyPDF2 doesn't install pillow
2 participants