caikit.core.toolkit.wip_decorator

Attributes

log

error

message_format

_ENABLE_DECORATOR

Classes

WipCategory

Create a collection of name/value pairs.

Action

Create a collection of name/value pairs.

TempDisableWIP

Temporarily disable wip decorator for a particular block of code

Functions

disable_wip()

Utility function to disable decorator functionality.

enable_wip()

Utility function to enable decorator functionality.

work_in_progress(*args, **kwargs)

Decorator that can be used to mark a function

_decorator_handler(wrapped_obj, category, action)

Utility function to cover common decorator handling

_get_message(wrapped_obj, category, action)

Utility function to run action

Module Contents

caikit.core.toolkit.wip_decorator.log[source]
caikit.core.toolkit.wip_decorator.error
caikit.core.toolkit.wip_decorator.message_format = '{} is still in the {} phase and subject to change!'
caikit.core.toolkit.wip_decorator._ENABLE_DECORATOR = True
class caikit.core.toolkit.wip_decorator.WipCategory(*args, **kwds)[source]

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

WIP = 1
BETA = 2
class caikit.core.toolkit.wip_decorator.Action(*args, **kwds)[source]

Bases: enum.Enum

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access:

>>> Color.RED
<Color.RED: 1>
  • value lookup:

>>> Color(1)
<Color.RED: 1>
  • name lookup:

>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes – see the documentation for details.

ERROR = 1
WARNING = 2
caikit.core.toolkit.wip_decorator.disable_wip()[source]

Utility function to disable decorator functionality. Mainly designed for testing

caikit.core.toolkit.wip_decorator.enable_wip()[source]

Utility function to enable decorator functionality. Mainly designed for testing

class caikit.core.toolkit.wip_decorator.TempDisableWIP[source]

Temporarily disable wip decorator for a particular block of code

NOTE: There is a potential race condition possible here in cases where other code using wip decorator gets called at the same time this context based disabling functionality is invoked. If this happens, the decorator will get disabled for all the functions invoking at the same time. This is because we are using the global disable / enable functions for this class.

__enter__()[source]
__exit__(*args)[source]
caikit.core.toolkit.wip_decorator.work_in_progress(*args, **kwargs)[source]

Decorator that can be used to mark a function or a class as “work in progress”. It will result in a warning being emitted when the function / class is used.

Args:
category (WipCategory): Enum specifying what category of message you

want to throw

action (Action): Enum specifying what type of action you want to take.

Example: ERROR or WARNING

Example Usage:

### Decorating class

  1. No configuration:

    @work_in_progress class Foo:

    pass

  2. Action and category configuration:

    @work_in_progress(action=Action.WARNING, category=WipCategory.BETA) class Foo:

    pass

### Decorating Function:

  1. No configuration:

    @work_in_progress def foo(*args, **kwargs):

    pass

  2. Action and category configuration:
    @work_in_progress(action=Action.WARNING, category=WipCategory.BETA)
    def foo(*args, **kwargs):

    pass

### Sample message:

foo is still in the BETA phase and subject to change!

caikit.core.toolkit.wip_decorator._decorator_handler(wrapped_obj, category, action)[source]

Utility function to cover common decorator handling logic. Args:

wrapped_obj (Callable): Class or function to be decorated category (Enum(WipCategory)): Enum specifying the category of the

message

Action (Enum(Action)): Enum specifying the action to be taken with the

decorator

Returns:
function:

Decorator function

caikit.core.toolkit.wip_decorator._get_message(wrapped_obj, category, action)[source]

Utility function to run action