pyTooling.CLIAbstraction


NamepyTooling.CLIAbstraction JSON
Version 0.4.1 PyPI version JSON
download
home_pagehttps://GitHub.com/pyTooling/pyTooling.CLIAbstraction
SummaryBasic abstraction layer for executables.
upload_time2023-07-07 22:21:08
maintainer
docs_urlNone
authorPatrick Lehmann
requires_python>=3.7
licenseApache-2.0
keywords abstract executable cli cli arguments
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Sourcecode on GitHub](https://img.shields.io/badge/pyTooling-pyTooling.CLIAbstraction-323131.svg?logo=github&longCache=true)](https://github.com/pyTooling/pyTooling.CLIAbstraction)
[![Sourcecode License](https://img.shields.io/pypi/l/pyTooling.CLIAbstraction?logo=GitHub&label=code%20license)](LICENSE.md)
[![GitHub tag (latest SemVer incl. pre-release)](https://img.shields.io/github/v/tag/pyTooling/pyTooling.CLIAbstraction?logo=GitHub&include_prereleases)](https://github.com/pyTooling/pyTooling.CLIAbstraction/tags)
[![GitHub release (latest SemVer incl. including pre-releases)](https://img.shields.io/github/v/release/pyTooling/pyTooling.CLIAbstraction?logo=GitHub&include_prereleases)](https://github.com/pyTooling/pyTooling.CLIAbstraction/releases/latest)
[![GitHub release date](https://img.shields.io/github/release-date/pyTooling/pyTooling.CLIAbstraction?logo=GitHub)](https://github.com/pyTooling/pyTooling.CLIAbstraction/releases)
[![Dependents (via libraries.io)](https://img.shields.io/librariesio/dependents/pypi/pyTooling.CLIAbstraction?logo=librariesdotio)](https://github.com/pyTooling/pyTooling.CLIAbstraction/network/dependents)  
[![GitHub Workflow - Build and Test Status](https://img.shields.io/github/workflow/status/pyTooling/pyTooling.CLIAbstraction/Unit%20Testing,%20Coverage%20Collection,%20Package,%20Release,%20Documentation%20and%20Publish?label=Pipeline&logo=GitHub%20Actions&logoColor=FFFFFF)](https://github.com/pyTooling/pyTooling.CLIAbstraction/actions/workflows/Pipeline.yml)
[![Codacy - Quality](https://img.shields.io/codacy/grade/3806b49bc754407d900232503a8f7d31?logo=Codacy)](https://www.codacy.com/gh/pyTooling/pyTooling.CLIAbstraction)
[![Codacy - Coverage](https://img.shields.io/codacy/coverage/3806b49bc754407d900232503a8f7d31?logo=Codacy)](https://www.codacy.com/gh/pyTooling/pyTooling.CLIAbstraction)
[![Codecov - Branch Coverage](https://img.shields.io/codecov/c/github/pyTooling/pyTooling.CLIAbstraction?logo=Codecov)](https://codecov.io/gh/pyTooling/pyTooling.CLIAbstraction)
[![Libraries.io SourceRank](https://img.shields.io/librariesio/sourcerank/pypi/pyTooling.CLIAbstraction?logo=librariesdotio)](https://libraries.io/github/pyTooling/pyTooling.CLIAbstraction/sourcerank)  
[![PyPI](https://img.shields.io/pypi/v/pyTooling.CLIAbstraction?logo=PyPI&logoColor=FBE072)](https://pypi.org/project/pyTooling.CLIAbstraction/)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyTooling.CLIAbstraction?logo=PyPI&logoColor=FBE072)
![PyPI - Status](https://img.shields.io/pypi/status/pyTooling.CLIAbstraction?logo=PyPI&logoColor=FBE072)
[![Libraries.io status for latest release](https://img.shields.io/librariesio/release/pypi/pyTooling.CLIAbstraction?logo=librariesdotio)](https://libraries.io/github/pyTooling/pyTooling.CLIAbstraction)
[![Requires.io](https://img.shields.io/requires/github/pyTooling/pyTooling.CLIAbstraction)](https://requires.io/github/pyTooling/pyTooling.CLIAbstraction/requirements/?branch=main)  
[![Read the Docs](https://img.shields.io/readthedocs/pyTooling.CLIAbstraction?label=ReadTheDocs&logo=readthedocs)](https://pyTooling.CLIAbstraction.readthedocs.io/)
[![Documentation License](https://img.shields.io/badge/doc%20license-CC--BY%204.0-green?logo=readthedocs)](LICENSE.md)
[![Documentation - Read Now!](https://img.shields.io/badge/doc-read%20now%20%E2%9E%94-blueviolet?logo=readthedocs)](https://pyTooling.CLIAbstraction.readthedocs.io/)

# 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.Popen` with proper escaping and quoting.
* Launch a program with `subprocess.Popen` and 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:**

```Python
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:**
```Python
# 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:

* ✅ [pyEDAA.CLITool](https://github.com/edaa-org/pyEDAA.CLITool)


## Contributors
* [Patrick Lehmann](https://github.com/Paebbels) (Maintainer)
* [Unai Martinez-Corral](https://github.com/umarcor)
* [and more...](https://github.com/pyTooling/pyTooling.CLIAbstraction/graphs/contributors)


## License

This Python package (source code) licensed under [Apache License 2.0](LICENSE.md).  
The accompanying documentation is licensed under [Creative Commons - Attribution 4.0 (CC-BY 4.0)](doc/Doc-License.rst).

-------------------------
SPDX-License-Identifier: Apache-2.0

            

Raw data

            {
    "_id": null,
    "home_page": "https://GitHub.com/pyTooling/pyTooling.CLIAbstraction",
    "name": "pyTooling.CLIAbstraction",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "abstract,executable,cli,cli arguments",
    "author": "Patrick Lehmann",
    "author_email": "Paebbels@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/72/7f/b2e9aa19d94e9c1678960979e02a5f554f5c0d3e41aa62c9913643fc9c79/pyTooling.CLIAbstraction-0.4.1.tar.gz",
    "platform": null,
    "description": "[![Sourcecode on GitHub](https://img.shields.io/badge/pyTooling-pyTooling.CLIAbstraction-323131.svg?logo=github&longCache=true)](https://github.com/pyTooling/pyTooling.CLIAbstraction)\n[![Sourcecode License](https://img.shields.io/pypi/l/pyTooling.CLIAbstraction?logo=GitHub&label=code%20license)](LICENSE.md)\n[![GitHub tag (latest SemVer incl. pre-release)](https://img.shields.io/github/v/tag/pyTooling/pyTooling.CLIAbstraction?logo=GitHub&include_prereleases)](https://github.com/pyTooling/pyTooling.CLIAbstraction/tags)\n[![GitHub release (latest SemVer incl. including pre-releases)](https://img.shields.io/github/v/release/pyTooling/pyTooling.CLIAbstraction?logo=GitHub&include_prereleases)](https://github.com/pyTooling/pyTooling.CLIAbstraction/releases/latest)\n[![GitHub release date](https://img.shields.io/github/release-date/pyTooling/pyTooling.CLIAbstraction?logo=GitHub)](https://github.com/pyTooling/pyTooling.CLIAbstraction/releases)\n[![Dependents (via libraries.io)](https://img.shields.io/librariesio/dependents/pypi/pyTooling.CLIAbstraction?logo=librariesdotio)](https://github.com/pyTooling/pyTooling.CLIAbstraction/network/dependents)  \n[![GitHub Workflow - Build and Test Status](https://img.shields.io/github/workflow/status/pyTooling/pyTooling.CLIAbstraction/Unit%20Testing,%20Coverage%20Collection,%20Package,%20Release,%20Documentation%20and%20Publish?label=Pipeline&logo=GitHub%20Actions&logoColor=FFFFFF)](https://github.com/pyTooling/pyTooling.CLIAbstraction/actions/workflows/Pipeline.yml)\n[![Codacy - Quality](https://img.shields.io/codacy/grade/3806b49bc754407d900232503a8f7d31?logo=Codacy)](https://www.codacy.com/gh/pyTooling/pyTooling.CLIAbstraction)\n[![Codacy - Coverage](https://img.shields.io/codacy/coverage/3806b49bc754407d900232503a8f7d31?logo=Codacy)](https://www.codacy.com/gh/pyTooling/pyTooling.CLIAbstraction)\n[![Codecov - Branch Coverage](https://img.shields.io/codecov/c/github/pyTooling/pyTooling.CLIAbstraction?logo=Codecov)](https://codecov.io/gh/pyTooling/pyTooling.CLIAbstraction)\n[![Libraries.io SourceRank](https://img.shields.io/librariesio/sourcerank/pypi/pyTooling.CLIAbstraction?logo=librariesdotio)](https://libraries.io/github/pyTooling/pyTooling.CLIAbstraction/sourcerank)  \n[![PyPI](https://img.shields.io/pypi/v/pyTooling.CLIAbstraction?logo=PyPI&logoColor=FBE072)](https://pypi.org/project/pyTooling.CLIAbstraction/)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyTooling.CLIAbstraction?logo=PyPI&logoColor=FBE072)\n![PyPI - Status](https://img.shields.io/pypi/status/pyTooling.CLIAbstraction?logo=PyPI&logoColor=FBE072)\n[![Libraries.io status for latest release](https://img.shields.io/librariesio/release/pypi/pyTooling.CLIAbstraction?logo=librariesdotio)](https://libraries.io/github/pyTooling/pyTooling.CLIAbstraction)\n[![Requires.io](https://img.shields.io/requires/github/pyTooling/pyTooling.CLIAbstraction)](https://requires.io/github/pyTooling/pyTooling.CLIAbstraction/requirements/?branch=main)  \n[![Read the Docs](https://img.shields.io/readthedocs/pyTooling.CLIAbstraction?label=ReadTheDocs&logo=readthedocs)](https://pyTooling.CLIAbstraction.readthedocs.io/)\n[![Documentation License](https://img.shields.io/badge/doc%20license-CC--BY%204.0-green?logo=readthedocs)](LICENSE.md)\n[![Documentation - Read Now!](https://img.shields.io/badge/doc-read%20now%20%E2%9E%94-blueviolet?logo=readthedocs)](https://pyTooling.CLIAbstraction.readthedocs.io/)\n\n# pyTooling.CLIAbstraction\n\npyTooling.CLIAbstraction is an abstraction layer and wrapper for command line programs, so they can be used easily in\nPython. All parameters like ``--value=42`` are described as parameters of the executable.\n\n\n## Main Goals\n\n* Offer access to CLI programs as Python classes.\n* Abstract CLI arguments (a.k.a. parameter, option, flag, ...) as members on such a Python class.\n* Derive program variants from existing programs.\n* Assemble parameters in list format for handover to `subprocess.Popen` with proper escaping and quoting.\n* Launch a program with `subprocess.Popen` and hide the complexity of Popen.\n* Get a generator object for line-by-line output reading to enable postprocessing of outputs.\n\n## Use Cases\n\n* Wrap command line interfaces of EDA tools (Electronic Design Automation) in Python classes.\n\n\n## Example\n\nThe following example implements a portion of the ``git`` program and its ``commit`` sub-command.\n\n**Git program defining `commit` argument:**\n\n```Python\nfrom pyTooling.CLIAbstraction import CLIArgument, Executable\nfrom pyTooling.CLIAbstraction.Command import CommandArgument\nfrom pyTooling.CLIAbstraction.Flag import LongFlag\nfrom pyTooling.CLIAbstraction.ValuedTupleFlag import ShortTupleFlag\n\nclass Git(Executable):\n\t_executableNames = {\n\t\t\"Windows\": \"git.exe\",\n\t\t\"Linux\": \"git\",\n\t\t\"Darwin\": \"git\"\n\t}\n\t\n\t@CLIArgument()\n\tclass FlagVerbose(LongFlag, name=\"verbose\"):\n\t\t\"\"\"Print verbose messages.\"\"\"\n\t\n\t@CLIArgument()\n\tclass CommandCommit(CommandArgument, name=\"commit\"):\n\t\t\"\"\"Command to commit staged files.\"\"\"\n\t\n\t@CLIArgument()\n\tclass ValueCommitMessage(ShortTupleFlag, name=\"m\"):\n\t\t\"\"\"Specify the commit message.\"\"\"\n\t\n\tdef GetCommitTool(self):\n\t\t\"\"\"Derive a new program from a configured program.\"\"\"\n\t\ttool = self.__class__(executablePath=self._executablePath)\n\t\ttool[tool.CommandCommit] = True\n\t\tself._CopyParameters(tool)\n\t\t\n\t\treturn tool\n```\n\n**Usage:**\n```Python\n# Create a program instance and set common parameters.\ngit = Git()\ngit[git.FlagVerbose] = True\n\n# Derive a variant of that pre-configured program.\ncommit = git.getCommitTool()\ncommit[commit.ValueCommitMessage] = \"Bumped dependencies.\"\n\n# Launch the program and parse outputs line-by-line.\ncommit.StartProcess()\nfor line in commit.GetLineReader():\n\tprint(line)\n```\n\n\n# Consumers\n\nThis layer is used by:\n\n* \u2705 [pyEDAA.CLITool](https://github.com/edaa-org/pyEDAA.CLITool)\n\n\n## Contributors\n* [Patrick Lehmann](https://github.com/Paebbels) (Maintainer)\n* [Unai Martinez-Corral](https://github.com/umarcor)\n* [and more...](https://github.com/pyTooling/pyTooling.CLIAbstraction/graphs/contributors)\n\n\n## License\n\nThis Python package (source code) licensed under [Apache License 2.0](LICENSE.md).  \nThe accompanying documentation is licensed under [Creative Commons - Attribution 4.0 (CC-BY 4.0)](doc/Doc-License.rst).\n\n-------------------------\nSPDX-License-Identifier: Apache-2.0\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Basic abstraction layer for executables.",
    "version": "0.4.1",
    "project_urls": {
        "Documentation": "https://pyTooling.GitHub.io/pyTooling.CLIAbstraction",
        "Homepage": "https://GitHub.com/pyTooling/pyTooling.CLIAbstraction",
        "Issue Tracker": "https://GitHub.com/pyTooling/pyTooling.CLIAbstraction/issues",
        "Source Code": "https://GitHub.com/pyTooling/pyTooling.CLIAbstraction"
    },
    "split_keywords": [
        "abstract",
        "executable",
        "cli",
        "cli arguments"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7e2887b6f2017253f8af583db98139317714bb76fcfc7a5b7374c03096730762",
                "md5": "21b8933954e92aa8ffe577f3bc5fb3f3",
                "sha256": "290ca69f8d977711162b0c38fbb947c6c24eeba89da1a6a1f26d39a727ce0592"
            },
            "downloads": -1,
            "filename": "pyTooling.CLIAbstraction-0.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "21b8933954e92aa8ffe577f3bc5fb3f3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 30872,
            "upload_time": "2023-07-07T22:21:09",
            "upload_time_iso_8601": "2023-07-07T22:21:09.753689Z",
            "url": "https://files.pythonhosted.org/packages/7e/28/87b6f2017253f8af583db98139317714bb76fcfc7a5b7374c03096730762/pyTooling.CLIAbstraction-0.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "727fb2e9aa19d94e9c1678960979e02a5f554f5c0d3e41aa62c9913643fc9c79",
                "md5": "3965230390136ee497f345b71ce08220",
                "sha256": "62c675d743564638785df6fcdab9a54be6321b789f34dcc6ca18103d3cc303a6"
            },
            "downloads": -1,
            "filename": "pyTooling.CLIAbstraction-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "3965230390136ee497f345b71ce08220",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 20771,
            "upload_time": "2023-07-07T22:21:08",
            "upload_time_iso_8601": "2023-07-07T22:21:08.182656Z",
            "url": "https://files.pythonhosted.org/packages/72/7f/b2e9aa19d94e9c1678960979e02a5f554f5c0d3e41aa62c9913643fc9c79/pyTooling.CLIAbstraction-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-07 22:21:08",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pytooling.cliabstraction"
}
        
Elapsed time: 0.13004s