aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2022-05-30 20:01:47 -0700
committerGravatar MarkKoz <[email protected]>2022-05-30 20:01:47 -0700
commit812374109a2adef13dd1a810cc69643c33de884f (patch)
treed1932b281961efea883281071633a6e0f36cd73f
parentMove logging code to separate utility modules (diff)
Make Sentry SDK and gunicorn optional dependencies
Falcon provides a WSGI app which can be used by any server, not just gunicorn. Thus, make gunicorn optional in case the user wants to use a different server. There shouldn't be any import errors since the class is now in an isolated module. The only time that module is imported is when gunicorn loads its config. Sentry is there for Python Discord mainly, so this dependency shouldn't be imposed on others.
-rw-r--r--Makefile3
-rw-r--r--pyproject.toml6
-rw-r--r--requirements/requirements.pip2
-rw-r--r--snekbox/utils/logging.py11
4 files changed, 14 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index add4293..a30579a 100644
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,8 @@ setup: install-piptools
.PHONY: upgrade
upgrade: install-piptools
- $(PIP_COMPILE_CMD) -o requirements/requirements.pip pyproject.toml
+ $(PIP_COMPILE_CMD) -o requirements/requirements.pip \
+ --extra gunicorn --extra sentry pyproject.toml
$(PIP_COMPILE_CMD) -o requirements/coverage.pip requirements/coverage.in
$(PIP_COMPILE_CMD) -o requirements/coveralls.pip requirements/coveralls.in
$(PIP_COMPILE_CMD) -o requirements/lint.pip requirements/lint.in
diff --git a/pyproject.toml b/pyproject.toml
index 09b69ac..abcf04f 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -27,12 +27,14 @@ requires-python = ">=3.10"
dependencies = [
# Sentry's Falcon integration relies on api_helpers (falconry/falcon#1902).
"falcon>=3.0.1",
- "gunicorn>=20",
"jsonschema>=4.0",
"protobuf>=3.19",
- "sentry-sdk[falcon]>=1.5.4"
]
+[project.optional-dependencies]
+gunicorn = ["gunicorn>=20"]
+sentry = ["sentry-sdk[falcon]>=1.5.4"]
+
[project.urls]
source = "https://github.com/python-discord/snekbox"
tracker = "https://github.com/python-discord/snekbox/issues"
diff --git a/requirements/requirements.pip b/requirements/requirements.pip
index d9587c1..034f104 100644
--- a/requirements/requirements.pip
+++ b/requirements/requirements.pip
@@ -2,7 +2,7 @@
# This file is autogenerated by pip-compile with python 3.10
# To update, run:
#
-# pip-compile --output-file=requirements/requirements.pip pyproject.toml
+# pip-compile --extra=gunicorn --extra=sentry --output-file=requirements/requirements.pip pyproject.toml
#
attrs==21.4.0
# via jsonschema
diff --git a/snekbox/utils/logging.py b/snekbox/utils/logging.py
index e5afd0c..9a713f8 100644
--- a/snekbox/utils/logging.py
+++ b/snekbox/utils/logging.py
@@ -2,9 +2,6 @@ import logging
import os
import sys
-import sentry_sdk
-from sentry_sdk.integrations.falcon import FalconIntegration
-
__all__ = ("FORMAT", "init_logger", "init_sentry")
FORMAT = "%(asctime)s | %(process)5s | %(name)30s | %(levelname)8s | %(message)s"
@@ -23,7 +20,13 @@ def init_logger(debug: bool) -> None:
def init_sentry() -> None:
- """Initialise the Sentry SDK."""
+ """Initialise the Sentry SDK if it's installed."""
+ try:
+ import sentry_sdk
+ from sentry_sdk.integrations.falcon import FalconIntegration
+ except ImportError:
+ return
+
git_sha = os.environ.get("GIT_SHA", "development")
sentry_sdk.init(
dsn=os.environ.get("SNEKBOX_SENTRY_DSN", ""),