Merge topic 'generate-pyi-static-import'

77f7aba92a Use the static loader when generating .pyi files

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Acked-by: Ben Boeckel <ben.boeckel@kitware.com>
Merge-request: !9607
HTGFixUnlimitedToRoot
Ben Boeckel 8 months ago committed by Kitware Robot
commit 44f2a8af3e

@ -1035,6 +1035,13 @@ static void ${_vtk_python_TARGET_NAME}_load() {\n")
set(_vtk_python_exe "${Python3_EXECUTABLE}")
endif ()
if (_vtk_python_BUILD_STATIC)
set(_generate_pyi_static_importer_arg
-i ${_vtk_python_static_importer_name})
else ()
set(_generate_pyi_static_importer_arg)
endif ()
# XXX(python2): Remove this conditional
if (NOT VTK_PYTHON_VERSION STREQUAL "2")
add_custom_command(
@ -1042,6 +1049,7 @@ static void ${_vtk_python_TARGET_NAME}_load() {\n")
COMMAND "${_vtk_python_exe}"
-m vtkmodules.generate_pyi
-p "${_vtk_python_PYTHON_PACKAGE}"
${_generate_pyi_static_importer_arg}
-o "${CMAKE_BINARY_DIR}/${_vtk_python_MODULE_DESTINATION}/${_vtk_python_package_dir}"
${_vtk_python_modules}
WORKING_DIRECTORY

@ -12,6 +12,7 @@ Options are as follows:
-p PACKAGE The package to generate .pyi files for [vtkmodules]
-o OUTPUT The output directory [default is the package directory]
-e EXT The file suffix [.pyi]
-i IMPORTER The static module importer (for static builds only)
-h HELP
With no arguments, the script runs with the defaults (the .pyi files
@ -566,6 +567,8 @@ def main(argv=sys.argv):
description="A .pyi generator for the VTK python wrappers.")
parser.add_argument('-p', '--package', type=str, default="vtkmodules",
help="Package name [vtkmodules].")
parser.add_argument('-i', '--importer', type=str,
help="Static module importer [].")
parser.add_argument('-o', '--output', type=str,
help="Output directory [package directory].")
parser.add_argument('-e', '--ext', type=str, default=".pyi",
@ -582,6 +585,18 @@ def main(argv=sys.argv):
basedir = args.output
ext = args.ext
# if static module importer is needed, it must be handled first
if args.importer:
if len(modules) == 0:
sys.stderr.write(progname + ": when using '-i', all modules " +
"in the package must be listed on the command line.\n")
return 1
# check that the modules aren't already present as builtins
# (we replace '.' separators with underscores for static importers)
module_exemplar = (packagename + '.' + modules[0]).replace('.', '_')
if module_exemplar not in sys.builtin_module_names:
importlib.import_module(args.importer)
# get information about the package
if basedir is None or len(modules) == 0:
mod = importlib.import_module(packagename)

Loading…
Cancel
Save