ptypy.utils.descriptor.ArgParseDescriptor#
- class ptypy.utils.descriptor.ArgParseDescriptor(name, parent=None, separator='.')#
Bases:
Descriptor- __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])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])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)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
OPTIONS_DEFIf parameter is a list of choices, these are listed here.
Returns default as a Python type
Iterator over all descendants as a pair (path name, object).
Short descriptive explanation of parameter
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.
- 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
- children#
Hierarchical tree of sub-Parameters.
- property choices#
If parameter is a list of choices, these are listed here.
- property default#
Returns default as a Python type
- property descendants#
Iterator over all descendants as a pair (path name, object).
- 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
- 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.