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

Poly check can't understand pillow dependency #107

Closed
BeRT2me opened this issue Sep 8, 2023 · 8 comments
Closed

Poly check can't understand pillow dependency #107

BeRT2me opened this issue Sep 8, 2023 · 8 comments
Assignees

Comments

@BeRT2me
Copy link
Contributor

BeRT2me commented Sep 8, 2023

Describe the bug
poetry poly check returns 🤔 Cannot locate PIL in my_package

To Reproduce
Steps to reproduce the behavior:

  1. Have an import like from PIL import Image
  2. Have a dependency like pillow = "^10.0.0"
  3. Run poetry poly check

Error Log

poetry poly check -vvv                     
Loading configuration file .../pypoetry/config.toml
🤔 Cannot locate PIL in my_package
ℹ my_package is importing skimage, PIL, numpy
Expected behavior
PIL == pillow

Expected behavior
A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • OS: M1 MacOS Ventura 13.5.2
  • Python version: 3.9.16
  • Poetry version: 1.6.1

Additional context
I thought it was interesting that it does find scikit-image even though its import is skimage. Though I guess that was fixed #83

@DavidVujic
Copy link
Owner

Thank you for reporting @BeRT2me!

This is probably because the poly check command couldn't see enough similarities between PIL and pillow and I will have a look at it. I have probably missed out the string comparison between different caps or something like that 😄

@DavidVujic
Copy link
Owner

@BeRT2me I believe I have fixed this issue and just released v1.8.2 of the tool. Please let me know if this has solved your issue, and thank you again for reporting it here! ⭐

@BeRT2me
Copy link
Contributor Author

BeRT2me commented Sep 12, 2023

@DavidVujic This is great, thank you!

Another one I've discovered are OpenCV packages; which can be installed as any one of:

  • opencv-python
  • opencv-contrib-python
  • opencv-python-headless
  • opencv-contrib-python-headless

And all have the import cv2.

Also, the mpl_toolkits import than comes with matplotlib.

@DavidVujic
Copy link
Owner

DavidVujic commented Sep 12, 2023

Yes, these imports are probably too different from the dependency names, and the builtin difflib that is used in the source code won't recognize them properly.

I think I will add a possibility to ignore, or to make hints, to the poly check and poly libs commands.

@DavidVujic DavidVujic reopened this Sep 12, 2023
@BeRT2me
Copy link
Contributor Author

BeRT2me commented Sep 12, 2023

Yeah, there are an unfortunate number of libraries that don't align their name and imports.

Although using difflib is a super interesting approach, I do worry about false positives. Maybe just giving the ability to map library names to a list of known imports wouldn't be clearer - and eliminate those false positives.

Something like this in the workspace.toml file:

[tool.polylith.known-libraries]
opencv-python = ["cv2"]
matplotlib = ["matplotlib", "mpl_toolkits"]
pillow = ["PIL"]
scikit-image = ["skimage"]

@DavidVujic
Copy link
Owner

Good ideas! ⭐ I plan to work on this during next week.

@BeRT2me
Copy link
Contributor Author

BeRT2me commented Sep 15, 2023

Speaking of false positives, pandas being installed falsely allowed geopandas to be overlooked.

@DavidVujic
Copy link
Owner

DavidVujic commented Sep 24, 2023

Hi @BeRT2me,

There's a new version of the tool out! v1.9.0 introduces two new options to the poly check and poly libs commands:

--strict
This option will narrow down the comparison between imports and third-party libraries. This should make false positives more rare. This option will allow libraries with - and the corresponding imports, using _, but not pandas and geopandas.

Usage:
poetry poly check --strict

--alias
This option will help the check and libs commands, when the difference between a library name and the import is too big. I chose to add it as a command option, to make it project-specific (and not for all projects in the workspace).

Usage:
poetry poly check --alias opencv-python=cv2

This will treat cv2 as a third-party library when running the analysis.

I hope this will help and make the commands more accurate! There will likely be more cases where the commands will fail on identifying libraries, but I think these options will cover many use cases.

The --strict and --alias options can be used in combination, to both rule out false positives and identifying dependencies.

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

No branches or pull requests

2 participants