Skip to content

Commit

Permalink
fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
nlef committed Feb 2, 2025
1 parent 631a66d commit 2ac801c
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 11 deletions.
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Please open PR only in `development` branch

# Setup environment
## Active virtualenv
This is the default location.
Expand All @@ -14,6 +16,30 @@ pre-commit install
```

You can also run pre-commit manually on all files:
Before commiting changes you should also run pre-commit and tests manually on all files:
```shell
pre-commit run --all-files --show-diff-on-failure --color=always
pytest -v
```

Run bot localy:

create dev config file `telegram_dev.conf ` for example in bot folder
```shell
cd ~/moonraker-telegram-bot
~/moonraker-telegram-bot-env/bin/python3 ~/moonraker-telegram-bot/bot/main.py -c ~/moonraker-telegram-bot/telegram_dev.conf
```

Test changes using docker and arm64 arc( docker buildx or docker desktop required). New container with the bot will be created and started.
```shell
pre-commit run --all-files
docker compose -f .\docker-compose-dev.yml up --build -d
```
you mast create bot config file under `./docker_data/config` or copy created earlier telegram_dev.conf to container config folder and rename in to `telegram.conf`
dev container contains preinstalled `memray` and `memory-profiler` for easy memory problem retrieval

Test building docker images (buildx required):
```shell
docker buildx build --platform linux/arm64 -t test -f Dockerfile-mjpeg .
docker buildx build --platform linux/arm64 -t test -f Dockerfile .
```
Empty file added bot/assets/__init__.py
Empty file.
11 changes: 5 additions & 6 deletions bot/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pickle
import threading
import time
from typing import List, Tuple
from typing import List, Optional, Tuple

from PIL import Image, _webp # type: ignore
from assets.ffmpegcv_custom import FFmpegReaderStreamRTCustomInit # type: ignore
Expand All @@ -30,7 +30,7 @@
try:
import cv2 # type: ignore
except ImportError:
cv2 = None
cv2 = None # type: ignore


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -317,13 +317,12 @@ def _take_raw_frame(self, rgb: bool = True) -> ndarray:
image = numpy.rot90(image, k=self._rotate_code, axes=(1, 0))

ndaarr = image[:, :, [2, 1, 0]].copy() if rgb else image.copy()
image = None
success = None
image = None # type: ignore
del image, success

return ndaarr

def take_photo(self, ndarr: ndarray = None) -> BytesIO:
def take_photo(self, ndarr: Optional[ndarray] = None) -> BytesIO:
img = Image.fromarray(ndarr) if ndarr is not None else Image.fromarray(self._take_raw_frame())

os_nice(15)
Expand Down Expand Up @@ -670,7 +669,7 @@ def _rotate_img(self, img: Image.Image) -> Image.Image:
return img

@cam_light_toggle
def take_photo(self, ndarr: ndarray = None, force_rotate: bool = True) -> BytesIO:
def take_photo(self, ndarr: Optional[ndarray] = None, force_rotate: bool = True) -> BytesIO:
bio = BytesIO()
os_nice(15)
try:
Expand Down
2 changes: 1 addition & 1 deletion bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
from telegram.constants import ChatAction, ParseMode
from telegram.error import BadRequest
from telegram.ext import Application, CallbackContext, CallbackQueryHandler, CommandHandler, ContextTypes, MessageHandler, filters
from telegram_helper import TelegramMessageRepr

from camera import Camera, FFmpegCamera, MjpegCamera
from configuration import ConfigWrapper
from klippy import Klippy, PowerDevice
from notifications import Notifier
from telegram_helper import TelegramMessageRepr
from timelapse import Timelapse
from websocket_helper import WebSocketHelper

Expand Down
2 changes: 1 addition & 1 deletion bot/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
from telegram.constants import ChatAction
from telegram.error import BadRequest
from telegram.helpers import escape_markdown
from telegram_helper import TelegramMessageRepr

from camera import Camera
from configuration import ConfigWrapper
from klippy import Klippy
from telegram_helper import TelegramMessageRepr

logger = logging.getLogger(__name__)

Expand Down
3 changes: 2 additions & 1 deletion bot/timelapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from concurrent.futures import ThreadPoolExecutor
import gc
import logging
from typing import Optional

from apscheduler.schedulers.base import BaseScheduler # type: ignore
from telegram import Bot, Message
Expand Down Expand Up @@ -238,7 +239,7 @@ def _reschedule_timelapse_timer(self) -> None:
replace_existing=True,
)

async def upload_timelapse(self, lapse_filename: str, info_mess, gcode_name_out: str = None) -> None:
async def upload_timelapse(self, lapse_filename: str, info_mess, gcode_name_out: Optional[str] = None) -> None:
try:
(
video_bytes,
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tool.pylint.master]
max-line-length = 200
max-positional-arguments=10 # maybe refactor code?
ignore-imports = true
disable = [
"broad-except",
Expand Down Expand Up @@ -31,6 +32,9 @@ good-names = [
]
ignore-paths= ['^bot/assets/.*$', 'tests']

[tool.mypy]
no_namespace_packages = true
exclude = "tests"

[tool.black]
line-length = 200
Expand All @@ -46,5 +50,6 @@ known_first_party = [
"klippy",
"notifications",
"timelapse",
"websocket_helper"
"websocket_helper",
"telegram_helper"
]
2 changes: 1 addition & 1 deletion scripts/requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-r requirements.txt
black==24.10.0
black==25.1.0
identify==2.6.6
isort==5.13.2
memory_profiler==0.61.0
Expand Down

0 comments on commit 2ac801c

Please sign in to comment.