diff --git a/modules/python/bindings/CMakeLists.txt b/modules/python/bindings/CMakeLists.txt index 23632ad9fb..9f62524a58 100644 --- a/modules/python/bindings/CMakeLists.txt +++ b/modules/python/bindings/CMakeLists.txt @@ -52,15 +52,13 @@ set_target_properties(_visp PROPERTIES set(build_configs "NONE" "RELEASE" "DEBUG" "RELEASEWITHDEBINFO" "RELWITHDEBINFO") foreach(imp_config ${build_configs}) set_target_properties(_visp PROPERTIES - LIBRARY_OUTPUT_DIRECTORY_${imp_config} "${CMAKE_CURRENT_BINARY_DIR}" + LIBRARY_OUTPUT_DIRECTORY_${imp_config} "${CMAKE_CURRENT_BINARY_DIR}/visp" ) endforeach() foreach(visp_lib ${VISP_LIBRARIES}) get_target_property(dir ${visp_lib} LIBRARY_OUTPUT_DIRECTORY) get_target_property(n ${visp_lib} OUTPUT_NAME) - - message("${dir}/${n}") endforeach() set_target_properties(_visp PROPERTIES EXCLUDE_FROM_ALL TRUE) diff --git a/modules/python/bindings/visp/__init__.py b/modules/python/bindings/visp/__init__.py index de44b785e2..6bbe0c7b2b 100644 --- a/modules/python/bindings/visp/__init__.py +++ b/modules/python/bindings/visp/__init__.py @@ -41,8 +41,8 @@ try: - import _visp - from _visp import * + from ._visp import * + from ._visp import __dict__ as cpp_extension_dict except ImportError: import platform if platform.system() == "Windows": # On windows import can fail because DLLs are not found in the default search paths @@ -51,13 +51,13 @@ with build_directory_manager() as dll_dir_manager: for p in get_dll_paths(): dll_dir_manager.add_dll_directory(p) - import _visp - from _visp import * + from ._visp import * + from ._visp import __dict__ as cpp_extension_dict else: - raise + raise ImportError('Could not import ViSP python bindings') # Fake module names -for k in _visp.__dict__: +for k in cpp_extension_dict: from types import ModuleType if isinstance(_visp.__dict__[k], ModuleType): sys.modules[f'{__name__}.{k}'] = _visp.__dict__[k] diff --git a/modules/python/bindings/visp/windows_dll_manager.py b/modules/python/bindings/visp/windows_dll_manager.py index 08edbcc7bb..4653195782 100644 --- a/modules/python/bindings/visp/windows_dll_manager.py +++ b/modules/python/bindings/visp/windows_dll_manager.py @@ -20,7 +20,9 @@ def get_dll_paths(): # For the choice of defaults: see https://peps.python.org/pep-0250/#implementation DEFAULT_DLL_PATHS = [ '..\\..\\..\\..\\bin', # when current folder is lib/python-version/site-packages/package + '..\\..\\..\\..\\Library\\bin', '..\\..\\..\\bin', # when current folder is lib/site-packages/package + '..\\..\\..\\Library\\bin', ] # If we have a different setup, the user should specify their own paths visp_user_defined_dll_paths = os.getenv("VISP_WINDOWS_DLL_PATH") diff --git a/modules/python/doc/conf.py.in b/modules/python/doc/conf.py.in index cd46bf0496..5f0df5e14b 100644 --- a/modules/python/doc/conf.py.in +++ b/modules/python/doc/conf.py.in @@ -389,6 +389,7 @@ object_description_options = [ python_type_aliases = { "_visp.": "visp.", + "visp._visp.": "visp." } diff --git a/modules/python/stubs/run_stub_generator.py b/modules/python/stubs/run_stub_generator.py index c8b904112d..ca5f7aebfe 100644 --- a/modules/python/stubs/run_stub_generator.py +++ b/modules/python/stubs/run_stub_generator.py @@ -39,6 +39,11 @@ import sys import argparse +import pybind11_stubgen +from pybind11_stubgen import __main__ + + + if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--output-root', type=str, help='Path where to save the stubs') @@ -47,11 +52,10 @@ output_root = Path(args.output_root) assert output_root.exists() bin_folder = Path(sys.executable).parent - - subprocess.run([sys.executable, '-m', 'pybind11_stubgen', '-o', str(output_root.absolute()), '--ignore-all-errors', '_visp'], check=True) + subprocess.run([sys.executable, '-m', 'pybind11_stubgen', '-o', str(output_root.absolute()), '--ignore-all-errors', 'visp._visp'], check=True) # Generate stubs for the bindings (C++ side) and mock it so that they appear in the true 'visp' package - p = Path('./_visp') + p = Path('./visp/_visp') target_path = Path('./visp-stubs') target_path.mkdir(exist_ok=True) for pyi_file in p.iterdir():