pyTooling.Attributes.ArgParse

Submodules

Classes

  • ArgParseAttribute: Base-class for all attributes to describe a argparse-base command line argument parser.

  • _HandlerMixin: A mixin-class that offers a class field for a reference to a handler method and a matching property.

  • CommandLineArgument: Base-class for all Argument classes.

  • CommandGroupAttribute: Experimental attribute to group sub-commands in groups for better readability in a prog.py --help call.

  • DefaultHandler: Marks a handler method as default handler. This method is called if no sub-command is given.

  • CommandHandler: Marks a handler method as responsible for the given ‘command’. This constructs

  • ArgParseHelperMixin: Mixin-class to implement an argparse-base command line argument processor.


Classes

class pyTooling.Attributes.ArgParse.ArgParseAttribute[source]

Base-class for all attributes to describe a argparse-base command line argument parser.

Inheritance

Inheritance diagram of ArgParseAttribute

classmethod GetAttributes(method, includeSubClasses=True)

Returns attached attributes of this kind for a given method.

Parameters:
  • method (MethodType)

  • includeSubClasses (bool)

Return type:

Tuple[Attribute, ...]

Returns:

Raises:

TypeError

classmethod GetClasses(scope=None, subclassOf=None)

Return a generator for all classes, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

  • subclassOf - when the item is a subclass of subclassOf.

Parameters:
Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of classes where this attribute is attached to.

classmethod GetFunctions(scope=None)

Return a generator for all functions, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of functions where this attribute is attached to.

classmethod GetMethods(scope=None)

Return a generator for all methods, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of methods where this attribute is attached to.

static _AppendAttribute(entity, attribute)

Append an attribute to a language entity (class, method, function).

Hint

This method can be used in attribute groups to apply multiple attributes within __call__ method.

class GroupAttribute(Attribute):
  def __call__(self, entity: Entity) -> Entity:
    self._AppendAttribute(entity, SimpleAttribute(...))
    self._AppendAttribute(entity, SimpleAttribute(...))

    return entity
Parameters:
Raises:

TypeError – If parameter ‘entity’ is not a class, method or function.

Return type:

None

__call__(entity)

Attributes get attached to an entity (function, class, method) and an index is updated at the attribute for reverse lookups.

Parameters:

entity (TypeVar(Entity, bound= Union[Type, Callable])) – Entity (function, class, method), to attach an attribute to.

Return type:

TypeVar(Entity, bound= Union[Type, Callable])

Returns:

Same entity, with attached attribute.

Raises:

TypeError – If parameter ‘entity’ is not a function, class nor method.

classmethod __init_subclass__(**kwargs)

Ensure each derived class has its own instance of _functions, _classes and _methods to register the usage of that Attribute.

Return type:

None

Parameters:

kwargs (Any)

_classes: ClassVar[List[Any]] = []

List of classes, this Attribute was attached to.

_functions: ClassVar[List[Any]] = []

List of functions, this Attribute was attached to.

_methods: ClassVar[List[Any]] = []

List of methods, this Attribute was attached to.

_scope: ClassVar[AttributeScope] = 7

Allowed language construct this attribute can be used with.

class pyTooling.Attributes.ArgParse._HandlerMixin[source]

A mixin-class that offers a class field for a reference to a handler method and a matching property.

Inheritance

_handler: Callable

Reference to a method that is called to handle e.g. a sub-command.

property Handler: Callable

Returns the handler method.

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

class pyTooling.Attributes.ArgParse.CommandLineArgument(*args, **kwargs)[source]

Base-class for all Argument classes.

An argument instance can be converted via AsArgument to a single string value or a sequence of string values (tuple) usable e.g. with subprocess.Popen. Each argument class implements at least one pattern parameter to specify how argument are formatted.

There are multiple derived formats supporting:

  • commands
    Command

  • simple names (flags)
    Flag, BooleanFlag

  • simple values (vlaued flags)
    StringArgument, PathArgument

  • names and values
    ValuedFlag, OptionalValuedFlag

  • key-value pairs
    NamedKeyValuePair

Inheritance

Inheritance diagram of CommandLineArgument

Parameters:
__init__(*args, **kwargs)[source]

The constructor expects positional (*args) and/or named parameters (**kwargs) which are passed without modification to add_argument().

Parameters:
Return type:

None

property Args: Tuple

A tuple of additional positional parameters (*args) passed to the attribute. These additional parameters are passed without modification to ArgumentParser.

property KWArgs: Dict

A dictionary of additional named parameters (**kwargs) passed to the attribute. These additional parameters are passed without modification to ArgumentParser.

classmethod GetAttributes(method, includeSubClasses=True)

Returns attached attributes of this kind for a given method.

Parameters:
  • method (MethodType)

  • includeSubClasses (bool)

Return type:

Tuple[Attribute, ...]

Returns:

Raises:

TypeError

classmethod GetClasses(scope=None, subclassOf=None)

Return a generator for all classes, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

  • subclassOf - when the item is a subclass of subclassOf.

Parameters:
Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of classes where this attribute is attached to.

classmethod GetFunctions(scope=None)

Return a generator for all functions, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of functions where this attribute is attached to.

classmethod GetMethods(scope=None)

Return a generator for all methods, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of methods where this attribute is attached to.

property Handler: Callable

Returns the handler method.

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

static _AppendAttribute(entity, attribute)

Append an attribute to a language entity (class, method, function).

Hint

This method can be used in attribute groups to apply multiple attributes within __call__ method.

class GroupAttribute(Attribute):
  def __call__(self, entity: Entity) -> Entity:
    self._AppendAttribute(entity, SimpleAttribute(...))
    self._AppendAttribute(entity, SimpleAttribute(...))

    return entity
Parameters:
Raises:

TypeError – If parameter ‘entity’ is not a class, method or function.

Return type:

None

__call__(entity)

Attributes get attached to an entity (function, class, method) and an index is updated at the attribute for reverse lookups.

Parameters:

entity (TypeVar(Entity, bound= Union[Type, Callable])) – Entity (function, class, method), to attach an attribute to.

Return type:

TypeVar(Entity, bound= Union[Type, Callable])

Returns:

Same entity, with attached attribute.

Raises:

TypeError – If parameter ‘entity’ is not a function, class nor method.

classmethod __init_subclass__(**kwargs)

Ensure each derived class has its own instance of _functions, _classes and _methods to register the usage of that Attribute.

Return type:

None

Parameters:

kwargs (Any)

_classes: ClassVar[List[Any]] = []

List of classes, this Attribute was attached to.

_functions: ClassVar[List[Any]] = []

List of functions, this Attribute was attached to.

_methods: ClassVar[List[Any]] = []

List of methods, this Attribute was attached to.

_scope: ClassVar[AttributeScope] = 7

Allowed language construct this attribute can be used with.

_handler: Callable

Reference to a method that is called to handle e.g. a sub-command.

class pyTooling.Attributes.ArgParse.CommandGroupAttribute(groupName)[source]

Experimental attribute to group sub-commands in groups for better readability in a prog.py --help call.

Inheritance

Inheritance diagram of CommandGroupAttribute

Parameters:

groupName (str)

__init__(groupName)[source]

The constructor expects a ‘groupName’ which can be used to group sub-commands for better readability.

Parameters:

groupName (str)

Return type:

None

property GroupName: str

Returns the name of the command group.

classmethod GetAttributes(method, includeSubClasses=True)

Returns attached attributes of this kind for a given method.

Parameters:
  • method (MethodType)

  • includeSubClasses (bool)

Return type:

Tuple[Attribute, ...]

Returns:

Raises:

TypeError

classmethod GetClasses(scope=None, subclassOf=None)

Return a generator for all classes, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

  • subclassOf - when the item is a subclass of subclassOf.

Parameters:
Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of classes where this attribute is attached to.

classmethod GetFunctions(scope=None)

Return a generator for all functions, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of functions where this attribute is attached to.

classmethod GetMethods(scope=None)

Return a generator for all methods, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of methods where this attribute is attached to.

static _AppendAttribute(entity, attribute)

Append an attribute to a language entity (class, method, function).

Hint

This method can be used in attribute groups to apply multiple attributes within __call__ method.

class GroupAttribute(Attribute):
  def __call__(self, entity: Entity) -> Entity:
    self._AppendAttribute(entity, SimpleAttribute(...))
    self._AppendAttribute(entity, SimpleAttribute(...))

    return entity
Parameters:
Raises:

TypeError – If parameter ‘entity’ is not a class, method or function.

Return type:

None

__call__(entity)

Attributes get attached to an entity (function, class, method) and an index is updated at the attribute for reverse lookups.

Parameters:

entity (TypeVar(Entity, bound= Union[Type, Callable])) – Entity (function, class, method), to attach an attribute to.

Return type:

TypeVar(Entity, bound= Union[Type, Callable])

Returns:

Same entity, with attached attribute.

Raises:

TypeError – If parameter ‘entity’ is not a function, class nor method.

classmethod __init_subclass__(**kwargs)

Ensure each derived class has its own instance of _functions, _classes and _methods to register the usage of that Attribute.

Return type:

None

Parameters:

kwargs (Any)

_classes: ClassVar[List[Any]] = []

List of classes, this Attribute was attached to.

_functions: ClassVar[List[Any]] = []

List of functions, this Attribute was attached to.

_methods: ClassVar[List[Any]] = []

List of methods, this Attribute was attached to.

_scope: ClassVar[AttributeScope] = 7

Allowed language construct this attribute can be used with.

class pyTooling.Attributes.ArgParse.DefaultHandler[source]

Marks a handler method as default handler. This method is called if no sub-command is given.

It’s an error, if more than one method is annotated with this attribute.

Inheritance

Inheritance diagram of DefaultHandler

__call__(func)[source]

Attributes get attached to an entity (function, class, method) and an index is updated at the attribute for reverse lookups.

Parameters:
  • entity – Entity (function, class, method), to attach an attribute to.

  • func (Callable)

Return type:

Callable

Returns:

Same entity, with attached attribute.

Raises:

TypeError – If parameter ‘entity’ is not a function, class nor method.

classmethod GetAttributes(method, includeSubClasses=True)

Returns attached attributes of this kind for a given method.

Parameters:
  • method (MethodType)

  • includeSubClasses (bool)

Return type:

Tuple[Attribute, ...]

Returns:

Raises:

TypeError

classmethod GetClasses(scope=None, subclassOf=None)

Return a generator for all classes, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

  • subclassOf - when the item is a subclass of subclassOf.

Parameters:
Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of classes where this attribute is attached to.

classmethod GetFunctions(scope=None)

Return a generator for all functions, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of functions where this attribute is attached to.

classmethod GetMethods(scope=None)

Return a generator for all methods, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of methods where this attribute is attached to.

property Handler: Callable

Returns the handler method.

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

static _AppendAttribute(entity, attribute)

Append an attribute to a language entity (class, method, function).

Hint

This method can be used in attribute groups to apply multiple attributes within __call__ method.

class GroupAttribute(Attribute):
  def __call__(self, entity: Entity) -> Entity:
    self._AppendAttribute(entity, SimpleAttribute(...))
    self._AppendAttribute(entity, SimpleAttribute(...))

    return entity
Parameters:
Raises:

TypeError – If parameter ‘entity’ is not a class, method or function.

Return type:

None

classmethod __init_subclass__(**kwargs)

Ensure each derived class has its own instance of _functions, _classes and _methods to register the usage of that Attribute.

Return type:

None

Parameters:

kwargs (Any)

_classes: ClassVar[List[Any]] = []

List of classes, this Attribute was attached to.

_functions: ClassVar[List[Any]] = []

List of functions, this Attribute was attached to.

_methods: ClassVar[List[Any]] = []

List of methods, this Attribute was attached to.

_scope: ClassVar[AttributeScope] = 7

Allowed language construct this attribute can be used with.

_handler: Callable

Reference to a method that is called to handle e.g. a sub-command.

class pyTooling.Attributes.ArgParse.CommandHandler(command, help='', **kwargs)[source]

Marks a handler method as responsible for the given ‘command’. This constructs a sub-command parser using add_subparsers().

Inheritance

Inheritance diagram of CommandHandler

Parameters:
__init__(command, help='', **kwargs)[source]

The constructor expects a ‘command’ and an optional list of named parameters (keyword arguments) which are passed without modification to add_subparsers().

Parameters:
Return type:

None

__call__(func)[source]

Attributes get attached to an entity (function, class, method) and an index is updated at the attribute for reverse lookups.

Parameters:
  • entity – Entity (function, class, method), to attach an attribute to.

  • func (M)

Return type:

TypeVar(M, bound= Callable)

Returns:

Same entity, with attached attribute.

Raises:

TypeError – If parameter ‘entity’ is not a function, class nor method.

property Command: str

Returns the ‘command’ a sub-command parser adheres to.

property Args: Tuple

A tuple of additional positional parameters (*args) passed to the attribute. These additional parameters are passed without modification to ArgumentParser.

property KWArgs: Dict

A dictionary of additional named parameters (**kwargs) passed to the attribute. These additional parameters are passed without modification to ArgumentParser.

classmethod GetAttributes(method, includeSubClasses=True)

Returns attached attributes of this kind for a given method.

Parameters:
  • method (MethodType)

  • includeSubClasses (bool)

Return type:

Tuple[Attribute, ...]

Returns:

Raises:

TypeError

classmethod GetClasses(scope=None, subclassOf=None)

Return a generator for all classes, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

  • subclassOf - when the item is a subclass of subclassOf.

Parameters:
Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of classes where this attribute is attached to.

classmethod GetFunctions(scope=None)

Return a generator for all functions, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of functions where this attribute is attached to.

classmethod GetMethods(scope=None)

Return a generator for all methods, where this attribute is attached to.

The resulting item stream can be filtered by:
  • scope - when the item is a nested class in scope scope.

Parameters:

scope (Optional[Type]) – Undocumented.

Return type:

Generator[TypeVar(TAttr, bound= Attribute), None, None]

Returns:

A sequence of methods where this attribute is attached to.

property Handler: Callable

Returns the handler method.

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

static _AppendAttribute(entity, attribute)

Append an attribute to a language entity (class, method, function).

Hint

This method can be used in attribute groups to apply multiple attributes within __call__ method.

class GroupAttribute(Attribute):
  def __call__(self, entity: Entity) -> Entity:
    self._AppendAttribute(entity, SimpleAttribute(...))
    self._AppendAttribute(entity, SimpleAttribute(...))

    return entity
Parameters:
Raises:

TypeError – If parameter ‘entity’ is not a class, method or function.

Return type:

None

classmethod __init_subclass__(**kwargs)

Ensure each derived class has its own instance of _functions, _classes and _methods to register the usage of that Attribute.

Return type:

None

Parameters:

kwargs (Any)

_classes: ClassVar[List[Any]] = []

List of classes, this Attribute was attached to.

_functions: ClassVar[List[Any]] = []

List of functions, this Attribute was attached to.

_methods: ClassVar[List[Any]] = []

List of methods, this Attribute was attached to.

_scope: ClassVar[AttributeScope] = 7

Allowed language construct this attribute can be used with.

_handler: Callable

Reference to a method that is called to handle e.g. a sub-command.

class pyTooling.Attributes.ArgParse.ArgParseHelperMixin(**kwargs)[source]

Mixin-class to implement an argparse-base command line argument processor.

Inheritance

Inheritance diagram of ArgParseHelperMixin

Parameters:

kwargs (Any)

__init__(**kwargs)[source]

The mixin-constructor expects an optional list of named parameters which are passed without modification to the ArgumentParser constructor.

Parameters:

kwargs (Any)

Return type:

None

class property HasClassAttributes: bool

Check if class has Attributes.

Returns:

True, if the class has Attributes.

class property HasMethodAttributes: bool

Check if class has any method with Attributes.

Returns:

True, if the class has any method with Attributes.

property MainParser: ArgumentParser

Returns the main parser.

property SubParsers: Dict

Returns the sub-parsers.