From c04b72e72bbbe4df573c1692852508add7d91884 Mon Sep 17 00:00:00 2001 From: eduzen Date: Sat, 1 Jun 2024 21:55:24 +0200 Subject: [PATCH] Update Python warnings configuration in .env.sample --- .env.sample | 2 +- .flake8 | 11 -- .pre-commit-config.yaml | 8 +- Dockerfile | 2 +- docker-compose.yml | 3 - eduzenbot/__main__.py | 4 +- eduzenbot/auth/restricted.py | 2 +- eduzenbot/decorators.py | 2 +- .../plugins/commands/hackernews/command.py | 7 +- eduzenbot/telegram_bot.py | 3 +- justfile | 21 ++- requirements-dev.txt | 132 ++++++++++++------ requirements.txt | 63 ++++++--- 13 files changed, 170 insertions(+), 90 deletions(-) delete mode 100644 .flake8 diff --git a/.env.sample b/.env.sample index 830a2888..579cbf86 100644 --- a/.env.sample +++ b/.env.sample @@ -7,7 +7,7 @@ LOG_LEVEL=DEBUG openweathermap_token=token PORT=5000 POSTGRES_PASSWORD=password -PYTHONWARNINGS=ignore:Unverified HTTPS request +PYTHONWARNINGS="ignore:Unverified HTTPS request" TMDB_API_KEY=somekey TOKEN=token TWITTER_ACCESS_TOKEN_SECRET=secret diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 6bd3da9d..00000000 --- a/.flake8 +++ /dev/null @@ -1,11 +0,0 @@ -[flake8] -exclude = docs,versioneer.py,.eggs/,.venv/,venv.,bin/,vscode/,.github/ -ignore=E203,E402 -count = True -show_source = True -statistics = True -max_line_length = 120 -filename = *.py -extend-ignore = - # See https://github.com/PyCQA/pycodestyle/issues/373 - E203 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index daf61486..863aa7cd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -28,10 +28,16 @@ repos: args: [--py311-plus] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.4.2' + rev: 'v0.4.7' hooks: # Run the linter - id: ruff args: ["--fix"] # Run the formatter - id: ruff-format + + - repo: https://github.com/pycqa/isort + rev: 5.13.2 # Use the ref you want to point at + hooks: + - id: isort + args: ["--profile", "black"] diff --git a/Dockerfile b/Dockerfile index 460b1a2c..6c3acd4b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ RUN apt-get update && \ apt-get autoclean -y && \ rm -rf /var/lib/apt/lists/* -RUN pip install -U wheel pip +RUN pip install -U wheel pip pip-tools COPY pyproject.toml requirements.txt ./ diff --git a/docker-compose.yml b/docker-compose.yml index 86a26334..2315eb27 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,8 @@ -version: '3.9' - volumes: pgdata: shell_history: services: - eduzenbot: tty: true image: eduzen/bot:latest diff --git a/eduzenbot/__main__.py b/eduzenbot/__main__.py index 077a1102..7eeeb6bf 100644 --- a/eduzenbot/__main__.py +++ b/eduzenbot/__main__.py @@ -2,8 +2,10 @@ import logging import os +from pathlib import Path import sentry_sdk +from dotenv import load_dotenv from rich.logging import RichHandler from telegram.ext import CallbackQueryHandler, CommandHandler, Filters @@ -13,8 +15,6 @@ from eduzenbot.plugins.messages.unknown import unknown from eduzenbot.scripts.initialize_db import create_db_tables from eduzenbot.telegram_bot import TelegramBot -from dotenv import load_dotenv -from pathlib import Path # Load environment variables from .env file env_path = Path("../.env") diff --git a/eduzenbot/auth/restricted.py b/eduzenbot/auth/restricted.py index ab4934e8..a507a091 100644 --- a/eduzenbot/auth/restricted.py +++ b/eduzenbot/auth/restricted.py @@ -1,7 +1,7 @@ import logging import os -from functools import wraps from collections.abc import Callable +from functools import wraps from telegram import Update from telegram.ext import CallbackContext diff --git a/eduzenbot/decorators.py b/eduzenbot/decorators.py index cffb56e3..0766cd23 100644 --- a/eduzenbot/decorators.py +++ b/eduzenbot/decorators.py @@ -1,8 +1,8 @@ import functools import logging +from collections.abc import Callable from functools import wraps from typing import Any -from collections.abc import Callable import peewee from telegram import Update diff --git a/eduzenbot/plugins/commands/hackernews/command.py b/eduzenbot/plugins/commands/hackernews/command.py index ac9a2724..9fdef227 100644 --- a/eduzenbot/plugins/commands/hackernews/command.py +++ b/eduzenbot/plugins/commands/hackernews/command.py @@ -7,7 +7,6 @@ from types import SimpleNamespace from typing import Any -import pendulum import requests from cachetools import TTLCache, cached from telegram import ChatAction, Update @@ -73,14 +72,14 @@ def get_hackernews_help(story_type: STORIES = STORIES.TOP) -> str: def parse_hackernews(story_id: int) -> str: raw_story = get_item(story_id) story = SimpleNamespace(**raw_story) - now = pendulum.now() - date = now - pendulum.from_timestamp(story.time) + # now = pendulum.now() + # date = now - pendulum.from_timestamp(story.time) try: url = story.url except AttributeError: url = "" story_text = ( - f"[{story.title}]({url})\n Score: {story.score} Hace: {date.in_words()}" + f"[{story.title}]({url})\n" # Score: {story.score} Hace: {date.in_words()}" ) return story_text diff --git a/eduzenbot/telegram_bot.py b/eduzenbot/telegram_bot.py index d900f84e..e25d6667 100644 --- a/eduzenbot/telegram_bot.py +++ b/eduzenbot/telegram_bot.py @@ -2,10 +2,9 @@ import logging import os import pkgutil -from collections.abc import Sequence +from collections.abc import Callable, Sequence from functools import partial from typing import Any -from collections.abc import Callable import attr import pytz diff --git a/justfile b/justfile index 91873485..d57b6e61 100644 --- a/justfile +++ b/justfile @@ -1,7 +1,7 @@ set dotenv-load := true -dco := "docker-compose" -run := "{{dco}} run --rm eduzenbot" +dco := "docker compose" +run := "docker compose run --rm eduzenbot" os: #!/usr/bin/env bash @@ -18,6 +18,17 @@ dockershell: #!/usr/bin/env bash {{run}} eduzenbot bash +update-requirements-dev: + {{run}} pip-compile --upgrade --extra=dev pyproject.toml -o requirements-dev.txt + +update-requirements-prod: + {{run}} pip-compile --upgrade pyproject.toml -o requirements.txt + +update-requirements: + just update-requirements-dev + just update-requirements-prod + + test: #!/usr/bin/env bash {{run}} pytest --cov=eduzenbot --cov-report=term-missing @@ -51,6 +62,12 @@ compile: compile-dev: pip-compile --extra=dev pyproject.toml -o requirements-dev.txt +format: + pre-commit run --all-files + +fmt: + just format + clean: #!/usr/bin/env python3 import pathlib, shutil diff --git a/requirements-dev.txt b/requirements-dev.txt index 9126b54c..4f2ebbf4 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,16 +1,23 @@ -# This file was autogenerated by uv via the following command: -# uv pip compile --all-extras pyproject.toml -o requirements-dev.txt -appdirs==1.4.4 - # via yfinance +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# pip-compile --extra=dev --output-file=requirements-dev.txt pyproject.toml +# apscheduler==3.6.3 # via python-telegram-bot asttokens==2.4.1 # via stack-data attrs==23.2.0 + # via eduzenbot (pyproject.toml) beautifulsoup4==4.12.3 - # via yfinance + # via + # eduzenbot (pyproject.toml) + # yfinance cachetools==4.2.2 - # via python-telegram-bot + # via + # eduzenbot (pyproject.toml) + # python-telegram-bot certifi==2024.2.2 # via # python-telegram-bot @@ -18,39 +25,45 @@ certifi==2024.2.2 # sentry-sdk charset-normalizer==3.3.2 # via requests -coverage==7.4.4 +coverage==7.5.3 + # via eduzenbot (pyproject.toml) decorator==5.1.1 # via # ipdb # ipython -emoji==2.11.0 -execnet==2.0.2 +emoji==2.12.1 + # via eduzenbot (pyproject.toml) +execnet==2.1.1 # via pytest-xdist executing==2.0.1 # via stack-data factory-boy==3.3.0 -faker==24.7.1 + # via eduzenbot (pyproject.toml) +faker==25.3.0 # via factory-boy -frozendict==2.4.1 +frozendict==2.4.4 # via yfinance html5lib==1.1 # via yfinance -idna==3.6 +idna==3.7 # via # requests # yarl iniconfig==2.0.0 # via pytest ipdb==0.13.13 -ipython==8.23.0 - # via ipdb + # via eduzenbot (pyproject.toml) +ipython==8.25.0 + # via + # eduzenbot (pyproject.toml) + # ipdb jedi==0.19.1 # via ipython -lxml==5.2.1 +lxml==5.2.2 # via yfinance markdown-it-py==3.0.0 # via rich -matplotlib-inline==0.1.6 +matplotlib-inline==0.1.7 # via ipython mdurl==0.1.2 # via markdown-it-py @@ -58,7 +71,8 @@ multidict==6.0.5 # via yarl multitasking==0.0.11 # via yfinance -mypy==1.9.0 +mypy==1.10.0 + # via eduzenbot (pyproject.toml) mypy-extensions==1.0.0 # via mypy numpy==1.26.4 @@ -71,38 +85,49 @@ oauthlib==3.2.2 # tweepy packaging==24.0 # via pytest -pandas==2.2.1 +pandas==2.2.2 # via yfinance parso==0.8.4 # via jedi -peewee==3.17.1 - # via yfinance +peewee==3.17.5 + # via + # eduzenbot (pyproject.toml) + # yfinance pendulum==3.0.0 + # via eduzenbot (pyproject.toml) pexpect==4.9.0 # via ipython -pluggy==1.4.0 +platformdirs==4.2.2 + # via yfinance +pluggy==1.5.0 # via pytest -prompt-toolkit==3.0.43 +prompt-toolkit==3.0.45 # via ipython psycopg2-binary==2.9.9 + # via eduzenbot (pyproject.toml) ptyprocess==0.7.0 # via pexpect pure-eval==0.2.2 # via stack-data -pygments==2.17.2 +pygments==2.18.0 # via # ipython # rich -pytest==8.1.1 +pytest==8.2.1 # via + # eduzenbot (pyproject.toml) # pytest-mock # pytest-randomly # pytest-recording # pytest-xdist pytest-mock==3.14.0 + # via eduzenbot (pyproject.toml) pytest-randomly==3.15.0 + # via eduzenbot (pyproject.toml) pytest-recording==0.13.1 -pytest-xdist==3.5.0 + # via eduzenbot (pyproject.toml) +pytest-xdist==3.6.1 + # via eduzenbot (pyproject.toml) python-dateutil==2.9.0.post0 # via # faker @@ -110,7 +135,9 @@ python-dateutil==2.9.0.post0 # pendulum # time-machine python-dotenv==1.0.1 + # via eduzenbot (pyproject.toml) python-telegram-bot==13.15 + # via eduzenbot (pyproject.toml) pytz==2024.1 # via # apscheduler @@ -119,8 +146,9 @@ pytz==2024.1 # yfinance pyyaml==6.0.1 # via vcrpy -requests==2.31.0 +requests==2.32.3 # via + # eduzenbot (pyproject.toml) # requests-oauthlib # tmdbsimple # tweepy @@ -128,9 +156,9 @@ requests==2.31.0 requests-oauthlib==1.3.1 # via tweepy rich==13.7.1 -sentry-sdk==1.44.1 -setuptools==69.2.0 - # via apscheduler + # via eduzenbot (pyproject.toml) +sentry-sdk==2.3.1 + # via eduzenbot (pyproject.toml) six==1.16.0 # via # apscheduler @@ -144,28 +172,44 @@ stack-data==0.6.3 time-machine==2.14.1 # via pendulum tmdbsimple==2.9.1 + # via eduzenbot (pyproject.toml) tornado==6.1 # via python-telegram-bot -traitlets==5.14.2 +traitlets==5.14.3 # via # ipython # matplotlib-inline tweepy==4.14.0 -types-beautifulsoup4==4.12.0.20240229 + # via eduzenbot (pyproject.toml) +types-beautifulsoup4==4.12.0.20240511 + # via eduzenbot (pyproject.toml) types-cachetools==5.3.0.7 + # via eduzenbot (pyproject.toml) types-colorama==0.4.15.20240311 -types-docutils==0.20.0.20240331 - # via types-pygments + # via eduzenbot (pyproject.toml) +types-docutils==0.21.0.20240423 + # via + # eduzenbot (pyproject.toml) + # types-pygments types-html5lib==1.1.11.20240228 # via types-beautifulsoup4 -types-psycopg2==2.9.21.20240311 -types-pygments==2.17.0.20240310 -types-pytz==2024.1.0.20240203 -types-requests==2.31.0.20240403 -types-setuptools==69.2.0.20240317 - # via types-pygments -typing-extensions==4.11.0 - # via mypy +types-psycopg2==2.9.21.20240417 + # via eduzenbot (pyproject.toml) +types-pygments==2.18.0.20240506 + # via eduzenbot (pyproject.toml) +types-pytz==2024.1.0.20240417 + # via eduzenbot (pyproject.toml) +types-requests==2.32.0.20240523 + # via eduzenbot (pyproject.toml) +types-setuptools==70.0.0.20240524 + # via + # eduzenbot (pyproject.toml) + # types-pygments +typing-extensions==4.12.1 + # via + # emoji + # ipython + # mypy tzdata==2024.1 # via # pandas @@ -187,4 +231,8 @@ wrapt==1.16.0 # via vcrpy yarl==1.9.4 # via vcrpy -yfinance==0.2.37 +yfinance==0.2.40 + # via eduzenbot (pyproject.toml) + +# The following packages are considered to be unsafe in a requirements file: +# setuptools diff --git a/requirements.txt b/requirements.txt index 3e74994b..1604414f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,14 +1,21 @@ -# This file was autogenerated by uv via the following command: -# uv pip compile pyproject.toml -o requirements.txt -appdirs==1.4.4 - # via yfinance +# +# This file is autogenerated by pip-compile with Python 3.11 +# by the following command: +# +# pip-compile --output-file=requirements.txt pyproject.toml +# apscheduler==3.6.3 # via python-telegram-bot attrs==23.2.0 + # via eduzenbot (pyproject.toml) beautifulsoup4==4.12.3 - # via yfinance + # via + # eduzenbot (pyproject.toml) + # yfinance cachetools==4.2.2 - # via python-telegram-bot + # via + # eduzenbot (pyproject.toml) + # python-telegram-bot certifi==2024.2.2 # via # python-telegram-bot @@ -16,14 +23,15 @@ certifi==2024.2.2 # sentry-sdk charset-normalizer==3.3.2 # via requests -emoji==2.11.0 -frozendict==2.4.1 +emoji==2.12.1 + # via eduzenbot (pyproject.toml) +frozendict==2.4.4 # via yfinance html5lib==1.1 # via yfinance -idna==3.6 +idna==3.7 # via requests -lxml==5.2.1 +lxml==5.2.2 # via yfinance markdown-it-py==3.0.0 # via rich @@ -39,13 +47,19 @@ oauthlib==3.2.2 # via # requests-oauthlib # tweepy -pandas==2.2.1 - # via yfinance -peewee==3.17.1 +pandas==2.2.2 # via yfinance +peewee==3.17.5 + # via + # eduzenbot (pyproject.toml) + # yfinance pendulum==3.0.0 + # via eduzenbot (pyproject.toml) +platformdirs==4.2.2 + # via yfinance psycopg2-binary==2.9.9 -pygments==2.17.2 + # via eduzenbot (pyproject.toml) +pygments==2.18.0 # via rich python-dateutil==2.9.0.post0 # via @@ -53,15 +67,18 @@ python-dateutil==2.9.0.post0 # pendulum # time-machine python-dotenv==1.0.1 + # via eduzenbot (pyproject.toml) python-telegram-bot==13.15 + # via eduzenbot (pyproject.toml) pytz==2024.1 # via # apscheduler # pandas # python-telegram-bot # yfinance -requests==2.31.0 +requests==2.32.3 # via + # eduzenbot (pyproject.toml) # requests-oauthlib # tmdbsimple # tweepy @@ -69,9 +86,9 @@ requests==2.31.0 requests-oauthlib==1.3.1 # via tweepy rich==13.7.1 -sentry-sdk==1.44.1 -setuptools==69.2.0 - # via apscheduler + # via eduzenbot (pyproject.toml) +sentry-sdk==2.3.1 + # via eduzenbot (pyproject.toml) six==1.16.0 # via # apscheduler @@ -82,9 +99,13 @@ soupsieve==2.5 time-machine==2.14.1 # via pendulum tmdbsimple==2.9.1 + # via eduzenbot (pyproject.toml) tornado==6.1 # via python-telegram-bot tweepy==4.14.0 + # via eduzenbot (pyproject.toml) +typing-extensions==4.12.1 + # via emoji tzdata==2024.1 # via # pandas @@ -97,4 +118,8 @@ urllib3==2.2.1 # sentry-sdk webencodings==0.5.1 # via html5lib -yfinance==0.2.37 +yfinance==0.2.40 + # via eduzenbot (pyproject.toml) + +# The following packages are considered to be unsafe in a requirements file: +# setuptools