vtk.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. """This is the paraview.vtk module."""
  2. import sys
  3. if sys.version_info <= (3,4):
  4. # imp is deprecated in 3.4
  5. import imp, importlib
  6. # import vtkmodules package.
  7. vtkmodules_m = importlib.import_module('vtkmodules')
  8. # import paraview.pv-vtk-all
  9. all_m = importlib.import_module('paraview.pv-vtk-all')
  10. # create a clone of the `vtkmodules.all` module.
  11. vtk_m = imp.new_module(__name__)
  12. for key in dir(all_m):
  13. if not hasattr(vtk_m, key):
  14. setattr(vtk_m, key, getattr(all_m, key))
  15. # make the clone of `vtkmodules.all` act as a package at the same location
  16. # as vtkmodules. This ensures that importing modules from within the vtkmodules package
  17. # continues to work.
  18. vtk_m.__path__ = vtkmodules_m.__path__
  19. # replace old `vtk` module with this new package.
  20. sys.modules[__name__] = vtk_m
  21. else:
  22. import importlib
  23. # import vtkmodules.all
  24. all_m = importlib.import_module('paraview.pv-vtk-all')
  25. # import vtkmodules
  26. vtkmodules_m = importlib.import_module('vtkmodules')
  27. # make vtkmodules.all act as the vtkmodules package to support importing
  28. # other modules from vtkmodules package via `vtk`.
  29. all_m.__path__ = vtkmodules_m.__path__
  30. # replace old `vtk` module with the `all` package.
  31. sys.modules[__name__] = all_m