pyTooling.CLIAbstraction
pyTooling.CLIAbstraction is an abstraction layer and wrapper for command line programs, so they can be used easily in
Python. All parameters like --value=42 are described as parameters of the executable.
Main Goals
- Offer access to CLI programs as Python classes.
- Abstract CLI arguments (a.k.a. parameter, option, flag, ...) as members on such a Python class.
- Derive program variants from existing programs.
- Assemble parameters in list format for handover to
subprocess.Popenwith proper escaping and quoting. - Launch a program with
subprocess.Popenand hide the complexity of Popen. - Get a generator object for line-by-line output reading to enable postprocessing of outputs.
Use Cases
- Wrap command line interfaces of EDA tools (Electronic Design Automation) in Python classes.
Example
The following example implements a portion of the git program and its commit sub-command.
Git program defining commit argument:
from pyTooling.CLIAbstraction import CLIArgument, Executable
from pyTooling.CLIAbstraction.Command import CommandArgument
from pyTooling.CLIAbstraction.Flag import LongFlag
from pyTooling.CLIAbstraction.ValuedTupleFlag import ShortTupleFlag
class Git(Executable):
_executableNames = {
"Windows": "git.exe",
"Linux": "git",
"Darwin": "git"
}
@CLIArgument()
class FlagVerbose(LongFlag, name="verbose"):
"""Print verbose messages."""
@CLIArgument()
class CommandCommit(CommandArgument, name="commit"):
"""Command to commit staged files."""
@CLIArgument()
class ValueCommitMessage(ShortTupleFlag, name="m"):
"""Specify the commit message."""
def GetCommitTool(self):
"""Derive a new program from a configured program."""
tool = self.__class__(executablePath=self._executablePath)
tool[tool.CommandCommit] = True
self._CopyParameters(tool)
return tool
Usage:
# Create a program instance and set common parameters.
git = Git()
git[git.FlagVerbose] = True
# Derive a variant of that pre-configured program.
commit = git.getCommitTool()
commit[commit.ValueCommitMessage] = "Bumped dependencies."
# Launch the program and parse outputs line-by-line.
commit.StartProcess()
for line in commit.GetLineReader():
print(line)
Consumers
This layer is used by:
Contributors
- Patrick Lehmann (Maintainer)
- Unai Martinez-Corral
- and more...
License
This Python package (source code) licensed under Apache License 2.0.
The accompanying documentation is licensed under Creative Commons - Attribution 4.0 (CC-BY 4.0).
SPDX-License-Identifier: Apache-2.0
Metadata
Release files for pyTooling.CLIAbstraction 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyTooling.CLIAbstraction-0.4.1.tar.gz | 20.8 kB | Without provenance | Details for pyTooling.CLIAbstraction-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyTooling.CLIAbstraction-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for pyTooling.CLIAbstraction-0.4.1-py3-none-any.whl |
Total release size: 51.6 kB
Release files / pyTooling.CLIAbstraction-0.4.1.tar.gz
| Download URL | pyTooling.CLIAbstraction-0.4.1.tar.gz |
|---|---|
| Size | 20.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
62c675d743564638785df6fcdab9a54be6321b789f34dcc6ca18103d3cc303a6
|
|
BLAKE2b-256 checksum How to use checksums |
727fb2e9aa19d94e9c1678960979e02a5f554f5c0d3e41aa62c9913643fc9c79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / pyTooling.CLIAbstraction-0.4.1-py3-none-any.whl
| Download URL | pyTooling.CLIAbstraction-0.4.1-py3-none-any.whl |
|---|---|
| Size | 30.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
290ca69f8d977711162b0c38fbb947c6c24eeba89da1a6a1f26d39a727ce0592
|
|
BLAKE2b-256 checksum How to use checksums |
7e2887b6f2017253f8af583db98139317714bb76fcfc7a5b7374c03096730762
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for pyTooling.CLIAbstraction 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.