Tollan Documentation

The tollan package includes various utility routines that are shared across the python packages developed for the TolTEC project.

Reference/API

tollan Package

tollan.utils Package

Functions

rgetattr(obj, attr, *args)

Get attribute recursively.

getobj(name, *args)

Return python object specified by name.

get_pkg_data_path()

Return the package data path.

make_subprocess_env()

odict_from_list(lst, key)

Return an ordered dict from list.

patchit(obj, name[, pass_patched])

Return a decorator that replace attribute with decorated item.

mapsum(map_func, gen, *args, **kwargs)

Return a map and sum generator.

to_typed(s)

Return a typed object from string s if possible.

dict_from_regex_match(pattern, input_[, …])

Return a dict from matching pattern to input_.

fileloc(loc[, local_parent_path, …])

Return a FileLoc object.

ensure_prefix(s, p)

Return a new string with prefix p if it does not.

anysum(a, b)

Return the sum of two objects.

rupdate(d, u)

Update dict recursively.

module_from_path(filepath[, name])

Load module from filepath.

call_subprocess_with_live_output(cmd)

Execute cmd in subprocess with live output.

get_user_data_dir()

rreload(m)

Reload module recursively.

mapreduce(map_func, reduce_func, gen, *args, …)

Return a map and reduce generator.

Classes

hookit(obj, name)

A context manager that allow inject code to object’s method.

FileLoc(uri, netloc, path)

A simple structure to hold file location info.

Class Inheritance Diagram

Inheritance diagram of tollan.utils.misc.hookit, tollan.utils.misc.FileLoc

tollan.utils.cli.click_helpers Module

Functions

varg_command(cli, name, *others)

Create positional argument that are of variable length.

hook_ctx_make_context(group)

A context manager that hook the make context function to reuse context object.

ctx_no_recreate_obj(ctx)

Return True if context object should not be recreated.

tollan.utils.cli.multi_action_argparser Module

Classes

MultiActionArgumentParser(*args, **kwargs)

This class wraps the argparse.ArgumentParser so that it allows defining subcommands with ease.

Class Inheritance Diagram

Inheritance diagram of tollan.utils.cli.multi_action_argparser.MultiActionArgumentParser

tollan.utils.cli.path_type Module

Classes

PathType([exists, type_])

A class that facilitates path-like argument for Argument

Class Inheritance Diagram

Inheritance diagram of tollan.utils.cli.path_type.PathType

tollan.utils.db Package

Classes

TableDef

A class that holds definitions to a table.

TableDefList(table_defs)

SqlaDB

A class that provide access to database related entities similar to that of flask_sqlalchemy.SQLAlchemy.

Class Inheritance Diagram

Inheritance diagram of tollan.utils.db.TableDef, tollan.utils.db.TableDefList, tollan.utils.db.SqlaDB

tollan.utils.db.conventions Module

This module defines a set of helpers for defining database with some column naming conventions.

Functions

name(**kwargs)

updated_at(**kwargs)

pg_utcnow(element, compiler, **kw)

table_info_table()

pk(**kwargs)

desc(**kwargs)

default_sql_utcnow(element, compiler, **kw)

client_info_fk(**kwargs)

label(**kwargs)

fk(other[, name])

client_info_model(Base)

ms_utcnow(element, compiler, **kw)

created_at(**kwargs)

pfk(other[, name])

client_info_table()

Classes

utcnow(*clauses, **kwargs)

Construct a FunctionElement.

Class Inheritance Diagram

Inheritance diagram of tollan.utils.db.conventions.utcnow

tollan.utils.env Module

Classes

EnvRegistry

A registry class that helps work with env vars.

Class Inheritance Diagram

Inheritance diagram of tollan.utils.env.EnvRegistry

tollan.utils.fmt Module

Functions

pformat_paths(paths[, sep, relative_to, sort])

pformat_list(lst, indent[, minw, …])

pformat_dict(d[, indent, minw])

pformat_obj(m)

Return info of python object.

pformat_yaml(obj)

pformat_fancy_index(i)

model_to_dict(m)

tollan.utils.log Package

Functions

init_log([preset, level, file_, colored])

Initialize logging with some sensible presets.

get_logger([name])

Return a logger named name if specified, otherwise use the name of the calling context.

Classes

timeit(arg)

Context decorator that logs the execution time of the decorated item.

logit(log, msg)

Decorator that logs the execution of the decorated item.

Class Inheritance Diagram

Inheritance diagram of tollan.utils.log.timeit, tollan.utils.log.logit

tollan.utils.mpl Module

Some matplotlib helpers.

Functions

save_or_show(fig, filepath[, bbox_inches, …])

Save figure or show plot, depending on the last sys.argv

tollan.utils.namespace Module

Functions

object_from_dict(d[, …])

Construct a Namespace object from dict.

dict_from_object(obj[, keys_attr, …])

Return a dict composed from object’s attributes.

Classes

NamespaceNotFoundError

NamespaceTypeError

Namespace

A convenient class that manages a set of attributes.

Class Inheritance Diagram

Inheritance diagram of tollan.utils.namespace.NamespaceNotFoundError, tollan.utils.namespace.NamespaceTypeError, tollan.utils.namespace.Namespace

tollan.utils.nc Package

Functions

ncopen(source, **kwargs)

Return a context manager to open netCDF file.

ncinfo(source)

Return a pretty formatted string for netCDF4 dataset.

Classes

NcNodeMapper([nc_node_map, source])

A adaptor class that accesses netCDF4 dataset with a custom name map.

Class Inheritance Diagram

Inheritance diagram of tollan.utils.nc.NcNodeMapper

tollan.utils.np Module

Functions

flex_reshape(arr, shape[, trim_option])

Reshape an array with possible trimming of extraneous items.

tollan.utils.registry Module

Functions

register_to(registry, key)

Register the decorated item with key.

Classes

Registry

Class Inheritance Diagram

Inheritance diagram of tollan.utils.registry.Registry

tollan.utils.slice Module

Functions

resolve_slice(slice_, n)

Return a bounded slice given length n.

parse_slice(slice_str)

Return a slice object from string.

Classes

BoundedSliceChain(range_[, n])

A chain of slices, with known array size.

UnboundedSliceChain([slices])

A chain of slices.

XLoc(func)

This provides a interface similar to that of pandas DataFrame.xloc.

Class Inheritance Diagram

Inheritance diagram of tollan.utils.slice.BoundedSliceChain, tollan.utils.slice.UnboundedSliceChain, tollan.utils.slice.XLoc

tollan.utils.wraps Package

Functions

get_wraps_dir()

Return the directory for saving wrappers.

tollan.utils.dirconf Module

Classes

DirConfError

Raise when errors occur in DirConfig.

DirConfMixin()

A mix-in class for managing configuration files stored in a directory.

Class Inheritance Diagram

Inheritance diagram of tollan.utils.dirconf.DirConfError, tollan.utils.dirconf.DirConfMixin

tollan.utils.sys Module

Functions

get_hostname()

Same as the shell command hostname

touch_file(out_file)

Same as the shell command touch.

tollan.utils.schema Module

Functions

create_relpath_validator(rootpath)

Return validator to validate a relative path.

make_nested_optional_defaults(s)

Return a schema that has optional defaults computed from nested schema.