From b43583c9542baab24e66326cadf589e7a4cee357 Mon Sep 17 00:00:00 2001 From: Andrew Mirsky Date: Mon, 26 May 2025 11:27:42 -0400 Subject: [PATCH 1/2] reapplying any remaining stack traces to logging messages that weren't already included in other updates --- amqtt/mqtt/protocol/handler.py | 10 +++++----- amqtt/plugins/manager.py | 4 ++-- amqtt/scripts/sub_script.py | 4 ++-- docs/references/mqttclient.rst | 4 ++-- samples/client_publish.py | 4 ++-- samples/client_publish_acl.py | 2 +- samples/client_subscribe.py | 4 ++-- samples/client_subscribe_acl.py | 2 +- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/amqtt/mqtt/protocol/handler.py b/amqtt/mqtt/protocol/handler.py index d7877f4..7da6574 100644 --- a/amqtt/mqtt/protocol/handler.py +++ b/amqtt/mqtt/protocol/handler.py @@ -138,11 +138,11 @@ class ProtocolHandler: if self.writer is not None: await self.writer.close() except asyncio.CancelledError: - self.logger.debug("Writer close was cancelled.") - except TimeoutError as e: - self.logger.debug(f"Writer close operation timed out: {e}.") - except OSError as e: - self.logger.debug(f"Writer close failed due to I/O error: {e}") + self.logger.debug("Writer close was cancelled.", exc_info=True) + except TimeoutError: + self.logger.debug("Writer close operation timed out.", exc_info=True) + except OSError: + self.logger.debug("Writer close failed due to I/O error.", exc_info=True) def _stop_waiters(self) -> None: self.logger.debug(f"Stopping {len(self._puback_waiters)} puback waiters") diff --git a/amqtt/plugins/manager.py b/amqtt/plugins/manager.py index e3c4496..0167df3 100644 --- a/amqtt/plugins/manager.py +++ b/amqtt/plugins/manager.py @@ -86,8 +86,8 @@ class PluginManager: plugin_context.logger = self.logger.getChild(ep.name) obj = plugin(plugin_context) return Plugin(ep.name, ep, obj) - except ImportError as ie: - self.logger.warning(f"Plugin {ep!r} import failed: {ie}") + except ImportError: + self.logger.warning(f"Plugin {ep!r} import failed", exc_info=True) return None diff --git a/amqtt/scripts/sub_script.py b/amqtt/scripts/sub_script.py index adf0807..536eb96 100644 --- a/amqtt/scripts/sub_script.py +++ b/amqtt/scripts/sub_script.py @@ -106,8 +106,8 @@ async def do_sub(client: MQTTClient, arguments: dict[str, Any]) -> None: except KeyboardInterrupt: await client.disconnect() logger.info(f"{client.client_id} Disconnected from broker") - except ConnectError as ce: - logger.fatal(f"Connection to '{arguments['--url']}' failed: {ce!r}") + except ConnectError: + logger.fatal(f"Connection to '{arguments['--url']}' failed.", exc_info=True) except asyncio.CancelledError: logger.fatal("Publish canceled due to previous error") diff --git a/docs/references/mqttclient.rst b/docs/references/mqttclient.rst index d6ae90b..df26542 100644 --- a/docs/references/mqttclient.rst +++ b/docs/references/mqttclient.rst @@ -38,8 +38,8 @@ The example below shows how to write a simple MQTT client which subscribes a top print("%d: %s => %s" % (i, packet.variable_header.topic_name, str(packet.payload.data))) await C.unsubscribe(['$SYS/broker/uptime', '$SYS/broker/load/#']) await C.disconnect() - except ClientException as ce: - logger.error("Client exception: %s" % ce) + except ClientException: + logger.error("Client exception", exc_info=True) if __name__ == '__main__': formatter = "[%(asctime)s] %(name)s {%(filename)s:%(lineno)d} %(levelname)s - %(message)s" diff --git a/samples/client_publish.py b/samples/client_publish.py index 57bcf58..9b0f4f6 100644 --- a/samples/client_publish.py +++ b/samples/client_publish.py @@ -43,8 +43,8 @@ async def test_coro2() -> None: await C.publish("a/b", b"TEST MESSAGE WITH QOS_2", qos=0x02) logger.info("messages published") await C.disconnect() - except ConnectError as ce: - logger.exception(f"Connection failed: {ce}") + except ConnectError: + logger.exception(f"Connection failed", exc_info=True) asyncio.get_event_loop().stop() diff --git a/samples/client_publish_acl.py b/samples/client_publish_acl.py index 0a1cbb6..2ecf33e 100644 --- a/samples/client_publish_acl.py +++ b/samples/client_publish_acl.py @@ -27,7 +27,7 @@ async def test_coro() -> None: logger.info("messages published") await C.disconnect() except ConnectError as ce: - logger.exception(f"Connection failed: {ce}") + logger.exception("Connection failed") asyncio.get_event_loop().stop() diff --git a/samples/client_subscribe.py b/samples/client_subscribe.py index 0a29efb..3d175d6 100644 --- a/samples/client_subscribe.py +++ b/samples/client_subscribe.py @@ -30,8 +30,8 @@ async def uptime_coro() -> None: await C.unsubscribe(["$SYS/broker/uptime", "$SYS/broker/load/#"]) logger.info("UnSubscribed") await C.disconnect() - except ClientError as ce: - logger.exception(f"Client exception: {ce}") + except ClientError: + logger.exception("Client exception") if __name__ == "__main__": diff --git a/samples/client_subscribe_acl.py b/samples/client_subscribe_acl.py index aa69435..1810b6b 100644 --- a/samples/client_subscribe_acl.py +++ b/samples/client_subscribe_acl.py @@ -35,7 +35,7 @@ async def uptime_coro() -> None: logger.info("UnSubscribed") await C.disconnect() except ClientError as ce: - logger.exception(f"Client exception: {ce}") + logger.exception("Client exception") if __name__ == "__main__": From a0b5d29aea8feda6d51928fad13b545ad409d48e Mon Sep 17 00:00:00 2001 From: Andrew Mirsky Date: Thu, 29 May 2025 13:31:38 -0400 Subject: [PATCH 2/2] simplifying the gitignore file so that it is easier to identify what is / isn't included --- .gitignore | 244 ++++++----------------------------------------------- 1 file changed, 27 insertions(+), 217 deletions(-) diff --git a/.gitignore b/.gitignore index dfe909c..dd30c86 100644 --- a/.gitignore +++ b/.gitignore @@ -1,225 +1,35 @@ -# Ignore .hidden files -.* -# Ignore everything -* +#------- Package & Cache Files ------- +*.egg-info +__pycache__ +node_modules +.vite -!.github/ -!.github/** - -!.codecov.yml -!.coveragerc - -!.gitattributes -!.gitignore -!.gitempty - -!CHANGELOG.md -!CONTRIBUTING.md -!LICENSE -!SECURITY.md - -!README.md -!README.rst -!MANIFEST.in - -!.pre-commit-config.yaml -!.gitleaks.toml -!.prettierrc.yml -!.yamllint - -# PROJECT - -!pyproject.toml -!uv.lock - -!amqtt/ -!amqtt/** - -!docs/ -!docs/** -!samples/ -!samples/** -!scripts/ -scripts/* -!scripts/*.sh - -!tests/ -!tests/** -tests/**/test.db - -# Created by https://www.toptal.com/developers/gitignore/api/python -# Edit at https://www.toptal.com/developers/gitignore?templates=python - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/#use-with-ide -.pdm.toml - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env +#------- Environment Files ------- +.python-version .venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ -# Spyder project settings -.spyderproject -.spyproject +#------- Git Files ------- +BASE +LOCAL +*.orig +REMOTE -# Rope project settings -.ropeproject +#------- OS Files ------- +.DS_Store -# mkdocs documentation -/site +#------ Database Files ------- +*.sqlite3 +*.db -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json +#------ IDE ------ +.idea +.vscode/ -# Pyre type checker -.pyre/ -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ - -### Python Patch ### -# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration -poetry.toml - -# ruff -.ruff_cache/ - -# LSP config files -pyrightconfig.json - -# End of https://www.toptal.com/developers/gitignore/api/python +#----- Built Directory & Files------ +.coverage +dist/ +site/ +_build/ +.hypothesis/ +coverage.xml