ptypy.utils.descriptor.Descriptor#
- class ptypy.utils.descriptor.Descriptor(name, parent=None, separator='.')#
Bases:
objectBase class for parameter descriptions and validation. This class is used to hold both command line arguments and Param-type parameter descriptions.
- OPTIONS_DEF#
A dictionary whose keys are attribute names and values are description of the attribute. It this description contains the text “required” or “mandatory”, the attribute is registered as required.
- __init__(name, parent=None, separator='.')#
- Parameters:
name (str) – The name of the parameter represented by this instance
parent (Descriptor or None) – Parent parameter or None if no parent parameter.
separator (str) – Subtree separator character. Defaults to ‘.’.
Methods
__init__(name[, parent, separator])add_child(desc[, copy])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)new_child(name[, options, implicit])Create a new descendant and pass new options.
prune_child(name)Remove and return the parameter "name" and all its children.
save_conf_parser(fbuffer[, print_optional])Save Parameter defaults using Pythons ConfigParser
save_csv(fbuffer, **kwargs)Save to fbuffer.
save_json(fbuffer)Return the full content of descriptor as a string in configparser format.
Attributes
Iterator over all descendants as a pair (path name, object).
Type check
option_keysReturn complete path from root of parameter tree.
Return root of parameter tree.
Name of parameter
Parent parameter (
Descriptortype) if it has one.Hierarchical tree of sub-Parameters.
Attributes to the parameters.
- children#
Hierarchical tree of sub-Parameters.
- property descendants#
Iterator over all descendants as a pair (path name, object).
- 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 is_child#
Type check
- 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
- 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 (
Descriptortype) if it has one.
- 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.
- 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.