ptypy.utils.descriptor.EvalDescriptor#

class ptypy.utils.descriptor.EvalDescriptor(name, parent=None, separator='.')#

Bases: ArgParseDescriptor

Parameter class to store metadata for all ptypy parameters (default, limits, documentation, etc.)

__init__(name, parent=None, separator='.')#

Parameter class to store metadata for all ptypy parameters (default, limits, documentation, etc.)

Methods

__init__(name[, parent, separator])

Parameter class to store metadata for all ptypy parameters (default, limits, documentation, etc.)

add2argparser([parser, prefix, excludes, mode])

Add parameter to an argparse.ArgumentParser instance (or create and return one if parser is None) prefix is

add_child(desc[, copy])

check(pars[, depth])

Check that input parameter pars is consistent with parameter description, up to given depth.

create_template([filename, start_at_root, ...])

Creates templates for ptypy scripts from an EvalDescriptor instance.

eval(val)

A more verbose wrapper around ast.literal_eval

from_string(s[, strict])

Load Parameter from string using Python's ConfigParser

get(path)

return self.root[path] if it exists, None otherwise.

load_conf_parser(fbuffer, **kwargs)

Load Parameter defaults using Python's ConfigParser

load_csv(fbuffer, **kwargs)

Load from csv as a fielded array.

load_json(fbuffer)

make_default([depth])

Creates a default parameter structure.

make_doc_rst(prst[, use_root])

Pretty-print in RST format the whole structure.

new_child(name[, options, implicit])

Create a new descendant and pass new options.

parse_doc([name, recursive])

Decorator to parse docstring and automatically attach new parameters.

prune_child(name)

Remove and return the parameter "name" and all its children.

sanity_check([depth])

Checks if default parameters from configuration are self-constistent with limits and choices.

save_conf_parser(fbuffer[, print_optional])

Save Parameter defaults using Pythons ConfigParser

save_csv(fbuffer, **kwargs)

Save to fbuffer.

save_json(fbuffer)

to_string()

Return the full content of descriptor as a string in configparser format.

validate(pars[, raisecodes])

Check that the parameter structure pars matches the documented constraints for this node / parameter.

Attributes

OPTIONS_DEF

choices

If parameter is a list of choices, these are listed here.

default

Default value as a Python type

descendants

Iterator over all descendants as a pair (path name, object).

doc

Long documentation, may contain sphinx inline markup.

help

Short descriptive explanation of parameter

is_child

Type check

is_evaluable

is_symlink

True if type/default are symlinks.

is_target

True if parent of symlink targets.

limits

(lower, upper) limits if applicable.

option_keys

path

Return complete path from root of parameter tree.

root

Return root of parameter tree.

type

List of possible data types.

userlevel

User level, a higher level means a parameter that is less likely to vary or harder to understand.

name

Name of parameter

parent

Parent parameter (Descriptor type) if it has one.

children

Hierarchical tree of sub-Parameters.

options

Attributes to the parameters.

add2argparser(parser=None, prefix='', excludes=('scans', 'engines'), mode='add')#

Add parameter to an argparse.ArgumentParser instance (or create and return one if parser is None) prefix is

check(pars, depth=99)#

Check that input parameter pars is consistent with parameter description, up to given depth.

Parameters:
  • pars (The input parameter or parameter tree)

  • depth (The level at wich verification is done.)

Return type:

A dictionary report using CODES values.

children#

Hierarchical tree of sub-Parameters.

property choices#

If parameter is a list of choices, these are listed here.

create_template(filename=None, start_at_root=True, user_level=0, doc_level=2)#

Creates templates for ptypy scripts from an EvalDescriptor instance.

property default#

Default value as a Python type

property descendants#

Iterator over all descendants as a pair (path name, object).

property doc#

Long documentation, may contain sphinx inline markup.

eval(val)#

A more verbose wrapper around ast.literal_eval

from_string(s, strict=False, **kwargs)#

Load Parameter from string using Python’s ConfigParser

Each parameter occupies its own section. Separator characters in sections names map to a tree-hierarchy.

Keyword arguments are forwarded to ConfigParser.RawConfigParser

get(path)#

return self.root[path] if it exists, None otherwise.

property help#

Short descriptive explanation of parameter

property is_child#

Type check

True if type/default are symlinks.

property is_target#

True if parent of symlink targets.

property limits#

(lower, upper) limits if applicable. (None, None) otherwise

load_conf_parser(fbuffer, **kwargs)#

Load Parameter defaults using Python’s ConfigParser

Each parameter occupies its own section. Separator characters in sections names map to a tree-hierarchy.

Keyword arguments are forwarded to ConfigParser.RawConfigParser

load_csv(fbuffer, **kwargs)#

Load from csv as a fielded array. Keyword arguments are passed on to csv.DictReader

make_default(depth=0)#

Creates a default parameter structure.

Parameters:

depth (int) – The depth in the structure to which all sub nodes are expanded All nodes beyond depth will be ignored.

Returns:

pars – A parameter branch as Param.

Return type:

Param

Examples

>>> from ptypy.utils.descriptor import defaults_tree
>>> print(defaults_tree['io'].make_default(depth=5))
make_doc_rst(prst, use_root=True)#

Pretty-print in RST format the whole structure.

name#

Name of parameter

new_child(name, options=None, implicit=False)#

Create a new descendant and pass new options.

If name contains separators, intermediate children are created.

If name already exists, update options and return existing child.

If name already exists and had been created implicitly to create a child further down, the order in self.children is corrected to honor the order of explicitly created children. This behaviour can be deactivated by setting implicit=True.

options#

Attributes to the parameters.

parent#

Parent parameter (Descriptor type) if it has one.

parse_doc(name=None, recursive=True)#

Decorator to parse docstring and automatically attach new parameters. The parameter section is identified by a line starting with the word “Parameters”

Parameters:
  • name (str) – The descendant name under which all parameters will be held. If None, use self.

  • recursive (bool) – Whether or not to traverse the docstring of base classes. Is there are use case for this?

Return type:

The decorator function.

property path#

Return complete path from root of parameter tree. (self.root[self.path] == self should always be True unless self.root is root)

prune_child(name)#

Remove and return the parameter “name” and all its children. :param name: The descendant name :return: The Parameter object.

property root#

Return root of parameter tree.

sanity_check(depth=10)#

Checks if default parameters from configuration are self-constistent with limits and choices.

save_conf_parser(fbuffer, print_optional=True)#

Save Parameter defaults using Pythons ConfigParser

Each parameter occupies its own section. Separator characters in sections names map to a tree-hierarchy.

save_csv(fbuffer, **kwargs)#

Save to fbuffer. Keyword arguments are passed on to csv.DictWriter

to_string()#

Return the full content of descriptor as a string in configparser format.

property type#

List of possible data types.

property userlevel#

User level, a higher level means a parameter that is less likely to vary or harder to understand.

validate(pars, raisecodes=(0, 4))#

Check that the parameter structure pars matches the documented constraints for this node / parameter.

The function raises a RuntimeError if one of the code in the list raisecodes has been found. If raisecode is empty, the function will always return successfully but problems will be logged using logger.

Parameters:
  • pars (Param, dict) – A parameter set to validate

  • raisecodes (list) – List of codes that will raise a RuntimeError.