schrodinger.utils.pythonpatch module

class schrodinger.utils.pythonpatch.ModulePatch(orig_source_path: str = None, mmshare_version: str = None, hostname: str = None, fullname: str = None, patch_path: str = None, timestamp: str = None)

Bases: object

A class representing a patch for a single Python module. This includes metadata about the patch as well as methods to read and write the patch to a file.

orig_source_path: str = None
mmshare_version: str = None
hostname: str = None
fullname: str = None
patch_path: str = None
timestamp: str = None
classmethod fromModule(module: module | str) ModulePatch

Create a ModulePatch from a module object or a module name string. If the module is not found, a ModuleNotFoundError will be raised.

classmethod fromFile(filename: str | pathlib.Path) ModulePatch

Create a ModulePatch from a file that contains the patch information. This file should have been created by the writeFile method of ModulePatch, which appends the patch information at the end of the file.

writeFile(filename: str | pathlib.Path)

Write the module patch to a file. If the module was read from an existing patch, the patched file will be copied to the new location, and the original patch information will be preserved.

Otherwise, the original source file will be copied and new patch information will be appended to the end of the file.

sourceFilename() Path
isFromPatch() bool
getPatchDetails(add_color=False) str
__init__(orig_source_path: str = None, mmshare_version: str = None, hostname: str = None, fullname: str = None, patch_path: str = None, timestamp: str = None) None
class schrodinger.utils.pythonpatch.Patch

Bases: object

__init__()
modulesDir() Path
loadDir(patch_dir: str | pathlib.Path)

Load a patch from the given directory, previously created by writeDir. This will read the modules configuration file and load the ModulePatch objects from the files in the directory.

writeDir(patch_dir: str, zip=False)

Write the patch to the given directory.

Zip:

if True, the patch modules will be zipped into a single file. This is useful for job launching, where the entire patch can be registered with job control as a single input file.

addModule(module: module | str)

Add a module to the patch. The module can be specified as a string (the module’s full name, e.g. ‘schrodinger.models.diffy’) or as a ModuleType object (e.g. import schrodinger.models.diffy).

If the module is already in the patch, it will be replaced with the new version.

activate()

Activate the patch. Only one patch can ever be activated within a single Python process. The patch will only affect imports made after activation, so it is recommended to call this method as early as possible in your script.

This method generally does not need to be called directly, as it is automatically called by the start_patch function when the SCHRODINGER_PYTHON_PATCH_DIR environment variable is set.

getPatchDetails(add_color=False) str
schrodinger.utils.pythonpatch.start_patch()

Start the patch defined by the environment variable SCHRODINGER_PYTHON_PATCH_DIR. This will load the patch and activate it. If the environment variable is not set, this will raise a RuntimeError.

schrodinger.utils.pythonpatch.get_active_patch() Patch | None

Get the currently active patch, if any. If no patch is active, returns None.

schrodinger.utils.pythonpatch.print_active_patch(verbose: bool = False)
schrodinger.utils.pythonpatch.patch_job_launch(cmd: list[str], env: dict | None, launch_dir=None)

Modifies a job launch to include the active python patch. This will copy the patch to the launch directory, register it with job control, and set the environment vairbale in the backend to the patch directory.