diff --git a/.flake8 b/.flake8 index 899da947823d6c2d0f7f7d31e15534ee9fc77302..ee3730ff0086b87efaa9a40fbfbf14245e9f19c5 100644 --- a/.flake8 +++ b/.flake8 @@ -9,3 +9,4 @@ per-file-ignores = scripts/docker-send-email.py: E501 # Too complex notifications_consumer/publisher.py: C901 +enable-extensions=G diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1442c62d39971d1f095a8ac0e5a977a462baa1e6..92b112a2b51c4fb44816db7287d3195027211d38 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,14 +16,13 @@ repos: hooks: - id: isort - repo: https://github.com/psf/black - rev: stable + rev: 20.8b1 hooks: - id: black - args: [ --line-length=120 ] - language_version: python3 - repo: https://gitlab.com/pycqa/flake8 rev: 3.8.4 hooks: - id: flake8 args: [--config=.flake8] language_version: python3 + additional_dependencies: [ flake8-docstrings, flake8-logging-format ] diff --git a/notifications_consumer/app.py b/notifications_consumer/app.py index 729a0c7e0f821f273109840aac9a4e312fc0ad91..21a19865d829cccb8e447811a13acc775b6cb86f 100644 --- a/notifications_consumer/app.py +++ b/notifications_consumer/app.py @@ -24,7 +24,9 @@ class App: listener = NotificationsConsumer(config=self.config, processor=processor) cons = Consumer( - name=processor.consumer_name, auto_connect=False, listener=listener, + name=processor.consumer_name, + auto_connect=False, + listener=listener, ) listener.set_connections(cons._connections) cons.connect() diff --git a/notifications_consumer/consumer.py b/notifications_consumer/consumer.py index d1dfb87f647e0f9e22cbdec3b2382d2c3aa329a9..8421fa4e96f351acc8ff6353cfd420ca9bdbafa9 100644 --- a/notifications_consumer/consumer.py +++ b/notifications_consumer/consumer.py @@ -22,30 +22,27 @@ class NotificationsConsumer(megabus.Listener): def ack_message(self, message_id): """Acknowledge a message.""" - logging.debug(f"Ack message message_id:{message_id}") + logging.debug("Ack message message_id:%s", message_id) for connection in self.connections: if connection.is_connected(): connection.ack(message_id, 1) def nack_message(self, message_id): """Send a message back to the queue.""" - logging.debug(f"Nack message: message_id:{message_id}") + logging.debug("Nack message: message_id:%s", message_id) for connection in self.connections: if connection.is_connected(): connection.nack(message_id, 1) def on_message(self, message, headers): """Process a message.""" - logging.info(f"Received message {headers['message-id']}") - logging.debug(f"Message Data: message:{message}, headers:{headers}") + logging.info("Received message - %s", headers["message-id"]) + logging.debug("Message Data: message:%s, headers:%s", message, headers) try: self.processor.process(**self.processor.read_message(json.loads(message)), **self.kwargs) self.ack_message(headers["message-id"]) except Exception as e: - logging.critical( - f"An exception happened while processing the message: {e}", - exc_info=True, - ) + logging.critical("An exception happened while processing the message", exception=e, exc_info=True) self.nack_message(headers["message-id"]) diff --git a/notifications_consumer/processors/email/processor.py b/notifications_consumer/processors/email/processor.py index b133329476b9cbccdd4147ee6e3dd6e09c386cc8..76bbb4c98b841652dbca852a28879678461765fb 100644 --- a/notifications_consumer/processors/email/processor.py +++ b/notifications_consumer/processors/email/processor.py @@ -29,7 +29,7 @@ class EmailProcessor(Processor): recipient_email = kwargs["email"] if Config.ENV == ENV_DEV and recipient_email not in Config.EMAIL_WHITELIST: - logging.info(f"Email recipient <{recipient_email}> isn't on the EMAIL_WHITELIST. Email sent is skipped.") + logging.info("Email recipient <%s> isn't on the EMAIL_WHITELIST. Email sent is skipped.", recipient_email) return subject = f'[{kwargs["channel_name"]}] - {kwargs["summary"]}' diff --git a/notifications_consumer/processors/email_gateway_failure/processor.py b/notifications_consumer/processors/email_gateway_failure/processor.py index c92de977e09cf5c7cb777606ac23b55f4d1e1881..4f6f1777a2b902e9bd352857bce89d8a34339a1d 100644 --- a/notifications_consumer/processors/email_gateway_failure/processor.py +++ b/notifications_consumer/processors/email_gateway_failure/processor.py @@ -74,7 +74,7 @@ class EmailGatewayFailureProcessor(Processor): channel_mail = self.data_source.get_channel_incoming_email(channel) return self.__send_notification_email(channel_mail, message_object, error, channel) except Exception as ex: - logging.info("Error while parsing %s email: %r", recipient_email, ex) + logging.exception("Error while parsing %s email", recipient_email, exception=ex) sender = message_object.get("sender") if sender: diff --git a/poetry.lock b/poetry.lock index 241dda1c4aa4d9cc194a9fa151c3cc4936af9e03..6d4a15b773556b1bc013a65b231b902f17b28370 100644 --- a/poetry.lock +++ b/poetry.lock @@ -110,6 +110,14 @@ python-versions = "*" flake8 = ">=3" pydocstyle = ">=2.1" +[[package]] +name = "flake8-logging-format" +version = "0.6.0" +description = "Flake8 extension to validate (lack of) logging format strings" +category = "dev" +optional = false +python-versions = "*" + [[package]] name = "http-ece" version = "1.1.0" @@ -211,7 +219,7 @@ python-versions = "*" [[package]] name = "pre-commit" -version = "2.7.1" +version = "2.9.3" description = "A framework for managing and maintaining multi-language pre-commit hooks." category = "dev" optional = false @@ -460,7 +468,7 @@ testing = ["pytest (>=3.5,!=3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake [metadata] lock-version = "1.1" python-versions = "^3.6.1" -content-hash = "85beefeace3d22393deb451282ec31b77d611e1db97150d70112805db277d778" +content-hash = "94fe24762e24fde15d457e3e095e8d6621e4f2c70ff4d79db93c98e40184ae2c" [metadata.files] appdirs = [ @@ -505,6 +513,7 @@ cffi = [ {file = "cffi-1.14.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:840793c68105fe031f34d6a086eaea153a0cd5c491cde82a74b420edd0a2b909"}, {file = "cffi-1.14.4-cp39-cp39-manylinux1_i686.whl", hash = "sha256:b18e0a9ef57d2b41f5c68beefa32317d286c3d6ac0484efd10d6e07491bb95dd"}, {file = "cffi-1.14.4-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:045d792900a75e8b1e1b0ab6787dd733a8190ffcf80e8c8ceb2fb10a29ff238a"}, + {file = "cffi-1.14.4-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:7ef7d4ced6b325e92eb4d3502946c78c5367bc416398d387b39591532536734e"}, {file = "cffi-1.14.4-cp39-cp39-win32.whl", hash = "sha256:ba4e9e0ae13fc41c6b23299545e5ef73055213e466bd107953e4a013a5ddd7e3"}, {file = "cffi-1.14.4-cp39-cp39-win_amd64.whl", hash = "sha256:f032b34669220030f905152045dfa27741ce1a6db3324a5bc0b96b6c7420c87b"}, {file = "cffi-1.14.4.tar.gz", hash = "sha256:1a465cbe98a7fd391d47dce4b8f7e5b921e6cd805ef421d04f5f66ba8f06086c"}, @@ -552,6 +561,9 @@ flake8-docstrings = [ {file = "flake8-docstrings-1.5.0.tar.gz", hash = "sha256:3d5a31c7ec6b7367ea6506a87ec293b94a0a46c0bce2bb4975b7f1d09b6f3717"}, {file = "flake8_docstrings-1.5.0-py2.py3-none-any.whl", hash = "sha256:a256ba91bc52307bef1de59e2a009c3cf61c3d0952dbe035d6ff7208940c2edc"}, ] +flake8-logging-format = [ + {file = "flake8-logging-format-0.6.0.tar.gz", hash = "sha256:ca5f2b7fc31c3474a0aa77d227e022890f641a025f0ba664418797d979a779f8"}, +] http-ece = [ {file = "http_ece-1.1.0.tar.gz", hash = "sha256:932ebc2fa7c216954c320a188ae9c1f04d01e67bec9cdce1bfbc912813b0b4f8"}, ] @@ -638,8 +650,8 @@ nodeenv = [ {file = "nodeenv-1.5.0.tar.gz", hash = "sha256:ab45090ae383b716c4ef89e690c41ff8c2b257b85b309f01f3654df3d084bd7c"}, ] pre-commit = [ - {file = "pre_commit-2.7.1-py2.py3-none-any.whl", hash = "sha256:810aef2a2ba4f31eed1941fc270e72696a1ad5590b9751839c90807d0fff6b9a"}, - {file = "pre_commit-2.7.1.tar.gz", hash = "sha256:c54fd3e574565fe128ecc5e7d2f91279772ddb03f8729645fa812fe809084a70"}, + {file = "pre_commit-2.9.3-py2.py3-none-any.whl", hash = "sha256:6c86d977d00ddc8a60d68eec19f51ef212d9462937acf3ea37c7adec32284ac0"}, + {file = "pre_commit-2.9.3.tar.gz", hash = "sha256:ee784c11953e6d8badb97d19bc46b997a3a9eded849881ec587accd8608d74a4"}, ] psycopg2-binary = [ {file = "psycopg2-binary-2.8.6.tar.gz", hash = "sha256:11b9c0ebce097180129e422379b824ae21c8f2a6596b159c7659e2e5a00e1aa0"}, diff --git a/pyproject.toml b/pyproject.toml index ff45eb86d8048d268bdd5f91b7dabb1690ed7cfb..e4f996f61970d061c35ed15a9efc3b8ed98a779b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,10 +17,28 @@ psycopg2-binary = "^2.8.6" pywebpush = "^1.11.0" [tool.poetry.dev-dependencies] -pre-commit = "~2.7.1" +pre-commit = "~2.9.2" flake8 = "~3.8.3" flake8-docstrings = "~1.5.0" +flake8-logging-format = "^0.6.0" [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" + +[tool.black] +line-length = 120 +include = '\.pyi?$' +exclude = ''' +/( + \.git + | \.hg + | \.mypy_cache + | \.tox + | \.venv + | _build + | buck-out + | build + | dist +)/ +'''