Add Python Bindings for getCacheDirectory function#18931
Add Python Bindings for getCacheDirectory function#18931sl-sergei wants to merge 2 commits intoopencv:3.4from
Conversation
|
@alalek can you advise on better naming/location for cache_directory.hpp? |
|
Why do we need to move declaration? If it is really necessary, the lets put single CV_EXPORTS_W wrapper (without namespace hierarchy) into |
I moved declaration because core/utils/filesystem.hpp is filtered out in python/bindings/CMakeLists.txt. If I move it without names, then it will be necessary to move definition into |
Lets put wrapper implementation there. |
| * @param configuration_name optional name of configuration parameter name which overrides default behavior. | ||
| * @return Path to cache directory. Returns empty string if cache directories support is not available. Returns "disabled" if cache disabled by user. | ||
| */ | ||
| CV_EXPORTS cv::String getCacheDirectory(const char* sub_directory_name, const char* configuration_name = NULL); |
There was a problem hiding this comment.
Please do not touch this at all.
Just add wrapper call for bindings only.
| from tests_common import NewOpenCVTests | ||
|
|
||
| class get_cache_dir_test(NewOpenCVTests): | ||
| def test_copytomask(self): |
There was a problem hiding this comment.
copytomask
?
please reuse test_misc.py
| #New binding | ||
| path = cv.utils.getCacheDirectory(subfolder_name) | ||
| self.assertTrue(os.path.exists(path)) | ||
| self.assertTrue(os.path.isdir(path)) |
There was a problem hiding this comment.
It make sense to dump path as failure message
|
@alalek I updated the test, are there other drawbacks that I need to fix? |
|
related: #15317. So it seems to me there is simpler way to enable the function. Also I think that we need to preserve namespace for transferability: |
|
BTW, There is an empty string result on Windows due to some reason. Perhaps we should improve this issue first. |
If we follow your way for enabling this function in Python, it will create bindings for other functions from |
@alalek I tried to reproduce this issue on local Windows machine, but I could not do that |
|
@sl-sergei, bindings are regulated by |
|
We can add only |
|
@dkurt How do you plan to do that? I don't know, maybe there is an easy way to do that, but I have already tried to change filtering logic/regex, but found that CMake has very limited options for regular expressions. The other option is to add |
There was a problem hiding this comment.
More serious problem here is non-ASCII paths (especially on Windows) and cv::String result.
On Windows it is expected to have path like C:\Documents and Settings\username\Local Settings\AppData\Local\opencv\<major_version>.x<version_status>\.
username is a source of Unicode symbols.
P.S. Even TEMP / TMP env paths are point into User's profile.
Need to design more robust solution.
Ref: #18305
| } | ||
|
|
||
| namespace fs { | ||
| CV_EXPORTS_W cv::String getCacheDirectory(const char *sub_directory_name); |
There was a problem hiding this comment.
Aliases should work:
CV_EXPORTS_AS(getCacheDirectory) cv::String getCacheDirectory_bindings(const char *sub_directory_name, ...);
Also repair configuration parameter. It is necessary to keep OpenCV configurable.
IMHO, It make sense to hide some details and provide more specialized wrapper.
In core/utility.hpp add:
CV_EXPORTS_W cv::String getCacheDirectoryForDownloads(void);
with implementation (to avoid details in .py files):
{
return cv::utils::fs::getCacheDirectory("downloads", "OPENCV_DOWNLOADS_CACHE_DIR");
}
There was a problem hiding this comment.
In
core/utility.hppadd:
I don't think it is a good idea to put function declaration and implementation there, because it would require including core/filesystem.hpp there. So I left it inside binding_utils, which is in my opinion a more suitable place for a binding wrapper.
|
@sl-sergei please squash commits |
1c50c38 to
cbdd5ae
Compare
|
@alalek Please take a look. Sergey added UTF8 handling too. |
|
Replaced by #19668 |
This PR adds new Python binding for getCacheDirectory, necessary for the PR: #18591