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

Allow opencv-python as requirement if alread present #586

Merged
merged 4 commits into from
Jan 24, 2020

Conversation

fchouteau
Copy link
Contributor

Referencing #473

This is a proposal, heavily inspired by a similar solution in albumentations that checks if opencv-python is installed when listing requirements and replaces opencv-python-headless if this is the case.

This is not the most "elegant" alternative, however I don't know any solution without resorting to extra requires and mandating the installation of imgaug with pip install imgaug[opencv-python] or pip install imgaug[opencv-python-headless]

Maybe extra_require installation would be preferred ? If so I can submit the PR again

…cv-python` if `opencv-python` is already installed
@codecov-io
Copy link

codecov-io commented Jan 20, 2020

Codecov Report

Merging #586 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #586   +/-   ##
=======================================
  Coverage   96.48%   96.48%           
=======================================
  Files          40       40           
  Lines       14549    14549           
=======================================
  Hits        14037    14037           
  Misses        512      512

@fchouteau
Copy link
Contributor Author

Note: I disabled C0114 for setup.py 391d71b

Writing """The setup file""" would be easier, but technically, is "setup.py" a module ? I can resubmit the PR with the module docstring if preferred

@aleju
Copy link
Owner

aleju commented Jan 22, 2020

Hey, thanks for the patch. I suspect that having such a check in setup.py is overall the best approach to deal with the different cv2 packages. Having no OpenCV package as an explicit requirement and instead demanding a manual install, like suggested in #473, is probably great for professional users, but could easily confuse less experienced ones. Using "extra requires" looks elegant, but it seems like the concept can only be used to add additional requirements and not to remove them (e.g. imgaug[no-opencv] to use a custom install). I.e. imgaug would have to default to not having any opencv package as a requirement and that would again confuse inexperienced users when they try to install imgaug instead of imgaug[opencv-python]. It would potentially also break many existing systems that have imgaug as a requirement, expecting it to auto-install an opencv package, as it currently does.

The patch looks good to me. It would be great if it would be extended a bit to provide a list of alternative packages, instead of only a single one. That way opencv-contrib-python and opencv-contrib-python-headless could also be accepted. Not sure if there's a specific reason why the albumentations don't accept them -- maybe they just forgot about these packages.

Oh and you can ignore codecov complaining. That thing is currently only there to occasionally catch errors in the code. It will probably be removed in the future.

setup.py Outdated
@@ -1,27 +1,64 @@
# pylint: disable=C0114
Copy link
Owner

Choose a reason for hiding this comment

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

You could change this to # pylint: disable=missing-module-docstring

setup.py Outdated
"Shapely",
]

ALT_INSTALL_REQUIRES = {"opencv-python-headless": "opencv-python"}
Copy link
Owner

Choose a reason for hiding this comment

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

["opencv-python", "opencv-contrib-python", "opencv-contrib-python-headless"] here instead of just "opencv-python".

setup.py Outdated
Comment on lines 30 to 34
try:
alternative_pkg_name = re.split(r"[!<>=]", alternative_install_require)[0]
get_distribution(alternative_pkg_name)
except DistributionNotFound:
return install_require
Copy link
Owner

Choose a reason for hiding this comment

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

This should then expect alternative_install_require to be a list and iterate over it via a for loop.
If an alternative name in a loop iteration is found, return that name. Otherwise return install_require at the end.

setup.py Outdated
If that is the case, replace the install require by the alternative to not install dual package"""
new_install_requires = []
for main_require in main_requires:
if main_require in alternative_requires.keys():
Copy link
Owner

Choose a reason for hiding this comment

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

I think the .keys() here is not necessary

…python, opencv-python instead of opencv-python-headless)
@fchouteau
Copy link
Contributor Author

Hello,
I agree with you on the fact that the package should be "sane by default" for most users (e.g. come with its own opencv requirements instead of using extra_require)

The PR was updated to account for multiple alternatives

@aleju aleju merged commit 9381d34 into aleju:master Jan 24, 2020
@aleju
Copy link
Owner

aleju commented Jan 24, 2020

This is now merged into master.
Thanks for the PR and the adding the changes!

aleju added a commit that referenced this pull request Jan 25, 2020
aleju added a commit that referenced this pull request Jan 25, 2020
aleju added a commit that referenced this pull request Jan 26, 2020
Add PR #586 (setup.py accepting all opencv-* installations) to changelog.
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.

None yet

3 participants