pyTooling.CLIAbstraction

Basic abstraction layer for executables.

Submodules

Exceptions

Classes


Exceptions

exception pyTooling.CLIAbstraction.CLIAbstractionException[source]

Inheritance

Inheritance diagram of CLIAbstractionException

exception pyTooling.CLIAbstraction.DryRunException[source]

This exception is raised if an executable is launched while in dry-run mode.

Inheritance

Inheritance diagram of DryRunException


Classes

class pyTooling.CLIAbstraction.CLIArgument[source]

An attribute to annotate nested classes as an CLI argument.

Inheritance

Inheritance diagram of CLIArgument

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.CLIAbstraction.Environment(variables=None)[source]

Inheritance

Inheritance diagram of Environment

Parameters:

variables (Dict[str, str] | None)

__init__(variables=None)[source]
Parameters:

variables (Dict[str, str] | None)

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.

class pyTooling.CLIAbstraction.Program(executablePath=None, binaryDirectoryPath=None, dryRun=False)[source]

Represent a simple command line interface (CLI) executable (program or script).

Inheritance

Inheritance diagram of Program

Parameters:
  • executablePath (Path | None)

  • binaryDirectoryPath (Path | None)

  • dryRun (bool)

_executableNames: ClassVar[Dict[str, str]]

Dictionary of platform specific executable names.

__cliOptions__: ClassVar[Dict[Type[CommandLineArgument], int]]

List of all possible CLI options.

classmethod __init_subclass__(*args, **kwargs)[source]

Whenever a subclass is derived from :class:Program, all nested classes declared within Program and which are marked with attribute CLIArgument are collected and then listed in the __cliOptions__ dictionary.

Parameters:
__init__(executablePath=None, binaryDirectoryPath=None, dryRun=False)[source]
Parameters:
  • executablePath (Path | None)

  • binaryDirectoryPath (Path | None)

  • dryRun (bool)

Return type:

None

_platform: str

Current platform the executable runs on (Linux, Windows, …)

_dryRun: bool

True, if program shall run in dry-run mode.

_executablePath: Path

The path to the executable (binary, script, …).

__cliParameters__: Dict[Type[CommandLineArgument], Optional[CommandLineArgument]]

List of all CLI parameters (used CLI options).

__getitem__(key)[source]

Access to a CLI parameter by CLI option (key must be of type CommandLineArgument), which is already used.

__repr__()[source]

Return repr(self).

__str__()[source]

Return str(self).

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.CLIAbstraction.Executable(executablePath=None, binaryDirectoryPath=None, workingDirectory=None, dryRun=False)[source]

Represent a CLI executable derived from Program, that adds an abstraction of subprocess.Popen.

Inheritance

Inheritance diagram of Executable

Parameters:
  • executablePath (Path)

  • binaryDirectoryPath (Path)

  • workingDirectory (Path)

  • dryRun (bool)

__init__(executablePath=None, binaryDirectoryPath=None, workingDirectory=None, dryRun=False)[source]
Parameters:
  • executablePath (Path)

  • binaryDirectoryPath (Path)

  • workingDirectory (Path)

  • dryRun (bool)

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.

__cliOptions__: ClassVar[Dict[Type[CommandLineArgument], int]] = {}

List of all possible CLI options.

__cliParameters__: Dict[Type[CommandLineArgument], Optional[CommandLineArgument]]

List of all CLI parameters (used CLI options).

__getitem__(key)

Access to a CLI parameter by CLI option (key must be of type CommandLineArgument), which is already used.

classmethod __init_subclass__(*args, **kwargs)

Whenever a subclass is derived from :class:Program, all nested classes declared within Program and which are marked with attribute CLIArgument are collected and then listed in the __cliOptions__ dictionary.

Parameters:
__repr__()

Return repr(self).

__str__()

Return str(self).

_dryRun: bool

True, if program shall run in dry-run mode.

_executableNames: ClassVar[Dict[str, str]]

Dictionary of platform specific executable names.

_executablePath: Path

The path to the executable (binary, script, …).

_platform: str

Current platform the executable runs on (Linux, Windows, …)

class pyTooling.CLIAbstraction.OutputFilteredExecutable(platform, dryrun, executablePath)[source]

Inheritance

Inheritance diagram of OutputFilteredExecutable

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.

__cliOptions__: ClassVar[Dict[Type[CommandLineArgument], int]] = {}

List of all possible CLI options.

__cliParameters__: Dict[Type[CommandLineArgument], Optional[CommandLineArgument]]

List of all CLI parameters (used CLI options).

__getitem__(key)

Access to a CLI parameter by CLI option (key must be of type CommandLineArgument), which is already used.

classmethod __init_subclass__(*args, **kwargs)

Whenever a subclass is derived from :class:Program, all nested classes declared within Program and which are marked with attribute CLIArgument are collected and then listed in the __cliOptions__ dictionary.

Parameters:
__repr__()

Return repr(self).

__str__()

Return str(self).

_dryRun: bool

True, if program shall run in dry-run mode.

_executableNames: ClassVar[Dict[str, str]]

Dictionary of platform specific executable names.

_executablePath: Path

The path to the executable (binary, script, …).

_platform: str

Current platform the executable runs on (Linux, Windows, …)

__init__(platform, dryrun, executablePath)[source]
property HasWarnings

True if warnings were found while processing the output stream.

property HasErrors

True if errors were found while processing the output stream.

property HasFatals

True if fatals were found while processing the output stream.