-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add mixed Python-C++ PyCOLMAP package #2747
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
Conversation
|
I did it in a quite dirty way here: https://github.com/cvg/limap/blob/main/limap/__init__.py. I am sure there are better alternatives (at least it should be switched to explicit import) |
|
Types in |
|
Thanks! This works in my test. However, are you sure that this is the only way to achieve this? "import *" looks quite aggressive and is widely considered to be avoided in all costs. |
|
This is a common solution (for example as done in torch) and the only alternative to manually listing the symbols to be imported (which is impractical for us). |
|
LGTM, also given that other notable libraries follow the same approach. |
| @@ -0,0 +1,15 @@ | |||
| from ._core import * # noqa F403 | |||
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.
Maybe something to consider. To avoid importing internal symbols, the following code snippet reduces the risk of name conflicts and keeps the pycolmap namespace clean:
from . import _core as _core_module
# Loop over all the members of the module, adding the symbols to the current
# module's namespace (i.e., pycolmap package's), and skipping internal symbols
# (names starting with '_').
for _name, _symbol in vars(_core_module).items():
if not _name.startswith("_"):
globals()[_name] = _symbol
# Cleanup.
del _core_module, _name, _symbolThis solution ensures that only the relevant symbols from _core are shown, without explicitly listing pycolmap._core when using help(pycolmap). Please note that I haven't tested this.
Move the C++ extension to
pycolmap._coresuch that we can augment PyCOLMAP with pure Python modules. Notes:_pycolmap, but this pollutes thesite-packagesdirectoryhelp(pycolmap), this shows types likepycolmap._core.Reconstructioninstead ofpycolmap.Reconstruction... @B1ueber2y Did you manage to fix this in limap?