Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* @analysiscenter/codeowners

8 changes: 4 additions & 4 deletions .github/workflows/test-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.9, '3.10', 3.11, 3.12]
python-version: [3.9, '3.10', 3.11, 3.12, 3.13]

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.9, '3.10', 3.11, 3.12]
python-version: [3.9, '3.10', 3.11, 3.12, 3.13]

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -87,7 +87,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.9, '3.10', 3.11, 3.12]
python-version: [3.9, '3.10', 3.11, 3.12, 3.13]

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -151,7 +151,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.9, '3.10', 3.11, 3.12]
python-version: [3.9, '3.10', 3.11, 3.12, 3.13]

runs-on: ${{ matrix.os }}

Expand Down
3 changes: 1 addition & 2 deletions batchflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from .sampler import Sampler, ConstantSampler, NumpySampler, HistoSampler, ScipySampler
from .utils import save_data_to, read_data_from
from .utils_random import make_rng, make_seed_sequence, spawn_seed_sequence
from .utils_telegram import TelegramMessage
from .utils_transforms import Normalizer, Quantizer


Expand All @@ -34,7 +33,7 @@
pylint_notebook = make_delayed_import(module='.utils_notebook', package=__name__, attribute='pylint_notebook')
get_available_gpus = make_delayed_import(module='.utils_notebook', package=__name__, attribute='get_available_gpus')
set_gpus = make_delayed_import(module='.utils_notebook', package=__name__, attribute='set_gpus')

TelegramMessage = make_delayed_import(module='.utils_telegram', package=__name__, attribute='TelegramMessage')

try:
__version__ = version('batchflow')
Expand Down
3 changes: 2 additions & 1 deletion batchflow/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

from .named_expr import NamedExpression, eval_expr
from .monitor import ResourceMonitor, MONITOR_ALIASES
from .utils_telegram import TelegramMessage



Expand Down Expand Up @@ -255,6 +254,8 @@ def __init__(self, bar='a', disable=False, frequency=1, monitors=None, graphs=No
# Prepare Telegram notifications
self.telegram = telegram
if self.telegram or initialize_telegram:
from .utils_telegram import TelegramMessage

self.telegram_text = TelegramMessage(token=token, chat_id=chat_id, silent=silent)
self.telegram_media = TelegramMessage(token=token, chat_id=chat_id, silent=silent)

Expand Down
6 changes: 4 additions & 2 deletions batchflow/utils_telegram.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
""" A class to send updateable content messages to Telegram. """
import os
import json
import imghdr
from uuid import uuid4
from io import BytesIO
from concurrent.futures import ThreadPoolExecutor
Expand Down Expand Up @@ -148,14 +147,17 @@ def delete(self):
def content_to_dict(content, group=True, **kwargs):
""" Convert a content (either a path to photo or matplotlib figure) to a telegram-acceptable dictionary. """
# Convert content to a bytestring
from PIL import Image

if isinstance(content, str):
bytes_ = TelegramMessage.path_to_bytes(content)
else:
bytes_ = TelegramMessage.figure_to_bytes(content, **kwargs)

# Create unique id of attachment, pack entities in json
attach_id = f'attached{uuid4().hex}'
attach_fmt = imghdr.what(None, bytes_)
image = Image.open(BytesIO(bytes_))
attach_fmt = image.format.lower()

media_dict = {'media': f'attach://{attach_id}', 'type': 'photo'}
media_dict = [media_dict] if group else media_dict
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ jupyter = [
"requests"
]

telegram = [
"pillow>=9.4,<11.0",
]

other = [
"urllib3>=1.25"
]
Expand Down
4 changes: 4 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading