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

python: accept path-like objects wherever file names are expected #24773

Merged
merged 6 commits into from
Jan 12, 2024

Conversation

tailsu
Copy link
Contributor

@tailsu tailsu commented Dec 26, 2023

Merry Christmas, all 🎄

Implements #15731

Support is enabled for all arguments named filename or filepath (case-insensitive), or annotated with CV_WRAP_FILE_PATH.

Support is based on PyOS_FSPath, which is available in Python 3.6+. When running on older Python versions the arguments must have a str value as before.

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 another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the 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

@tailsu tailsu force-pushed the sd/pathlike branch 3 times, most recently from 22d7fb3 to 1bb2f2f Compare December 26, 2023 15:17
@asmorkalov
Copy link
Contributor

OpenCV team build OpenCV-Python package with Limited API option to reduce support matrix. The patch breaks it:

[ 97%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_int_perform_substitution_test.cpp.o
/mnt/projects/Projects/OpenCV/opencv-master/modules/python/src2/cv2_convert.cpp: In function ‘bool pyopencv_to(PyObject*, T&, const ArgInfo&) [with T = std::__cxx11::basic_string<char>; PyObject = _object]’:
/mnt/projects/Projects/OpenCV/opencv-master/modules/python/src2/cv2_convert.cpp:708:15: error: ‘PyOS_FSPath’ was not declared in this scope
         obj = PyOS_FSPath(obj);
               ^~~~~~~~~~~
/mnt/projects/Projects/OpenCV/opencv-master/modules/python/src2/cv2_convert.cpp:708:15: note: suggested alternative: ‘Py_SetPath’
         obj = PyOS_FSPath(obj);
               ^~~~~~~~~~~
               Py_SetPath
modules/python3/CMakeFiles/opencv_python3.dir/build.make:117: recipe for target 'modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2_convert.cpp.o' failed
make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2_convert.cpp.o] Error 1

@asmorkalov
Copy link
Contributor

Fix for the versioning issue of limited API: #24837

Copy link
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

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

👍

@asmorkalov asmorkalov self-assigned this Jan 12, 2024
@asmorkalov asmorkalov merged commit 2791bb7 into opencv:4.x Jan 12, 2024
26 checks passed
@@ -701,6 +701,18 @@ bool pyopencv_to(PyObject* obj, String &value, const ArgInfo& info)
return true;
}
std::string str;

#if ((PY_VERSION_HEX >= 0x03060000) && !defined(Py_LIMITED_API)) || (Py_LIMITED_API >= 0x03060000)
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to update this check, because compilation fails in this configuration:

--   Python 3:
--     Interpreter:                 C:/utils/soft/python35-x64/python.exe (ver 3.5.4)
--     Libraries:                   C:/utils/soft/python35-x64/Libs/python35.lib (ver 3.5.4)
--     Limited API:                 YES (ver 0x03060000)
--     numpy:                       C:/utils/soft/python35-x64/lib/site-packages/numpy/core/include (ver 1.12.1)
--     install path:                python/cv2/python-3

https://pullrequest.opencv.org/buildbot/builders/precommit_opencl/builds/100307

@tailsu tailsu deleted the sd/pathlike branch January 12, 2024 16:09
@asmorkalov asmorkalov mentioned this pull request Jan 23, 2024
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.

None yet

3 participants