Skip to content

Commit

Permalink
Merge pull request #24 from TimNekk/develop
Browse files Browse the repository at this point in the history
Add Ruff Linting
  • Loading branch information
TimNekk authored Nov 28, 2023
2 parents 1222e00 + 0819277 commit 534308e
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 64 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions lint.sh
Original file line number Diff line number Diff line change
@@ -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 .
98 changes: 51 additions & 47 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions tgbot/middlewares/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
5 changes: 5 additions & 0 deletions tgbot/states/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
from .send_all import SendAllState
from .ping import PingState

__all__ = [
"SendAllState",
"PingState"
]

0 comments on commit 534308e

Please sign in to comment.