direct.showbase.VFSImporter
from direct.showbase.VFSImporter import VFSImporter, VFSLoader, VFSSharedImporter, VFSSharedLoader, register, reloadSharedPackage, reloadSharedPackages
The VFS importer allows importing Python modules from Panda3D’s virtual file system, through Python’s standard import mechanism.
Calling the register()
function to register the import hooks should be
sufficient to enable this functionality.
Inheritance diagram
- class VFSImporter(path)[source]
Bases:
object
This class serves as a Python importer to support loading Python .py and .pyc/.pyo files from Panda’s Virtual File System, which allows loading Python source files from mounted .mf files (among other places).
- class VFSLoader(dir_path, vfile, filename, desc, packagePath=None)[source]
Bases:
object
The second part of VFSImporter, this is created for a particular .py file or directory.
Bases:
object
This is a special importer that is added onto the meta_path list, so that it is called before sys.path is traversed. It uses special logic to load one of the “shared” packages, by searching the entire sys.path for all instances of this shared package, and merging them.
Returns the directory name that the indicated conventionally-loaded module must have been loaded from.
Bases:
object
The second part of VFSSharedImporter, this imports a list of packages and combines them.
- register()[source]
Register the VFSImporter on the path_hooks, if it has not already been registered, so that future Python import statements will vector through here (and therefore will take advantage of Panda’s virtual file system).
Reloads the specific module as a shared package, adding any new directories that might have appeared on the search path.
Walks through the sharedPackages list, and forces a reload of any modules on that list that have already been loaded. This allows new directories to be added to the search path.
The sharedPackages dictionary lists all of the “shared packages”, special Python packages that automatically span multiple directories via magic in the VFSImporter. You can make a package “shared” simply by adding its name into this dictionary (and then calling reloadSharedPackages() if it’s already been imported).
When a package name is in this dictionary at import time, all instances of the package are located along sys.path, and merged into a single Python module with a __path__ setting that represents the union. Thus, you can have a direct.showbase.foo in your own application, and loading it won’t shadow the system direct.showbase.ShowBase which is in a different directory on disk.