Skip to content

Update __init__.py to support symbolic links#19908

Merged
opencv-pushbot merged 1 commit intoopencv:3.4from
CSBVision:patch-2
Apr 15, 2021
Merged

Update __init__.py to support symbolic links#19908
opencv-pushbot merged 1 commit intoopencv:3.4from
CSBVision:patch-2

Conversation

@CSBVision
Copy link
Copy Markdown
Contributor

Currently, the LOADER_DIR is set to os.path.dirname(os.path.abspath(file)). This does not point to the true library path if the cv2 folder is symlinked into the Python package directory such that importing cv2 under Python fails. The proposed change only resolves symbolic links correctly by calling os.path.realpath(file) first and does not change anything if file contains no symbolic link.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • [] The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

I believe, this patch should not break anything in general.

As I understand from the problem description, configuration files try to refer on files outside of Python installation location (through parent directories, and these extra files are not installed).
For such cases, it makes sense to install cv2 package with all necessary dependencies into the target package directory (with modified config files for specific layout).

Currently, the LOADER_DIR is set as os.path.dirname(os.path.abspath(__file__)). This does not point to the true library path if the cv2 folder is symlinked into the Python package directory such that importing cv2 under Python fails. The proposed change only resolves symbolic links correctly by calling os.path.realpath(__file__) first and does not change anything if __file__ contains no symbolic link.
@alalek
Copy link
Copy Markdown
Member

alalek commented Apr 14, 2021

This patch should go into 3.4 branch first.
We will merge changes from 3.4 into master regularly (weekly/bi-weekly).

Please:

  • change "base" branch of this PR: master => 3.4 (use "Edit" button near PR title)
  • rebase your commits from master onto 3.4 branch. For example:
    git rebase -i --onto upstream/3.4 upstream/master
    (check list of your commits, save and quit (Esc + "wq" + Enter)
    where upstream is configured by following this GitHub guide and fetched (git fetch upstream).
  • push rebased commits into source branch of your fork (with --force option)

Note: no needs to re-open PR, apply changes "inplace".

@CSBVision CSBVision changed the base branch from master to 3.4 April 15, 2021 04:56
@CSBVision CSBVision closed this Apr 15, 2021
@CSBVision CSBVision deleted the patch-2 branch April 15, 2021 05:47
@CSBVision CSBVision restored the patch-2 branch April 15, 2021 05:49
@CSBVision
Copy link
Copy Markdown
Contributor Author

I tried to follow these steps, however there was some weird stuff in the commit besides the Python script and while trying to fix it, it seems that I pretty much messed up the PR. Whats the right way to fix this?

@CSBVision CSBVision reopened this Apr 15, 2021
@CSBVision CSBVision closed this Apr 15, 2021
@CSBVision CSBVision deleted the patch-2 branch April 15, 2021 05:55
@CSBVision CSBVision reopened this Apr 15, 2021
@CSBVision CSBVision restored the patch-2 branch April 15, 2021 05:58
@opencv-pushbot opencv-pushbot merged commit 6598e9d into opencv:3.4 Apr 15, 2021
@alalek alalek mentioned this pull request Apr 15, 2021
@CSBVision CSBVision deleted the patch-2 branch April 16, 2021 04:52
@alalek alalek mentioned this pull request Jun 4, 2021
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.

3 participants