6. dxpy.utils Module

Utilities used in the DNAnexus execution environment and test harness.

dxpy.utils.exec_utils.run(function_name=None, function_input=None)[source]

Triggers the execution environment entry point processor.

Use this function in the program entry point code:

import dxpy

@dxpy.entry_point('main')
def hello(i):
    pass

dxpy.run()

This method may be used to invoke the program either in a production environment (inside the execution environment) or for local debugging (in the debug harness), as follows:

If the environment variable DX_JOB_ID is set, the processor retrieves the job with that ID from the API server. The job’s function field indicates the function name to be invoked. That function name is looked up in the table of all methods decorated with @dxpy.entry_point(‘name’) in the module from which run() was called, and the matching method is invoked (with the job’s input supplied as parameters). This is the mode of operation used in the DNAnexus execution environment.

Warning

The parameters function_name and function_input are disregarded in this mode of operation.

If the environment variable DX_JOB_ID is not set, the function name may be given in function_name; if not set, it is set by the environment variable DX_TEST_FUNCTION. The function input may be given in function_input; if not set, it is set by the local file job_input.json which is expected to be present.

The absence of DX_JOB_ID signals to run() that execution is happening in the debug harness. In this mode of operation, all calls to dxpy.bindings.dxjob.new_dxjob() (and higher level handler methods which use it) are intercepted, and run() is invoked instead with appropriate inputs.

dxpy.utils.exec_utils.entry_point(entry_point_name)[source]

Use this to decorate a DNAnexus execution environment entry point.

Example:

@dxpy.entry_point('main')
def hello(i):
    pass
class dxpy.utils.exec_utils.DXJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Like json.JSONEncoder, but converts DXObject objects into dxlinks.

Constructor for JSONEncoder, with sensible defaults.

If skipkeys is false, then it is a TypeError to attempt encoding of keys that are not str, int, float or None. If skipkeys is True, such items are simply skipped.

If ensure_ascii is true, the output is guaranteed to be str objects with all incoming non-ASCII characters escaped. If ensure_ascii is false, the output can contain non-ASCII characters.

If check_circular is true, then lists, dicts, and custom encoded objects will be checked for circular references during encoding to prevent an infinite recursion (which would cause an RecursionError). Otherwise, no such check takes place.

If allow_nan is true, then NaN, Infinity, and -Infinity will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise, it will be a ValueError to encode such floats.

If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure that JSON serializations can be compared on a day-to-day basis.

If indent is a non-negative integer, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0 will only insert newlines. None is the most compact representation.

If specified, separators should be an (item_separator, key_separator) tuple. The default is (’, ‘, ‘: ‘) if indent is None and (‘,’, ‘: ‘) otherwise. To get the most compact JSON representation, you should specify (‘,’, ‘:’) to eliminate whitespace.

If specified, default is a function that gets called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError.

default(obj)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
exception dxpy.utils.exec_utils.DXExecDependencyError[source]
class dxpy.utils.exec_utils.DXExecDependencyInstaller(executable_desc, job_desc, logger=None)[source]

Installs dependencies specified by the job.

Dependencies are processed in the order specified in the bundledDepends, execDepends, and dependencies arrays of the runSpec hash (the former two are deprecated). Neighboring package dependencies of the same type are grouped.

Parameters:
  • executable_desc (dict) –

    The description of the executable of this job, which can be obtained in the response of the /executable-x/describe request. This dict must contain the following keys:

    • ”runSpec”

  • job_desc (dict) –

    The description of this job, which can be obtained in the response of the /job-x/describe request. If executable_desc["runSpec"] has key “bundledDependsByRegion”, then this dict must contain the following keys:

    • ”region”