-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
Add CMake option to install pip metadata when Python bindings are installed just by CMake #21611
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
base: 4.x
Are you sure you want to change the base?
Conversation
…talled just by CMake
For what regard documentation, this is a packager-oriented option, so I do not know where is the best place where to document this. |
endif() | ||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/METADATA "") | ||
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/METADATA "Metadata-Version: 2.1${NEW_LINE}") | ||
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/METADATA "Name: opencv-python${NEW_LINE}") |
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.
opencv-python
It is just a name of the package from dedicated repository: https://github.com/opencv/opencv-python
It is not an entity of this upstream repository. Perhaps we should not have it here.
Moreover there are several conflicting subpackages from "opencv-python", like headless or contrib variants.
Ubuntu's python3-opencv
package also doesn't know anything about opencv-python
names:
- 18.04: https://packages.ubuntu.com/bionic/amd64/python3-opencv/filelist
- 20.04: https://packages.ubuntu.com/focal/amd64/python3-opencv/filelist
/METADATA
Modern Python uses PKG-INFO
: https://www.python.org/dev/peps/pep-0314/
Not sure about "conda".
Examples:
- https://packages.ubuntu.com/bionic/amd64/python-numpy/filelist
- https://packages.ubuntu.com/bionic/amd64/python3-numpy/filelist
tries to install a Python library that depends on
opencv-python
Are there another ways to mask package installation in pip?
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.
opencv-python
It is just a name of the package from dedicated repository: https://github.com/opencv/opencv-python
It is not an entity of this upstream repository. Perhaps we should not have it here.Moreover there are several conflicting subpackages from "opencv-python", like headless or contrib variants.
Ubuntu's python3-opencv package also doesn't know anything about opencv-python names:
Ack, I see why you may not want CMake's upstream to enter in this details that are mostly related to distributions (and mixing two different distribution, the base apt/conda system and pip).
Modern Python uses PKG-INFO: https://www.python.org/dev/peps/pep-0314/
I am not an expert, I got the METADATA info from official Python documentation (and from PyPI's opencv-python
installations):
- https://packaging.python.org/specifications/recording-installed-packages/
- https://packaging.python.org/en/latest/specifications/core-metadata/#core-metadata
From a quick search, it seems that it was introduced by the following PEPs that amend/complete pep-0314:
tries to install a Python library that depends on
opencv-python
Are there another ways to mask package installation in pip?
That I am aware of, just passing to pip the --no-deps
, that however do not install any dependency at and needs to be specified manually by users.
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.
@traversaro Thank you for information!
I have looked a bit on this specification: https://www.python.org/dev/peps/pep-0345/
There is a field to declare package name aliases (which wold work for us): Provides-Dist
E.g. we could have package name opencv
and define known package aliases with names: opencv-python
, opencv-python-headless
.
But, looks like installation tools don't care about this field: https://stackoverflow.com/questions/61603438/do-any-tools-support-provides-dist-metadata-for-python-packages-if-not-why
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.
I am a random dude, who would like this feature to be implemented.
Regarding the package name, how about just making the OPENCV_PYTHON_PIP_METADATA_INSTALL
option accept a String instead of a boolean and use that name everywhere opencv_python
/opencv-python
currently appears (with appropriate _
/-
translations)? This way, downstream package distributors could choose the appropriate name themselves?
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.
Just a curiosity, what is the use case for you for using this feature?
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.
I use ArchLinux and I normally prefer to install my python packages through pacman/AUR. The official python-opencv
arch package builds and installs opencv
from source (including the python bindings). This leads to the problems described by @traversaro, where pip
doesn't know, that opencv
is already installed. Currently, I roll my own PKGBUILD that installs the appropriate dist-info
alongside the system-wide opencv
package, but this is obviously inconvenient.
What is current status of this PR? It should help to make our build visible to pip as |
When OpenCV's Python bindings are installed only via CMake by enabling the appropriate CMake option, the
opencv-python
package is not listed bypip list
.This is not problematic until a user tries to install a Python library that depends on
opencv-python
viapip install .
. In that case, the Pythonopencv-python
package already available in the system is ignored, and the PyPI version ofopencv-python
is installed itself.This PR adds the CMake logic to generate the necessary
METADATA
andINSTALLER
Python files so that even when just installed via cmake, theopencv-python
python package can be listed bypip list
.This logic is disabled by default, but can be enabled by the option
OPENCV_PYTHON_PIP_METADATA_INSTALL
, to avoid conflicts with existing installation script of Python bindings in https://github.com/opencv/opencv-python that generate these metadata files viasetup.py
.This PR originated from conda-forge/opencv-feedstock#299 and has been validated in conda-forge/opencv-feedstock#300, but it can be useful for all downstream packagers of OpenCV's python bindings. For example, Debian's
python3-opencv
is affected by the same problem.Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.