diff --git a/requirements-dev.txt b/.archive/requirements-dev.txt similarity index 100% rename from requirements-dev.txt rename to .archive/requirements-dev.txt diff --git a/requirements.txt b/.archive/requirements.txt similarity index 100% rename from requirements.txt rename to .archive/requirements.txt diff --git a/.env.default b/.env.default index 88eb9e9..19dc321 100644 --- a/.env.default +++ b/.env.default @@ -1,4 +1,2 @@ APP_LIFECYCLE="dev" -SENTRY_ENABLED="False" -SENTRY_DSN="" WEBEX_API_KEY="" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 841ed49..49c1599 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,7 @@ on: jobs: ci: - uses: luketainton/gha-workflows/.github/workflows/ci-python-with-docker.yml@main + uses: luketainton/gha-workflows/.github/workflows/ci-python-poetry-with-docker.yml@main secrets: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6012ad1..3e510bd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -5,6 +5,12 @@ on: - cron: "0 9 * * 0" jobs: + test: + uses: luketainton/gha-workflows/.github/workflows/ci-python-poetry-with-docker.yml@main + secrets: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + create_release: name: Create Release uses: luketainton/gha-workflows/.github/workflows/create-release.yml@main diff --git a/.gitignore b/.gitignore index 7f4045e..cee07d3 100644 --- a/.gitignore +++ b/.gitignore @@ -133,3 +133,6 @@ dmypy.json # IDE .vscode .idea + +# Ruff +.ruff_cache/ diff --git a/Dockerfile b/Dockerfile index eeb1828..8f7e896 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,10 +8,13 @@ WORKDIR /run RUN mkdir -p /.local && \ chmod -R 777 /.local && \ - pip install -U pip + pip install -U pip poetry -COPY requirements.txt /run/requirements.txt -RUN pip install --no-cache-dir -r requirements.txt +COPY pyproject.toml /run/pyproject.toml +COPY poetry.lock /run/poetry.lock + +RUN poetry config virtualenvs.create false && \ + poetry install --without dev ENTRYPOINT ["python3", "-B", "-m", "app.main"] diff --git a/app/config.py b/app/config.py index f2a75e3..8b42d9a 100644 --- a/app/config.py +++ b/app/config.py @@ -11,11 +11,6 @@ class Config: self.__environment: str = os.environ.get("APP_LIFECYCLE", "DEV").upper() self.__version: str = os.environ["APP_VERSION"] self.__webex_token: str = os.environ["WEBEX_API_KEY"] - self.__sentry_dsn: str = os.environ.get("SENTRY_DSN", "") - self.__sentry_enabled: bool = bool( - os.environ.get("SENTRY_ENABLED", "False").upper() == "TRUE" - and self.__sentry_dsn != "" - ) @property def environment(self) -> str: @@ -27,19 +22,6 @@ class Config: """Returns the current app version.""" return self.__version - @property - def sentry_enabled(self) -> bool: - """Returns True if Sentry SDK is enabled, else False.""" - return self.__sentry_enabled - - @property - def sentry_dsn(self) -> str: - """Returns the Sentry DSN value if Sentry SDK is enabled AND - Sentry DSN is set, else blank string.""" - if not self.__sentry_enabled: - return "" - return self.__sentry_dsn - @property def webex_token(self) -> str: """Returns the Webex API key.""" diff --git a/app/img.py b/app/img.py index b59d8c5..6a5e19f 100644 --- a/app/img.py +++ b/app/img.py @@ -18,7 +18,7 @@ CHAR_REPLACEMENTS: list = [ def get_templates() -> list[dict]: url: str = "https://api.memegen.link/templates" - req: requests.Response = requests.get(url=url, timeout=5) + req: requests.Response = requests.get(url=url, timeout=10) req.raise_for_status() data: dict = req.json() templates: list = [] diff --git a/app/main.py b/app/main.py index 4e28ad4..d8bd01f 100644 --- a/app/main.py +++ b/app/main.py @@ -1,22 +1,10 @@ #!/usr/local/bin/python3 -import sentry_sdk -from sentry_sdk.integrations.stdlib import StdlibIntegration from webex_bot.webex_bot import WebexBot from app import close, meme from app.config import config -if config.sentry_enabled: - apm = sentry_sdk.init( - dsn=config.sentry_dsn, - enable_tracing=True, - environment=config.environment, - release=config.version, - integrations=[StdlibIntegration()], - spotlight=True, - ) - def create_bot() -> WebexBot: """Create a Bot object.""" diff --git a/poetry.lock b/poetry.lock index 610bd1c..2ec67dd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. [[package]] name = "astroid" @@ -390,20 +390,17 @@ files = [ [[package]] name = "isort" -version = "5.12.0" +version = "5.13.2" description = "A Python utility / library to sort Python imports." optional = false python-versions = ">=3.8.0" files = [ - {file = "isort-5.12.0-py3-none-any.whl", hash = "sha256:f84c2818376e66cf843d497486ea8fed8700b340f308f076c6fb1229dff318b6"}, - {file = "isort-5.12.0.tar.gz", hash = "sha256:8bef7dde241278824a6d83f44a544709b065191b95b6e50894bdc722fcba0504"}, + {file = "isort-5.13.2-py3-none-any.whl", hash = "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6"}, + {file = "isort-5.13.2.tar.gz", hash = "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109"}, ] [package.extras] -colors = ["colorama (>=0.4.3)"] -pipfile-deprecated-finder = ["pip-shims (>=0.5.2)", "pipreqs", "requirementslib"] -plugins = ["setuptools"] -requirements-deprecated-finder = ["pip-api", "pipreqs"] +colors = ["colorama (>=0.4.6)"] [[package]] name = "mccabe" @@ -784,60 +781,6 @@ files = [ [package.dependencies] requests = ">=2.0.1,<3.0.0" -[[package]] -name = "sentry-sdk" -version = "2.19.0" -description = "Python client for Sentry (https://sentry.io)" -optional = false -python-versions = ">=3.6" -files = [ - {file = "sentry_sdk-2.19.0-py2.py3-none-any.whl", hash = "sha256:7b0b3b709dee051337244a09a30dbf6e95afe0d34a1f8b430d45e0982a7c125b"}, - {file = "sentry_sdk-2.19.0.tar.gz", hash = "sha256:ee4a4d2ae8bfe3cac012dcf3e4607975904c137e1738116549fc3dbbb6ff0e36"}, -] - -[package.dependencies] -certifi = "*" -urllib3 = ">=1.26.11" - -[package.extras] -aiohttp = ["aiohttp (>=3.5)"] -anthropic = ["anthropic (>=0.16)"] -arq = ["arq (>=0.23)"] -asyncpg = ["asyncpg (>=0.23)"] -beam = ["apache-beam (>=2.12)"] -bottle = ["bottle (>=0.12.13)"] -celery = ["celery (>=3)"] -celery-redbeat = ["celery-redbeat (>=2)"] -chalice = ["chalice (>=1.16.0)"] -clickhouse-driver = ["clickhouse-driver (>=0.2.0)"] -django = ["django (>=1.8)"] -falcon = ["falcon (>=1.4)"] -fastapi = ["fastapi (>=0.79.0)"] -flask = ["blinker (>=1.1)", "flask (>=0.11)", "markupsafe"] -grpcio = ["grpcio (>=1.21.1)", "protobuf (>=3.8.0)"] -http2 = ["httpcore[http2] (==1.*)"] -httpx = ["httpx (>=0.16.0)"] -huey = ["huey (>=2)"] -huggingface-hub = ["huggingface_hub (>=0.22)"] -langchain = ["langchain (>=0.0.210)"] -launchdarkly = ["launchdarkly-server-sdk (>=9.8.0)"] -litestar = ["litestar (>=2.0.0)"] -loguru = ["loguru (>=0.5)"] -openai = ["openai (>=1.0.0)", "tiktoken (>=0.3.0)"] -openfeature = ["openfeature-sdk (>=0.7.1)"] -opentelemetry = ["opentelemetry-distro (>=0.35b0)"] -opentelemetry-experimental = ["opentelemetry-distro"] -pure-eval = ["asttokens", "executing", "pure_eval"] -pymongo = ["pymongo (>=3.1)"] -pyspark = ["pyspark (>=2.4.4)"] -quart = ["blinker (>=1.1)", "quart (>=0.16.1)"] -rq = ["rq (>=0.6)"] -sanic = ["sanic (>=0.8)"] -sqlalchemy = ["sqlalchemy (>=1.2)"] -starlette = ["starlette (>=0.19.1)"] -starlite = ["starlite (>=1.48)"] -tornado = ["tornado (>=6)"] - [[package]] name = "setuptools" version = "68.0.0" @@ -1021,4 +964,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.11.2" -content-hash = "f7823bb3d889bedb7b2edccc56ba8169403af44b0e5d17925cee1e42445ccb5c" +content-hash = "3bf64765123ffdd88b19d2ddaa5cd4a40370e4e635cd22164065e4cc583aae20" diff --git a/pyproject.toml b/pyproject.toml index 94fafd7..5a1c7e0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,19 +1,20 @@ [tool.poetry] name = "webexmemebot" -version = "0.1.0" +version = "0.0.0" # Version is tracked by GitHub Releases description = "Webex-based meme generation bot using memegen.link." authors = ["luketainton"] readme = "README.md" +package-mode = false [tool.poetry.dependencies] python = "^3.11.2" webex-bot = "^0.5.2" pillow = "^11.0.0" -sentry-sdk = "^2.19.0" [tool.poetry.group.dev.dependencies] black = "^24.10.0" coverage = "^7.6.8" +isort = "^5.13.2" pylint = "^3.2.6" pylint-exit = "^1.2.0" pytest = "^8.3.3" diff --git a/tests/test_config.py b/tests/test_config.py index c90373e..2cf5fc4 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -5,8 +5,6 @@ import os vars: dict = { "APP_VERSION": "dev", "WEBEX_API_KEY": "testing", - "SENTRY_ENABLED": "false", - "SENTRY_DSN": "http://localhost", } @@ -20,4 +18,3 @@ from app.config import config # pragma: no cover # noqa: E402 def test_config() -> None: assert config.webex_token == vars["WEBEX_API_KEY"] assert config.version == vars["APP_VERSION"] - assert config.sentry_enabled == bool(vars["SENTRY_ENABLED"].lower() == "true")