Package schrodinger :: Package infra :: Module util
[hide private]
[frames] | no frames]

Module util

General infrastructure level utilities.

Copyright Schrodinger, LLC. All rights reserved.

Classes [hide private]
  cached_property
Decorator that converts a method with a single self argument into a property cached on the instance.
  CreateWhenNeeded
This class can be used like property() (i.e., it is a descriptor; see section 3.3.2.2 in the python reference).
  DecoratorAndContextManager
An abstract base class for context managers that can also be used to decorate functions and classes.
  OneIndexedList
A list that starts at one instead of zero
Functions [hide private]
 
flag_context_manager(attr_name, set_to=True)
Create a context manager that sets the specified class attribute to the given value and then restores the original value of the attribute when leaving the context.
 
skip_if(attr_name, if_set_to=True)
Create a decorator that converts the decorated method to a no-op if class attribute C{attr_name} equals C{is_set_to}.
 
prevent_choruslibs_msys_collision(modulename)
Prevent loading choruslibs modules at the same time as desmond gpu code
Variables [hide private]
  __package__ = 'schrodinger.infra'
Function Details [hide private]

flag_context_manager(attr_name, set_to=True)

 

Create a context manager that sets the specified class attribute to the
given value and then restores the original value of the attribute when
leaving the context.

Example:

class Foo(object):
    _includingStructure = util.flag_context_manager("_including_structure")

    def __init__(self):
        self._including_structure = False

    def includeStructure(proj_row):
        with self._includingStructure():
            proj_row.in_workspace = project.IN_WORKSPACE

@see: L{skip_if}

@param attr_name: The attribute to set to C{set_to}
@type attr_name: str

@param set_to: The value to set C{attr_name} to
@type set_to: object

skip_if(attr_name, if_set_to=True)

 

Create a decorator that converts the decorated method to a no-op if class
attribute C{attr_name} equals C{is_set_to}.

Example:

skip_if_including_structure = util.skip_if("_including_structure")

class Foo(object):
    _includingStructure = util.flag_context_manager("_including_structure")

    def __init__(self):
        self._including_structure = False

    def includeStructure(proj_row):
        with self._includingStructure():
            proj_row.in_workspace = project.IN_WORKSPACE

    @skip_if_including_structure
    def skipped_method(self):
        print ("This method would have been skipped if we were the process "
               "of including a structure")

@see: L{flag_context_manager}

@param attr_name: The attribute name to check
@type attr_name: str

@param if_set_to: The decorated method will be skipped if C{attr_name}
equals this value.
@type if_set_to: object