From 1aba5984d23a235e01693f7700ac1b2c93796094 Mon Sep 17 00:00:00 2001 From: DevilXD Date: Tue, 11 Jan 2022 20:29:13 +0100 Subject: [PATCH] Protect 3p lib imports + update requirements --- gui.py | 10 ++++++++-- requirements.txt | 3 ++- twitch.py | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/gui.py b/gui.py index 6acaed0..dcbe035 100644 --- a/gui.py +++ b/gui.py @@ -13,8 +13,14 @@ from typing import ( Any, Optional, List, Dict, Set, Tuple, TypedDict, Iterable, NoReturn, TYPE_CHECKING ) -from PIL import Image -import pystray +try: + from PIL import Image +except ModuleNotFoundError as exc: + raise ImportError("You have to run 'pip install Pillow' first") from exc +try: + import pystray +except ModuleNotFoundError as exc: + raise ImportError("You have to run 'pip install pystray' first") from exc from version import __version__ from constants import FORMATTER, WS_TOPICS_LIMIT, MAX_WEBSOCKETS, State diff --git a/requirements.txt b/requirements.txt index 50d8e37..b3cbb08 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ aiohttp>2.0,<4.0 -pywin32 +Pillow +pystray diff --git a/twitch.py b/twitch.py index fbb1937..fc0804a 100644 --- a/twitch.py +++ b/twitch.py @@ -14,8 +14,8 @@ from typing import ( try: import aiohttp -except ImportError: - raise ImportError("You have to run 'python -m pip install aiohttp' first") +except ModuleNotFoundError as exc: + raise ImportError("You have to run 'pip install aiohttp' first") from exc from channel import Channel from gui import GUIManager, LoginData