Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
VTK
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Migliore
VTK
Commits
bdb232d4
Commit
bdb232d4
authored
5 months ago
by
Sebastien Jourdain
Browse files
Options
Downloads
Patches
Plain Diff
load registered python dependency on vtk module load
parent
53abdbc7
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Wrapping/Python/vtkmodules/__init__.py.in
+43
-0
43 additions, 0 deletions
Wrapping/Python/vtkmodules/__init__.py.in
Wrapping/Tools/vtkWrapPythonInit.c
+5
-0
5 additions, 0 deletions
Wrapping/Tools/vtkWrapPythonInit.c
with
48 additions
and
0 deletions
Wrapping/Python/vtkmodules/__init__.py.in
+
43
−
0
View file @
bdb232d4
...
...
@@ -3,6 +3,7 @@ Currently, this package is experimental and may change in the future.
"""
from __future__ import absolute_import
import sys
import importlib
def _windows_dll_path():
...
...
@@ -63,3 +64,45 @@ __all__ = [
#------------------------------------------------------------------------------
# get the version
__version__ = "@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@.@VTK_BUILD_VERSION@"
#------------------------------------------------------------------------------
# describe import dependencies to properly define Python @override
MODULE_MAPPER = {
"vtkCommonDataModel": [
"vtkmodules.util.data_model",
],
"vtkCommonExecutionModel": [
"vtkmodules.util.execution_model",
],
}
LOADED_MODULES = set()
IMPORTED_MODULES = set()
def register_vtk_module_dependencies(vtk_module_name, *import_names):
"""Method to call for registering external override on vtkmodule load"""
if vtk_module_name not in MODULE_MAPPER:
MODULE_MAPPER[vtk_module_name] = []
for import_name in import_names:
MODULE_MAPPER[vtk_module_name].append(import_name)
# If already loaded let's make sure we import it now
if vtk_module_name in LOADED_MODULES:
for import_name in import_names:
if import_name not in IMPORTED_MODULES:
importlib.import_module(import_name)
IMPORTED_MODULES.add(import_name)
def on_vtk_module_loaded(module_name):
"""Automatically called by vtkmodule when they are loaded"""
if module_name in LOADED_MODULES:
return
LOADED_MODULES.add(module_name)
if module_name in MODULE_MAPPER:
for import_name in MODULE_MAPPER[module_name]:
if import_name not in IMPORTED_MODULES:
importlib.import_module(import_name)
IMPORTED_MODULES.add(import_name)
This diff is collapsed.
Click to expand it.
Wrapping/Tools/vtkWrapPythonInit.c
+
5
−
0
View file @
bdb232d4
...
...
@@ -128,6 +128,11 @@ static void CreateImplFile(
fprintf
(
fout
,
"
\n
"
);
fprintf
(
fout
,
" vtkPythonUtil::AddModule(
\"
%s
\"
);
\n\n
"
,
libName
);
// For any loaded module check if we need to import pure python dependency
// by calling vtkmodules.on_vtk_module_loaded(libName)
fprintf
(
fout
,
" PyRun_SimpleString(
\"
vtkmodules.on_vtk_module_loaded('%s')
\"
);
\n\n
"
,
libName
);
fprintf
(
fout
,
" return m;
\n
"
);
fprintf
(
fout
,
"}
\n\n
"
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment