schrodinger.infra.unusable_module_importer module¶
A module that can replace imports with dummy modules. For example
>>> from schrodinger.infra import unusable_module_importer
>>> unusable_module_importer.enable_dummy_maestro_imports()
>>> from schrodinger.maestro import maestro
>>> bool(maestro)
False
>>> maestro.WORKSPACE_CHANGED_EVERYTHING
MaestroNotAvailableError: Cannot access
schrodinger.maestro.maestro.WORKSPACE_CHANGED_EVERYTHING outside of
Maestro
or
>>> from schrodinger.infra import unusable_module_importer
>>> unusable_module_importer.enable_dummy_non_post_test_imports()
>>> from schrodinger.application.prime.packages import antibody
>>> antibody.get_antibody_data_dir()
ProductNotAvailableError: Cannot access
schrodinger.application.prime.packages.antibody.get_antibody_data_dir
when running tests without --post-test
- exception schrodinger.infra.unusable_module_importer.ProductNotAvailableError¶
Bases:
ImportError
,AttributeError
Error indicating that a product is not available and there was an attempt to use it.
- __init__(*args, **kwargs)¶
- args¶
- msg¶
exception message
- name¶
module name
- path¶
module path
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- exception schrodinger.infra.unusable_module_importer.MaestroNotAvailableError¶
Bases:
schrodinger.infra.unusable_module_importer.ProductNotAvailableError
Error indicating that Maestro is not available and there was an attempt to use it.
- __init__(*args, **kwargs)¶
- args¶
- msg¶
exception message
- name¶
module name
- path¶
module path
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class schrodinger.infra.unusable_module_importer.UnusableModuleLoader¶
Bases:
importlib.abc.Loader
A module loader that loads
DummyModule
instances instead of the real module.- Variables
_REASON – The reason that the real module was not available
- classmethod create_module(spec)¶
Return a module to initialize and into which to load.
This method should raise ImportError if anything prevents it from creating a new module. It may return None to indicate that the spec should create the new module.
- static exec_module(module)¶
- classmethod get_code(fullname)¶
- load_module(fullname)¶
Return the loaded module.
The module must be added to sys.modules and have import-related attributes set properly. The fullname is a str.
ImportError is raised on failure.
This method is deprecated in favor of loader.exec_module(). If exec_module() exists then it is used to provide a backwards-compatible functionality for this method.
- module_repr(module)¶
Return a module’s repr.
Used by the module type when the method does not raise NotImplementedError.
This method is deprecated.
- class schrodinger.infra.unusable_module_importer.NonPostTestUnusableModuleLoader¶
Bases:
schrodinger.infra.unusable_module_importer.UnusableModuleLoader
- classmethod create_module(spec)¶
Return a module to initialize and into which to load.
This method should raise ImportError if anything prevents it from creating a new module. It may return None to indicate that the spec should create the new module.
- static exec_module(module)¶
- classmethod get_code(fullname)¶
- load_module(fullname)¶
Return the loaded module.
The module must be added to sys.modules and have import-related attributes set properly. The fullname is a str.
ImportError is raised on failure.
This method is deprecated in favor of loader.exec_module(). If exec_module() exists then it is used to provide a backwards-compatible functionality for this method.
- module_repr(module)¶
Return a module’s repr.
Used by the module type when the method does not raise NotImplementedError.
This method is deprecated.
- class schrodinger.infra.unusable_module_importer.MissingProductUnusableModuleLoader¶
Bases:
schrodinger.infra.unusable_module_importer.UnusableModuleLoader
- classmethod create_module(spec)¶
Return a module to initialize and into which to load.
This method should raise ImportError if anything prevents it from creating a new module. It may return None to indicate that the spec should create the new module.
- static exec_module(module)¶
- classmethod get_code(fullname)¶
- load_module(fullname)¶
Return the loaded module.
The module must be added to sys.modules and have import-related attributes set properly. The fullname is a str.
ImportError is raised on failure.
This method is deprecated in favor of loader.exec_module(). If exec_module() exists then it is used to provide a backwards-compatible functionality for this method.
- module_repr(module)¶
Return a module’s repr.
Used by the module type when the method does not raise NotImplementedError.
This method is deprecated.
- class schrodinger.infra.unusable_module_importer.DummyModule(module_name: str, spec: Optional[_frozen_importlib.ModuleSpec] = None, reason: str = '', loader: Type[importlib.abc.Loader] = <class 'schrodinger.infra.unusable_module_importer.UnusableModuleLoader'>)¶
Bases:
object
Used to replace modules from non-mmshare products when the product is not available. Casts to bool return False to allow portions of scripts to be protected by “if my_module:”. Raises an explanatory error if the calling module tries to access any attribute.
- Variables
_EXCEPTION_CLASS – The exception type to raise if a user tries to access an attribute of this module.
- __init__(module_name: str, spec: Optional[_frozen_importlib.ModuleSpec] = None, reason: str = '', loader: Type[importlib.abc.Loader] = <class 'schrodinger.infra.unusable_module_importer.UnusableModuleLoader'>)¶
- Parameters
module_name – The name fo the module that this object is standing in for.
spec – The module spec. Required if this module represents a package. Optional otherwise.
reason – The reason that the real module was not available.
loader – The loader class used to load this instance.
- class schrodinger.infra.unusable_module_importer.DummyMaestroModule(module_name: str, spec: Optional[_frozen_importlib.ModuleSpec] = None, reason: str = '', loader: Type[importlib.abc.Loader] = <class 'schrodinger.infra.unusable_module_importer.UnusableModuleLoader'>)¶
Bases:
schrodinger.infra.unusable_module_importer.DummyModule
Used to replace maestro modules (e.g. schrodinger.maestro.maestro) when running outside of Maestro. Casts to bool return False to allow portions of scripts to be protected by “if maestro:”. Raises an explanatory error if the calling module tries to access any attribute.
- __init__(module_name: str, spec: Optional[_frozen_importlib.ModuleSpec] = None, reason: str = '', loader: Type[importlib.abc.Loader] = <class 'schrodinger.infra.unusable_module_importer.UnusableModuleLoader'>)¶
- Parameters
module_name – The name fo the module that this object is standing in for.
spec – The module spec. Required if this module represents a package. Optional otherwise.
reason – The reason that the real module was not available.
loader – The loader class used to load this instance.
- class schrodinger.infra.unusable_module_importer.AbstractUnusableModuleFinder¶
Bases:
importlib.abc.MetaPathFinder
A meta-path finder (see https://docs.python.org/3/reference/import.html#the-meta-path) that imports
DummyModule
instances. Subclasses should redefineUNUSABLE_PACKAGES
to specify which packages should be replaced with dummy modules.- Variables
UNUSABLE_PACKAGES – A set of fully-qualified Python package names that we should intercept the imports of. Imports for any modules within these packages will also be intercepted. Formatted as, e.g.,
schrodinger.application.prime.packages
orschrodinger.forcefield.packages
MISSING_PRODUCTS_ONLY – If True, this class will only affect imports when the product is missing (i.e. there’s no
$SCHRODINGER/<product>-v*
directory). Note that if this value is True, this class will never affectschrodinger.maestro
imports.LOADER – The loader class to use to load dummy modules.
PACKAGE_TO_PRODUCT_NAME – A dictionary mapping package names (e.g. “prime” from
schrodinger.application.prime.packages
) to the product name used in the $SCHRODINGER subdirectory for the product (e.g. “psp” frompsp-v7.1
). For any package names not found in this dictionary, it will be assumed that the package name and product name are the same.
- UNUSABLE_PACKAGES: Set[str] = frozenset({})¶
- MISSING_PRODUCTS_ONLY: bool = False¶
- LOADER¶
alias of
schrodinger.infra.unusable_module_importer.UnusableModuleLoader
- PACKAGE_TO_PRODUCT_NAME: Dict[str, str] = {'forcefield': 'ffld', 'prime': 'psp'}¶
- missing_packages = {}¶
- classmethod find_spec(fullname, path, target=None)¶
- find_module(fullname, path)¶
Return a loader for the module.
If no module is found, return None. The fullname is a str and the path is a list of strings or None.
This method is deprecated since Python 3.4 in favor of finder.find_spec(). If find_spec() exists then backwards-compatible functionality is provided for this method.
- invalidate_caches()¶
An optional method for clearing the finder’s cache, if any. This method is used by importlib.invalidate_caches().
- class schrodinger.infra.unusable_module_importer.MaestroUnusableModuleFinder¶
Bases:
schrodinger.infra.unusable_module_importer.AbstractUnusableModuleFinder
A meta-path finder that replaces
schrodinger.maestro.whatever
modules withDummyMaestroModule
instances.- UNUSABLE_PACKAGES: Set[str] = {'schrodinger.maestro'}¶
- LOADER¶
alias of
schrodinger.infra.unusable_module_importer.UnusableModuleLoader
- MISSING_PRODUCTS_ONLY: bool = False¶
- PACKAGE_TO_PRODUCT_NAME: Dict[str, str] = {'forcefield': 'ffld', 'prime': 'psp'}¶
- find_module(fullname, path)¶
Return a loader for the module.
If no module is found, return None. The fullname is a str and the path is a list of strings or None.
This method is deprecated since Python 3.4 in favor of finder.find_spec(). If find_spec() exists then backwards-compatible functionality is provided for this method.
- classmethod find_spec(fullname, path, target=None)¶
- invalidate_caches()¶
An optional method for clearing the finder’s cache, if any. This method is used by importlib.invalidate_caches().
- missing_packages = {}¶
- class schrodinger.infra.unusable_module_importer.NonPostTestUnusableModuleFinder¶
Bases:
schrodinger.infra.unusable_module_importer.AbstractUnusableModuleFinder
A meta-path finder for use in non-post-test unit test runs (i.e. neither –post-test nor –post-test-only was passed to py.test). This finder replaces
schrodinger.maestro.whatever
modules withDummyMaestroModule
instances and replaces allschrodinger.application.product_name.packages
modules withDummyModules
.Note that UNUSABLE_PACKAGES is populated the first time
find_spec
is called. This is done to avoid triggering unneeded i/o calls when unusable_module_importer is imported. (We use several glob.glob() calls to find the package directories.)- UNUSABLE_PACKAGES: Set[str] = None¶
- classmethod find_spec(fullname, path, target=None)¶
- MISSING_PRODUCTS_ONLY: bool = False¶
- PACKAGE_TO_PRODUCT_NAME: Dict[str, str] = {'forcefield': 'ffld', 'prime': 'psp'}¶
- find_module(fullname, path)¶
Return a loader for the module.
If no module is found, return None. The fullname is a str and the path is a list of strings or None.
This method is deprecated since Python 3.4 in favor of finder.find_spec(). If find_spec() exists then backwards-compatible functionality is provided for this method.
- invalidate_caches()¶
An optional method for clearing the finder’s cache, if any. This method is used by importlib.invalidate_caches().
- missing_packages = {}¶
- class schrodinger.infra.unusable_module_importer.MissingProductUnusableModuleFinder¶
Bases:
schrodinger.infra.unusable_module_importer.NonPostTestUnusableModuleFinder
A meta-path finder that replaces
schrodinger.application.product_name.packages
modules withDummyModules
if and only if the product is missing (i.e. there’s no$SCHRODINGER/<product>-v*
directory)Note that, as with
NonPostTestUnusableModuleFinder
, UNUSABLE_PACKAGES is populated the first timefind_spec
is called.- MISSING_PRODUCTS_ONLY: bool = True¶
- PACKAGE_TO_PRODUCT_NAME: Dict[str, str] = {'forcefield': 'ffld', 'prime': 'psp'}¶
- UNUSABLE_PACKAGES: Set[str] = {'schrodinger.application.canvas.packages', 'schrodinger.application.combiglide.packages', 'schrodinger.application.desmond.packages', 'schrodinger.application.epik', 'schrodinger.application.glide.packages', 'schrodinger.application.jaguar.packages', 'schrodinger.application.macromodel.packages', 'schrodinger.application.phase.packages', 'schrodinger.application.prime.packages', 'schrodinger.application.scisol.packages', 'schrodinger.forcefield.packages', 'schrodinger.maestro'}¶
- find_module(fullname, path)¶
Return a loader for the module.
If no module is found, return None. The fullname is a str and the path is a list of strings or None.
This method is deprecated since Python 3.4 in favor of finder.find_spec(). If find_spec() exists then backwards-compatible functionality is provided for this method.
- classmethod find_spec(fullname, path, target=None)¶
- invalidate_caches()¶
An optional method for clearing the finder’s cache, if any. This method is used by importlib.invalidate_caches().
- missing_packages = {}¶
- class schrodinger.infra.unusable_module_importer.RestrictedProductUnusableModuleFinder¶
Bases:
schrodinger.infra.unusable_module_importer.MissingProductUnusableModuleFinder
A meta-path finder that replaces
schrodinger.application.product_name.packages
modules withDummyModules
, but only for restricted products (i.e. products that are not installed when using a non-advanced installer). DummyModules are used if and only if the product is missing (i.e. there’s no$SCHRODINGER/<product>-v*
directory).Note that, as with
NonPostTestUnusableModuleFinder
, UNUSABLE_PACKAGES is populated the first timefind_spec
is called.- RESTRICTED_PRODUCTS = {'ffld', 'scisol', 'watermap'}¶
- MISSING_PRODUCTS_ONLY: bool = True¶
- PACKAGE_TO_PRODUCT_NAME: Dict[str, str] = {'forcefield': 'ffld', 'prime': 'psp'}¶
- UNUSABLE_PACKAGES: Set[str] = {'schrodinger.application.canvas.packages', 'schrodinger.application.combiglide.packages', 'schrodinger.application.desmond.packages', 'schrodinger.application.epik', 'schrodinger.application.glide.packages', 'schrodinger.application.jaguar.packages', 'schrodinger.application.macromodel.packages', 'schrodinger.application.phase.packages', 'schrodinger.application.prime.packages', 'schrodinger.application.scisol.packages', 'schrodinger.forcefield.packages', 'schrodinger.maestro'}¶
- find_module(fullname, path)¶
Return a loader for the module.
If no module is found, return None. The fullname is a str and the path is a list of strings or None.
This method is deprecated since Python 3.4 in favor of finder.find_spec(). If find_spec() exists then backwards-compatible functionality is provided for this method.
- classmethod find_spec(fullname, path, target=None)¶
- invalidate_caches()¶
An optional method for clearing the finder’s cache, if any. This method is used by importlib.invalidate_caches().
- missing_packages = {}¶
- schrodinger.infra.unusable_module_importer.get_schrodinger_package_dirs()¶
Get directories under the schrodinger module that contain code from product repositories outside of mmshare
- schrodinger.infra.unusable_module_importer.enable_dummy_maestro_imports()¶
Replace all schrodinger.maestro.module_name imports with dummy modules. Intended for use when running outside of Maestro.
- schrodinger.infra.unusable_module_importer.disable_dummy_maestro_imports()¶
Remove the effects of
enable_dummy_maestro_imports
for any future imports.
- schrodinger.infra.unusable_module_importer.enable_dummy_non_post_test_imports()¶
Replace all schrodinger.maestro.module_name and schrodinger.application.product.packages imports with dummy modules, even if the product is installed. Intended for use in non-post-test unit test runs (i.e. neither –post-test nor –post-test-only was passed to py.test).
- schrodinger.infra.unusable_module_importer.disable_dummy_non_post_test_imports()¶
Remove the effects of
enable_dummy_non_post_test_imports
for any future imports.
- schrodinger.infra.unusable_module_importer.enable_dummy_missing_product_imports()¶
For any product that is missing, replace schrodinger.application.product.packages imports with dummy modules. Note that this function does not affect schrodinger.maestro imports.
- schrodinger.infra.unusable_module_importer.disable_dummy_missing_product_imports()¶
Remove the effects of
enable_dummy_missing_product_imports
for any future imports.
- schrodinger.infra.unusable_module_importer.enable_dummy_restricted_product_imports()¶
For any restricted product (i.e. scisol, ffld, or watermap) that is missing, replace schrodinger.application.product.packages imports with dummy modules. Note that this function does not affect schrodinger.maestro imports.
- schrodinger.infra.unusable_module_importer.disable_dummy_restricted_product_imports()¶
Remove the effects of
enable_dummy_restricted_product_imports
for any future imports.