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

python3Packages.opencv4: fix installation metadata #153373

Merged
merged 1 commit into from
Jan 7, 2022

Conversation

jonringer
Copy link
Contributor

Motivation for this change

Also install the installation metadata and other python files, so other modules can correctly import the module.

before:

$ tree -L 4 $(nix-build '<nixpkgs>' -A python3Packages.opencv4)/lib/python3.9
/nix/store/dfylw3ppidn6gpbxrkjhmpsazk7cdzdj-opencv-4.5.4/lib/python3.9
└── site-packages
    └── cv2.cpython-39-x86_64-linux-gnu.so

1 directory, 1 file

after:

$ tree -L 4 $(nix-build ./. -A python3Packages.opencv4)/lib/python3.9
/nix/store/mcpyj0c16xq4kz22hzh34m8zadzs9b6n-opencv-4.5.4/lib/python3.9
└── site-packages
    ├── cv2
    │   ├── __init__.py
    │   ├── load_config_py2.py
    │   ├── load_config_py3.py
    │   └── __pycache__
    │       ├── __init__.cpython-39.pyc
    │       ├── load_config_py2.cpython-39.pyc
    │       └── load_config_py3.cpython-39.pyc
    ├── cv2.cpython-39-x86_64-linux-gnu.so
    └── opencv-4.5.4.dist-info
        ├── direct_url.json
        ├── INSTALLER
        ├── METADATA
        ├── RECORD
        ├── REQUESTED
        ├── top_level.txt
        └── WHEEL
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.05 Release Notes (or backporting 21.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/how-to-give-opencv-dependency-to-python-package/16949/8

@jonringer
Copy link
Contributor Author

Well, this is a net improvement for now. Going to merge for now, we can do further work if it still falls short in some way.

@jonringer jonringer merged commit cc091b9 into NixOS:master Jan 7, 2022
@jonringer jonringer deleted the fix-opencv4 branch January 7, 2022 21:38
@SomeoneSerge
Copy link
Contributor

SomeoneSerge commented Jan 18, 2022

Would this allow discarding all the scattered patches that remove opencv-python from requirements?

$ ag opencv-python
pkgs/applications/science/robotics/mavproxy/default.nix
15:      --replace "opencv-python" ""

pkgs/applications/video/manim/remove-dependency-constraints.patch
13:-opencv-python==3.4.2.17

pkgs/servers/home-assistant/component-packages.nix
612:    "opencv" = ps: with ps; [ numpy ]; # missing inputs: opencv-python-headless

pkgs/development/python-modules/baselines/default.nix
46:    # in nixos anyways. Since opencv-python is not currently packaged, we
48:    sed -ie '/opencv-python/d' setup.py

pkgs/development/python-modules/imagecorruptions/default.nix
20:      --replace "'opencv-python >= 3.4.5'," ""

pkgs/development/python-modules/imantics/default.nix
32:      --replace "'opencv-python>=3'," ""

pkgs/development/python-modules/imgaug/default.nix
28:      --replace "opencv-python-headless" ""
30:      --replace "opencv-python-headless" ""

EDIT: Unfortunately not. Most packages declare a requirement of opencv-python and this so far ships opencv

@@ -333,6 +338,21 @@ stdenv.mkDerivation {
postInstall = ''
sed -i "s|{exec_prefix}/$out|{exec_prefix}|;s|{prefix}/$out|{prefix}|" \
"$out/lib/pkgconfig/opencv4.pc"
''
# install python distribution information, so other packages can `import opencv`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think other packages do import cv2 and it has always worked with python3Packages.opencv4? What hadn't worked is setuptools checking for requirements

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants