Async Cmd2
==========
Async extension to a famous
`Cmd2 <https://github.com/python-cmd2/cmd2>`__ library.
Cmd2 permanently occupies the main thread which is a problem if you plan
to receive callbacks on the main thread (e.g., by Bluetooth stack Bleak)
Pip installation
----------------
BoolTest is available via ``pip``:
::
pip3 install ph4-acmd2
Local installation
------------------
From the local dir:
::
pip3 install --upgrade --find-links=. .
Usage
-----
.. code:: python
import asyncio
import ph4acmd2
class CmdLineApp(ph4acmd2.Cmd):
async def main(self):
await self.acmdloop()
print("Cmdloop finished now")
if __name__ == '__main__':
app = CmdLineApp()
loop = asyncio.get_event_loop()
loop.set_debug(True)
loop.run_until_complete(app.main())
Limitations
-----------
We use
`asyncio.lool.add_reader <https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.add_reader>`__
to read from the stdin and process the commands thus it is not currently
possible to ue readline features such as auto-complete or ctrl-r,
UP-arrow for previous commands, etc…
Readline occupies main thread in a blocking way, so it is not compatible
with runloop model running on the main thread and executing coroutines.
In order to use readline it needs to add async support. A potential
workaround could be to access terminal in async way e.g., submit short
coroutine monitoring the terminal state to simulate readline library.
However, it is not tested.
Development
-----------
Install pre-commit hooks defined by ``.pre-commit-config.yaml``
.. code:: shell
pip3 install -U pre-commit pytest mypy
mypy --install-types
pre-commit install
Auto fix
.. code:: shell
pre-commit run --all-files
Plugin version update
.. code:: shell
pre-commit autoupdate
Raw data
{
"_id": null,
"home_page": "https://github.com/ph4r05/ph4-acmd2",
"name": "ph4-acmd2",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Dusan Klinec",
"author_email": "dusan.klinec@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/52/10/dbfc94609aec99794914808c3b3e46fbb76fb31eaef21dd2e2d3e6555b6d/ph4_acmd2-1.0.0.tar.gz",
"platform": null,
"description": "Async Cmd2\n==========\n\nAsync extension to a famous\n`Cmd2 <https://github.com/python-cmd2/cmd2>`__ library.\n\nCmd2 permanently occupies the main thread which is a problem if you plan\nto receive callbacks on the main thread (e.g., by Bluetooth stack Bleak)\n\nPip installation\n----------------\n\nBoolTest is available via ``pip``:\n\n::\n\n pip3 install ph4-acmd2\n\nLocal installation\n------------------\n\nFrom the local dir:\n\n::\n\n pip3 install --upgrade --find-links=. .\n\nUsage\n-----\n\n.. code:: python\n\n import asyncio\n import ph4acmd2\n\n class CmdLineApp(ph4acmd2.Cmd):\n async def main(self):\n await self.acmdloop()\n print(\"Cmdloop finished now\")\n\n if __name__ == '__main__':\n app = CmdLineApp()\n loop = asyncio.get_event_loop()\n loop.set_debug(True)\n loop.run_until_complete(app.main())\n\nLimitations\n-----------\n\nWe use\n`asyncio.lool.add_reader <https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.add_reader>`__\nto read from the stdin and process the commands thus it is not currently\npossible to ue readline features such as auto-complete or ctrl-r,\nUP-arrow for previous commands, etc\u2026\n\nReadline occupies main thread in a blocking way, so it is not compatible\nwith runloop model running on the main thread and executing coroutines.\n\nIn order to use readline it needs to add async support. A potential\nworkaround could be to access terminal in async way e.g., submit short\ncoroutine monitoring the terminal state to simulate readline library.\nHowever, it is not tested.\n\nDevelopment\n-----------\n\nInstall pre-commit hooks defined by ``.pre-commit-config.yaml``\n\n.. code:: shell\n\n pip3 install -U pre-commit pytest mypy\n mypy --install-types\n pre-commit install\n\nAuto fix\n\n.. code:: shell\n\n pre-commit run --all-files\n\nPlugin version update\n\n.. code:: shell\n\n pre-commit autoupdate\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Cmd2 extension for async programs",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/ph4r05/ph4-acmd2"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5210dbfc94609aec99794914808c3b3e46fbb76fb31eaef21dd2e2d3e6555b6d",
"md5": "cae000d591f94bb94ef6a0b10f5fd979",
"sha256": "313b8d63e0887dbce678e6b3271f890ca3c5c8f7bd3b0341bc07ace42b1bcca5"
},
"downloads": -1,
"filename": "ph4_acmd2-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "cae000d591f94bb94ef6a0b10f5fd979",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5999,
"upload_time": "2024-09-22T14:49:56",
"upload_time_iso_8601": "2024-09-22T14:49:56.666674Z",
"url": "https://files.pythonhosted.org/packages/52/10/dbfc94609aec99794914808c3b3e46fbb76fb31eaef21dd2e2d3e6555b6d/ph4_acmd2-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-22 14:49:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ph4r05",
"github_project": "ph4-acmd2",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "ph4-acmd2"
}