addpkg(x11/python-opencv-python): 88

- Fixes https://github.com/termux/termux-packages/issues/27407

- Could be said to be somewhat similar in design and utility to https://github.com/termux/termux-packages/pull/25434, but for OpenCV instead of CMake

- Similarly to the software 'CMake', OpenCV's PyPi package https://pypi.org/project/opencv-python/ is built from different source code from the main project, resulting in some difficulty importing it from Python projects in Termux. This package, like the `python-cmake` package, is built from the same actual source code as the software's PyPi package, but with patches to disable the installation of all files that it would normally attempt to install that are already provided by Termux packages.

- This package provides these files:

```
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_contrib_python-4.12.0.88.dist-info
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_contrib_python-4.12.0.88.dist-info/INSTALLER
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_contrib_python-4.12.0.88.dist-info/METADATA
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_contrib_python-4.12.0.88.dist-info/RECORD
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_contrib_python-4.12.0.88.dist-info/REQUESTED
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_contrib_python-4.12.0.88.dist-info/WHEEL
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_contrib_python-4.12.0.88.dist-info/direct_url.json
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_contrib_python-4.12.0.88.dist-info/licenses
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_contrib_python-4.12.0.88.dist-info/licenses/LICENSE-3RD-PARTY.txt
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_contrib_python-4.12.0.88.dist-info/licenses/LICENSE.txt
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_contrib_python-4.12.0.88.dist-info/top_level.txt
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_python-4.12.0.88.dist-info
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_python-4.12.0.88.dist-info/INSTALLER
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_python-4.12.0.88.dist-info/METADATA
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_python-4.12.0.88.dist-info/RECORD
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_python-4.12.0.88.dist-info/REQUESTED
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_python-4.12.0.88.dist-info/WHEEL
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_python-4.12.0.88.dist-info/direct_url.json
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_python-4.12.0.88.dist-info/licenses
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_python-4.12.0.88.dist-info/licenses/LICENSE-3RD-PARTY.txt
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_python-4.12.0.88.dist-info/licenses/LICENSE.txt
/data/data/com.termux/files/usr/lib/python3.12/site-packages/opencv_python-4.12.0.88.dist-info/top_level.txt
```
This commit is contained in:
termux-pacman-bot
2025-11-26 05:39:16 +00:00
parent 1bb0fd0429
commit ee602b0454
3 changed files with 108 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
TERMUX_PKG_HOMEPAGE=https://github.com/opencv/opencv-python
TERMUX_PKG_DESCRIPTION="Python wrapper for Python bindings for OpenCV"
TERMUX_PKG_LICENSE="Apache-2.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION="88"
TERMUX_PKG_REPOLOGY_METADATA_VERSION="$(. "$TERMUX_SCRIPTDIR/x11-packages/opencv/build.sh"; echo "$TERMUX_PKG_VERSION").${TERMUX_PKG_VERSION}"
TERMUX_PKG_SRCURL="https://github.com/opencv/opencv-python/archive/refs/tags/${TERMUX_PKG_VERSION}.tar.gz"
TERMUX_PKG_SHA256=c1cfdef91a45468b1c4404af594e2286ce2bcd343fe318aae287997a395a6c90
TERMUX_PKG_DEPENDS="opencv, opencv-python, python"
TERMUX_PKG_PYTHON_COMMON_DEPS="scikit-build"
TERMUX_PKG_BUILD_IN_SRC=true
TERMUX_PKG_AUTO_UPDATE=true
termux_step_pre_configure() {
termux_setup_cmake
# prevent any downloading or compiling of opencv source code,
# but allow the normal installation of all other files
echo '' > pyproject.toml
mkdir -p opencv/empty
echo 'cmake_minimum_required(VERSION 4.0)' > opencv/CMakeLists.txt
echo 'install(DIRECTORY empty DESTINATION "${CMAKE_INSTALL_PREFIX}")' >> opencv/CMakeLists.txt
# force version.py to generate
patch="$TERMUX_PKG_BUILDER_DIR/find_version.py.diff"
echo "Applying patch: $(basename "$patch")"
test -f "$patch" && sed \
-e "s%\@TERMUX_PREFIX\@%${TERMUX_PREFIX}%g" \
-e "s%\@TERMUX_PKG_VERSION\@%${TERMUX_PKG_VERSION}%g" \
"$patch" | patch --silent -p1
}
termux_step_post_make_install() {
# also provide the opencv-contrib-python variant because Termux opencv also has the extra modules,
# but some python projects might attempt to import either 'opencv-python' or 'opencv-contrib-python'.
# which have different names
export ENABLE_CONTRIB=1
pip install --no-deps . --prefix "$TERMUX_PREFIX"
}

View File

@@ -0,0 +1,46 @@
--- a/setup.py
+++ b/setup.py
@@ -497,7 +497,7 @@ def get_and_set_info(contrib, headless, rolling, ci_build):
# generate a fresh version.py always when Git repository exists
# (in sdists the version.py file already exists)
- if os.path.exists(".git"):
+ if True:
old_args = sys.argv.copy()
sys.argv = ["", str(contrib), str(headless), str(rolling), str(ci_build)]
runpy.run_path("find_version.py", run_name="__main__")
--- a/find_version.py
+++ b/find_version.py
@@ -10,7 +10,7 @@ if __name__ == "__main__":
opencv_version = ""
# dig out the version from OpenCV sources
- version_file_path = "opencv/modules/core/include/opencv2/core/version.hpp"
+ version_file_path = "@TERMUX_PREFIX@/include/opencv4/opencv2/core/version.hpp"
with open(version_file_path, "r") as f:
for line in f:
@@ -29,21 +29,10 @@ if __name__ == "__main__":
break
# used in local dev releases
- git_hash = (
- subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
- .splitlines()[0]
- .decode()
- )
+ git_hash = "N/A"
# this outputs the annotated tag if we are exactly on a tag, otherwise <tag>-<n>-g<shortened sha-1>
try:
- tag = (
- subprocess.check_output(
- ["git", "describe", "--tags"], stderr=subprocess.STDOUT
- )
- .splitlines()[0]
- .decode()
- .split("-")
- )
+ tag = ["@TERMUX_PKG_VERSION@"]
except subprocess.CalledProcessError as e:
# no tags reachable (e.g. on a topic branch in a fork), see
# https://stackoverflow.com/questions/4916492/git-describe-fails-with-fatal-no-names-found-cannot-describe-anything

View File

@@ -0,0 +1,23 @@
This forces github.com/opencv/opencv-python to only install the
files that don't exist in the other preexisting
termux opencv and opencv-python packages, i.e. *dist-info folders.
--- a/setup.py
+++ b/setup.py
@@ -271,7 +271,7 @@ def main():
description="Wrapper package for OpenCV python bindings.",
long_description=long_description,
long_description_content_type="text/markdown",
- packages=packages,
+ packages={},
package_data=package_data,
maintainer="OpenCV Team",
ext_modules=EmptyListWithLength(),
@@ -378,6 +378,7 @@ class RearrangeCMakeOutput:
subpackage\
etc.
"""
+ return
cls = self.__class__