schrodinger.utils.imputils module

Utility functions to import python modules. Always prefer loading from a location on sys.path.

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.utils.imputils.import_module_from_file(filename)

Import module from a file path. Returns the imported module object.

schrodinger.utils.imputils.import_from_file(modulename, filename)
schrodinger.utils.imputils.get_path_from_module(module)

Given a module, return a path string. The path string will either be in ‘.’ format if the module can be found in either the schrodinger scripts or modules directory or an absolute path if the module is defined in a python unittest module. Inverse function of get_module_from_path.

Parameters:module – The module to export a path string for. To get the module of any arbitrary object, use inspect.getmodule.

: type module: module

schrodinger.utils.imputils.get_module_from_path(module_path)

Given a module path string generated by get_path_from_module, return the corresponding module. Inverse function of get_path_from_module.

Parameters:module_path – The path string describing the module to import

: type module_path: str

schrodinger.utils.imputils.import_script(name, subdir=None)

Import the given script residing in mmshare/python/scripts as a module. If the script is not found in the scripts directory, an attempt is made to import the script from a subdirectory following our standard naming convention by replacing ‘_driver.py’ or ‘_backend.py’ with ‘_gui_dir’.

Parameters:
  • name (str) – The name of the script, including the .py extension
  • subdir (str) – The name of the subdirectory the script resides in - must be a path relative to mmshare/python/scripts. If given, this name will be used instead of attempting to derive a subdirectory name from the script name.
Return type:

module

Returns:

The script imported as a module

Raises:

FileNotFoundError – If the script can’t be found