pyTooling.Attributes.ArgParse
Submodules
Classes
ArgParseAttribute
: Base-class for all attributes to describe aargparse
-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 aprog.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 constructsArgParseHelperMixin
: Mixin-class to implement anargparse
-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
- classmethod GetAttributes(method, includeSubClasses=True)
Returns attached attributes of this kind for a given method.
- 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 scopescope
.subclassOf
- when the item is a subclass ofsubclassOf
.
- Parameters:
- Return type:
- 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 scopescope
.
- 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 scopescope
.
- 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
- __call__(entity)
Attributes get attached to an entity (function, class, method) and an index is updated at the attribute for reverse lookups.
- classmethod __init_subclass__(**kwargs)
Ensure each derived class has its own instance of
_functions
,_classes
and_methods
to register the usage of that Attribute.
- _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
- 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. withsubprocess.Popen
. Each argument class implements at least onepattern
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
- __init__(*args, **kwargs)[source]
The constructor expects positional (
*args
) and/or named parameters (**kwargs
) which are passed without modification toadd_argument()
.
- property Args: Tuple
A tuple of additional positional parameters (
*args
) passed to the attribute. These additional parameters are passed without modification toArgumentParser
.
- property KWArgs: Dict
A dictionary of additional named parameters (
**kwargs
) passed to the attribute. These additional parameters are passed without modification toArgumentParser
.
- classmethod GetAttributes(method, includeSubClasses=True)
Returns attached attributes of this kind for a given method.
- 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 scopescope
.subclassOf
- when the item is a subclass ofsubclassOf
.
- Parameters:
- Return type:
- 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 scopescope
.
- 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 scopescope
.
- 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
- __call__(entity)
Attributes get attached to an entity (function, class, method) and an index is updated at the attribute for reverse lookups.
- classmethod __init_subclass__(**kwargs)
Ensure each derived class has its own instance of
_functions
,_classes
and_methods
to register the usage of that Attribute.
- _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
- 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
- classmethod GetAttributes(method, includeSubClasses=True)
Returns attached attributes of this kind for a given method.
- 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 scopescope
.subclassOf
- when the item is a subclass ofsubclassOf
.
- Parameters:
- Return type:
- 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 scopescope
.
- 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 scopescope
.
- 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
- __call__(entity)
Attributes get attached to an entity (function, class, method) and an index is updated at the attribute for reverse lookups.
- classmethod __init_subclass__(**kwargs)
Ensure each derived class has its own instance of
_functions
,_classes
and_methods
to register the usage of that Attribute.
- _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
- __call__(func)[source]
Attributes get attached to an entity (function, class, method) and an index is updated at the attribute for reverse lookups.
- classmethod GetAttributes(method, includeSubClasses=True)
Returns attached attributes of this kind for a given method.
- 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 scopescope
.subclassOf
- when the item is a subclass ofsubclassOf
.
- Parameters:
- Return type:
- 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 scopescope
.
- 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 scopescope
.
- 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
- classmethod __init_subclass__(**kwargs)
Ensure each derived class has its own instance of
_functions
,_classes
and_methods
to register the usage of that Attribute.
- _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
- __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()
.
- __call__(func)[source]
Attributes get attached to an entity (function, class, method) and an index is updated at the attribute for reverse lookups.
- property Args: Tuple
A tuple of additional positional parameters (
*args
) passed to the attribute. These additional parameters are passed without modification toArgumentParser
.
- property KWArgs: Dict
A dictionary of additional named parameters (
**kwargs
) passed to the attribute. These additional parameters are passed without modification toArgumentParser
.
- classmethod GetAttributes(method, includeSubClasses=True)
Returns attached attributes of this kind for a given method.
- 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 scopescope
.subclassOf
- when the item is a subclass ofsubclassOf
.
- Parameters:
- Return type:
- 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 scopescope
.
- 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 scopescope
.
- 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
- classmethod __init_subclass__(**kwargs)
Ensure each derived class has its own instance of
_functions
,_classes
and_methods
to register the usage of that Attribute.
- _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
- 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
- property MainParser: ArgumentParser
Returns the main parser.