diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 13581a8..f562173 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -16,13 +16,7 @@ jobs: uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install mypy flake8 Flake8-pyproject - - name: Analysing the code with mypy - run: | - mypy tgbot --install-types --non-interactive - - name: Analysing the code with flake8 - run: | - flake8 + - name: Give execute permission to lint.sh + run: chmod +x ./lint.sh + - name: Lint code + run: ./lint.sh diff --git a/lint.sh b/lint.sh new file mode 100755 index 0000000..278d358 --- /dev/null +++ b/lint.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Exit script on first error +set -e + +# Check if pylint is installed +if ! pip list | grep ruff; then + # Upgrade pip and install pylint if not installed + python -m pip install --upgrade pip + pip install ruff +fi + +# Run pylint on all Python files in the repository +#find . -name "*.py" -print0 | xargs -0 pylint +ruff check . \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 8d8f649..5f96287 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,53 +1,57 @@ -[tool.flake8] -max-line-length = 120 +[tool.ruff] +# Exclude a variety of commonly ignored directories. exclude = [ + ".bzr", + ".direnv", + ".eggs", ".git", - "__pycache__", - "docs/source/conf.py", + ".git-rewrite", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", "build", "dist", - "tests", - "alembic" -] -ignore = [ - "I101", - "D100", - "D101", - "D102", - "D103", - "D104", - "D105", - "D107", - "D401", - "E203", - "I900", - "N802", - "N806", - "N812", - "W503", - "S311", - "S605", - "S607", - "ISC003", - "ISC001", - "T101", - "T000", - "F541", - "PL123", - "E712" -] -per-file-ignores = [ - '__init__.py:F401', + "node_modules", + "venv", ] -[tool.mypy] -ignore_missing_imports = true -disallow_untyped_defs = true -check_untyped_defs = true -warn_redundant_casts = true -no_implicit_optional = true -strict_optional = true -show_error_codes = true -strict_equality = true -warn_unreachable = true -warn_unused_configs = true +# Same as Black. +line-length = 88 +indent-width = 4 + +# Assume Python 3.10 +target-version = "py310" + +[tool.ruff.lint] +# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. +select = ["E4", "E7", "E9", "F"] +ignore = ["E712"] + +# Allow fix for all enabled rules (when `--fix`) is provided. +fixable = ["ALL"] +unfixable = [] + +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +[tool.ruff.format] +# Like Black, use double quotes for strings. +quote-style = "double" + +# Like Black, indent with spaces, rather than tabs. +indent-style = "space" + +# Like Black, respect magic trailing commas. +skip-magic-trailing-comma = false + +# Like Black, automatically detect the appropriate line ending. +line-ending = "auto" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 3bf3474..90bce37 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,9 @@ -aiogram==2.25.1 +aiogram==2.23.1 aioredis~=2.0 -environs~=9.5 +environs~=9.0 git+https://github.com/TimNekk/aiogram_broadcaster.git gino==1.0.1 -loguru==0.7.0 -alembic==1.11.1 -psycopg2==2.9.6 +loguru==0.6.0 +alembic==1.8.1 +psycopg2==2.9.3 validators==0.20.0 diff --git a/tgbot/middlewares/subscription.py b/tgbot/middlewares/subscription.py index 1fdbfa7..73ba456 100644 --- a/tgbot/middlewares/subscription.py +++ b/tgbot/middlewares/subscription.py @@ -24,14 +24,14 @@ async def setup_channels(cls, dp: Dispatcher, channels_ids: list[int]) -> None: async def on_process_message(self, message: Message, data: dict) -> None: user = data.get('user') if not user: - raise KeyError(f"User not found in data") + raise KeyError("User not found in data") await self.check_subscriptions(message, user=user) async def on_process_callback_query(self, call: CallbackQuery, data: dict) -> None: user = data.get('user') if not user: - raise KeyError(f"User not found in data") + raise KeyError("User not found in data") await self.check_subscriptions(call.message, user=user, call=call, callback_data=data.get("callback_data")) diff --git a/tgbot/states/__init__.py b/tgbot/states/__init__.py index 6192fb0..eeb5b95 100644 --- a/tgbot/states/__init__.py +++ b/tgbot/states/__init__.py @@ -1,2 +1,7 @@ from .send_all import SendAllState from .ping import PingState + +__all__ = [ + "SendAllState", + "PingState" +]