schrodinger.utils.env module

schrodinger.utils.env.append_path(env_dict: Dict[str, str], env_var: str, path: str)

Appends a path to env_var (defined as constants in schrodinger.utils.env) in the env_dict. This uses the traditional path seperator. We normalize the path argument.

Parameters
  • env_dict – Dictionary of environment variables.

  • env_var – existing environment variable (example: schrodinger.utils.env.PATH)

  • path – path to extend with

schrodinger.utils.env.prepend_path(env_dict: Dict[str, str], env_var: str, path: str)

Appends a path to env_var (defined as constants in schrodinger.utils.env) We normalize the path argument.

Parameters
  • env_dict – Dictionary of environment variables.

  • env_var – existing environment variable (example: schrodinger.utils.env.PATH)

  • path – path to extend with

schrodinger.utils.env.swap_ld_library_path()

Restore LD_LIBRARY_PATH to the value that it was when we first ran a toplevel script. ORIGINAL_LD_LIBRARY_PATH is set by toplevel.sh

class schrodinger.utils.env.EnvironmentContext(key: str, value: str)

Bases: object

Context manager to temporarily set an environment variable and then return it to its original value upon exit.

__init__(key: str, value: str)
class schrodinger.utils.env.MultiEnvironmentContext(env: dict)

Bases: contextlib.ExitStack

Context manager to temporarily set multiple environment variables

__init__(env: dict)
callback(callback, /, *args, **kwds)

Registers an arbitrary callback and arguments.

Cannot suppress exceptions.

close()

Immediately unwind the context stack.

enter_context(cm)

Enters the supplied context manager.

If successful, also pushes its __exit__ method as a callback and returns the result of the __enter__ method.

pop_all()

Preserve the context stack by transferring it to a new instance.

push(exit)

Registers a callback with the standard __exit__ method signature.

Can suppress exceptions the same way __exit__ method can. Also accepts any object with an __exit__ method (registering a call to the method instead of the object itself).

schrodinger.utils.env.get_ld_library_path_for_system_ssh() Optional[str]

In order to run ssh as a subprocess, sometimes we need to use system openssl libraries. This will return a modified LD_LIBRARY_PATH that does not have Schrodinger OpenSSL libraries in it.

Returns

LD_LIBRARY_PATH str or None if LD_LIBRARY_PATH was not originally set

schrodinger.utils.env.remove_ssl_ld_library_path()

Temporarily remove SSL library path from the LD_LIBRARY_PATH. This will force ssh, as called by MPI, to be linked against the system libcrypto rather than the one in the Schrodinger software (JOBCON-5027). But sometimes the user has ssh but not libcrypto and then their ssh has to use our libcrypto (DESMOND-7780). So test whether ssh fails or not by actually running it. What a world!

schrodinger.utils.env.prepend_sys_path(path: Union[str, pathlib.Path])

Prepend a specific path to sys.path. Prefer placing the module for import in an existing sys.path.

Parameters

path – directory name of path

schrodinger.utils.env.add_cuda_stubs_for_tensorflow(env_dict: Dict[str, str])

Prepends the CUDA stubs library to LD_LIBRARY_PATH if libcuda.so is not linked to the tensorflow library.

Parameters

env_dict – dict of the environment

schrodinger.utils.env.find_knime_java_path() str

Find the path to the jre included with KNIME

Raises

RuntimeError – if KNIME is not installed or it cannot find java

Returns

the path to the java file in the jre