pyfarm.core.enums module

Enums

Provides enum values for certain aspect of PyFarm. See below for more detailed information.

Operating System

Describes an operating system type.

OperatingSystem
Attribute Description
LINUX operating system on agent is a Linux variant
WINDOWS operating system on agent is a Windows variant
MAC operating system on agent is an Apple OS variant
BSD operating system on agent is a BSD variant

Agent State

The last known state of the remote agent, used for making queue decisions and locking off resources.

Attribute Description
OFFLINE agent cannot be reached
ONLINE agent is waiting for work
DISABLED agent is online but cannot accept work
RUNNING agent is currently processing work
ALLOC special internal state used when the agent entry is being built

Work State

The state a job or task is currently in. These values apply more directly to tasks as job statuses are built from task status values.

Attribute Description
PAUSED this task cannot be assigned right now but can be once unpaused
RUNNING work is currently being processed
DONE work is finished (previous failures may be present)
FAILED work as failed and cannot be continued

Use Agent Address

Describes which address should be used to contact the agent

Attribute Description
LOCAL use the address which was provided by the agent
REMOTE use the address which we received the request from
HOSTNAME disregard both the local IP and the remote IP and use the hostname
PASSIVE agent cannot be contacted but will still request work and process jobs
const PY_MAJOR:the major Python version
const PY_MINOR:the minor Python version
const PY_VERSION:
 a tuple containing the major and minor Python versions
const PY3:True if running Python 3
const PY2:True if running Python 2
const PY26:True if running Python 2.6
const PY27:True if running Python 2.7
const NOTSET:Instance of the object class, mainly used when None is actually a valid value
const STRING_TYPES:
 A tuple of string types, provided for Python 3 backwards compatibility
const NUMERIC_TYPES:
 A tuple of numeric types, provided for Python 3 backwards compatibility
const INTEGER_TYPES:
 A tuple of integer types, provided for Python 3 backwards compatibility
const BOOLEAN_TRUE:
 A set containing strings and other objects representing True under some conditions. Generally used by pyfarm.core.utility.convert.bool()
const BOOLEAN_FALSE:
 A set containing strings and other objects representing False under some conditions. Generally used by pyfarm.core.utility.convert.bool()
const NONE:A set containing strings and other objects which represent None under some conditions. Generally used by pyfarm.core.utility.convert.none()
const INTERACTIVE_INTERPRETER:
 True when we’re running inside an interactive interpreter such as a Python shell like IPython. This value will also be True if there’s an active debugger.
const OS:The current os type, the value will map to one of the values in OperatingSystem
const POSIX:True if OS in (OperatingSystem.LINUX, OperatingSystem.MAC)
const WINDOWS:True if OS == OperatingSystem.WINDOWS
const LINUX:True if OS == OperatingSystem.LINUX
const MAC:True if OS == OperatingSystem.MAC
pyfarm.core.enums.Enum(classname, **kwargs)

Produce an enum object using namedtuple()

>>> Foo = Enum("Foo", A=1, B=2)
>>> assert Foo.A == 1 and Foo.B == 2
>>> FooTemplate = Enum("Foo", A=int, instance=False)
>>> Foo = FooTemplate(A=1)
>>> assert Foo.A == 1
Parameters:
  • classname (str) – the name of the class to produce
  • to_dict – a callable function to add to the named tuple for converting the internal values into a dictionary
  • instance (bool) – by default calling Enum() will produce an instanced namedtuple() object, setting instance to False will instead produce the named tuple without instancing it
class pyfarm.core.enums.Values(*args, **kwargs)

Bases: pyfarm.core.enums.Values

Stores values to be used in an enum. Each time this class is instanced it will ensure that the input values are of the correct type and unique.

NUMERIC_TYPES = (<class 'int'>,)
check_uniqueness = True
pyfarm.core.enums.cast_enum(enum, enum_type)

Pulls the requested enum_type from enum and produce a new named tuple which contains only the requested data

>>> from pyfarm.core.enums import Enum, Values
>>> FooBase = Enum("Foo", A=Values(int=1, str="1")
>>> Foo = cast_enum(FooBase, str)
>>> assert Foo.A == "1"
>>> Foo = cast_enum(FooBase, int)
>>> assert Foo.A == 1
>>> assert Foo._map == {"A": 1, 1: "A"}

Warning

This function does not perform any kind of caching. For the most efficient usage it should only be called once per process or module for a given enum and enum_type combination.

pyfarm.core.enums.operating_system(plat='linux')

Returns the operating system for the given platform. Please note that while you can call this function directly you’re more likely better off using values in pyfarm.core.enums instead.