Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork56.4k
Python module: replace config.py files by config.ini#16008
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…ATH_RELATIVE_CONFIGCMAKE when not neededThe variable OpenCV_PYTHON_INSTALL_PATH_RELATIVE_CONFIGCMAKE is set inthe if(IS_ABSOLUTE ...), but it is not used anywhere afterwards.A variable of the same name is defined and used in the else() clauseof the same condition, but it is only used within that else() clause.Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
The cv2 Python modules currently reads at runtime some bits ofconfiguration from config.py and config-X.Y.py files, by executingthem using execfile() or similar inside the Python interpreter.Unfortunately, this requires having the .py files themselvesavailable, which may not be the case on embedded systems where onlythe byte-compiled .pyc files are present (the .pyc files are alreadybyte-compiled, and in order to be space-efficient, .py files are notinstalled on some embedded systems).Due to the lack of .py files, importing the cv2 Python modulefails. Since this configuration mechanism is a bit unusual, and alsorequires separate handling for Python 2 and Python 3, this commitreplaces it by using two .ini files, which are generated with the sameinformation as the .py files, but parsed using the standardConfigParser module of Python.config.ini looks like this:[python]binpath = /usr/libwhile config-3.8.ini looks like this:[python]extensionpath = /usr/lib/python3.8/site-packages/cv2/python-3.8If multiple paths are present, they are stored colon-separated, andthey are split again when the configuration files are parsed.The only change relevant mentioning is that the expansion ofLOADER_DIR is now done when the configuration is parsed: if we have anabsolute path, we take it as-is, if there is a relative path, weassume it is relative to LOADER_DIR.Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
| ''' | ||
| importos | ||
| importsys | ||
| importconfigparser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
In Python2 it is namedConfigParser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ah, yes, thank you, indeed.
VadimLevin commentedDec 27, 2019
Thanks for you contribution! |
asmorkalov commentedJan 10, 2020
@tpetazzoni any progress on the patch? |
tpetazzoni commentedJan 10, 2020
@asmorkalov No sorry, not yet, I'll try to get to it. |
alalek commentedJan 10, 2020
Consider disabling OpenCV Python bindings loader in your configuration: Perhaps .ini files will not work for us. In the future we want to detect Python distributions in runtime, like Anaconda Python, Intel Python distribution, etc. One package + auto detection/configuration through .py files config. Instead of .ini approach you may take a look in direction of changing of importing approach (use some "import" code instead of "execfile") |
asmorkalov commentedJan 31, 2020
OpenCV team decided to close the PR as expected behavior is reachable with |
tpetazzoni commentedJan 31, 2020
Well, OPENCV_SKIP_PYTHON_LOADER may not be an option: some people do want the Python bindings of OpenCV available on their embedded system. |
alalek commentedJan 31, 2020
|
The OpenCV Python module currently installs and reads at runtime a config.py file and a config-X.Y.py file to retrieve some bits of configuration. This is done using the execfile() Python mechanism, which unfortunately only works with .py files, and not with .pyc files.
However, on some embedded systems, only .pyc files are installed: they are already byte-compiled, which optimizes the startup time, and installating both .pyc and .py files doubles the storage space, which is a limited resource on embedded systems.
In addition, loading .py file requires different code between Python 2 and Python 3.
To solve these issues, this pull request replaces the .py files by .ini files, which can trivially be parsed by the standard ConfigParser Python module.