Cyclopts Tools Module – cyclopts.tools

This module provides a variety of utilities that are useful when working with Cyclopts.

Provides some useful tools for working with Cyclopts, including reporting output.

author:Matthew Gidden <matthew.gidden _at_ gmail.com>
class cyclopts.tools.Incrementer(start=0)[source]

A simple helper class to increment a value

Parameters:

start : int, optional

an initial value

next()[source]

Returns an incremented value

class cyclopts.tools.RunControl(**kwargs)[source]

A composable configuration class for cyclopts. Unlike argparse.Namespace, this keeps the object dictionary (__dict__) separate from the run control attributes dictionary (_dict). Modified from xdress’ run control in xdress/utils.py

Parameters:

kwargs : optional

Items to place into run control.

cyclopts.tools.collect_instids(h5file, path, rc=None, instids=None, colname='instid')[source]

Collects all instids as specified.

If rc and instids is None, all ids found in the h5file’s path are collected. Otherwise, instids provided by the instid listing and the paramater space defined by the run control inst_queries parameter are collected.

Parameters:

h5file : PyTables File object

the file to collect ids from

path : str

the path to a property table node

rc : RunControl object, optional

a run control object specifying a subset of instids to collect

instids : collection of uuids

explicit instids to collect

colname : str

the instance id column name

cyclopts.tools.combine(files, new_file=None, clean=False)[source]

Combines two or more databases with identical layout, writing their output into a new file or appending to the first in the list.

Parameters:

files : iterator

An iterator listing all databases to combine

new_file : str, optional

The new database to write to. If None, all databases are appended to the end of the first database in the list.

clean : bool, optional

Whether to remove original files after combining them

cyclopts.tools.cyc_members(obj)[source]

return a list of persistable members per the Cyclopts style guide.

cyclopts.tools.exec_file(filename, glb=None, loc=None)[source]

A function equivalent to the Python 2.x execfile statement. Taken from xdress/utils.py

cyclopts.tools.expand_args(x)[source]
Parameters:

x : list of lists of arguments

Returns:

args : generator

a generator that returns a collection of single arguments

cyclopts.tools.get_obj(kind=None, rcs=None, args=None)[source]

Get an object of certain kind, e.g. species or family. Both the rc and args argument will be searched for attributes named <kind>_package, <kind>_module, and <kind>_cname. The package/module is then imported and an instance of the cname is returned. The CLI is searched before the rcs.

Parameters:

kind : str

the kind of object

rcs : list of RunControl objects or single object, optional

rcs are checked in order

args : argparse args, optional

CLI args

cyclopts.tools.get_process_children(pid)[source]
cyclopts.tools.memusg(pid)[source]

in kb

cyclopts.tools.n_permutations(x, iter_keys=, []recurse=True)[source]
Parameters:

x : dict, list, or other

iter_keys : a list of keys atomic values should be iterables, optional

recurse : bool, whether to recurse at the lowest level

Returns:

n : int

the total number of permutations of values in x, if x has container values, those are recusively interrogated as well

cyclopts.tools.obj_info(kind=None, rcs=None, args=None)[source]

Get information about an importable object

Parameters:

kind : str

the kind of object

rcs : list of RunControl objects or single object, optional

rcs are checked in order

args : argparse args, optional

CLI args

cyclopts.tools.parse_rc(files)[source]

Parse a list of rc files.

Parameters:

files : list or str

the files to parse

Returns:

rc : RunControl

cyclopts.tools.ssh_test_connect(client, host, user, keyfile=None, auth=True)[source]

Tests an ssh connection and returns success or failure thereof.

Parameters:

client : paramiko SSH client

host : str

user : str

keyfile : str, optional

auth : bool, optional

whether to prompt for a password authorization on failure

This Page