From 550fcfeddcecc7ef36e5b722bda2f2d4a4a90a45 Mon Sep 17 00:00:00 2001 From: Benex254 Date: Sun, 22 Sep 2024 21:50:41 +0300 Subject: [PATCH] feat: make plyer an optional dependency --- fastanime/cli/commands/anilist/notifier.py | 7 ++++- fastanime/cli/utils/tools.py | 9 +++++-- fastanime/libs/rofi/__init__.py | 30 ++++++++++++++++++++-- pyproject.toml | 5 +++- 4 files changed, 45 insertions(+), 6 deletions(-) diff --git a/fastanime/cli/commands/anilist/notifier.py b/fastanime/cli/commands/anilist/notifier.py index b49c5f2..3e5d6d1 100644 --- a/fastanime/cli/commands/anilist/notifier.py +++ b/fastanime/cli/commands/anilist/notifier.py @@ -16,7 +16,12 @@ def notifier(config: "Config"): from sys import exit import requests - from plyer import notification + + try: + from plyer import notification + except ImportError: + print("Please install plyer to use this command") + exit(1) from ....anilist import AniList from ....constants import APP_CACHE_DIR, APP_DATA_DIR, APP_NAME, ICON_PATH, PLATFORM diff --git a/fastanime/cli/utils/tools.py b/fastanime/cli/utils/tools.py index c5260d7..d99034f 100644 --- a/fastanime/cli/utils/tools.py +++ b/fastanime/cli/utils/tools.py @@ -37,8 +37,13 @@ def exit_app(exit_code=0, *args): console = Console() if not console.is_terminal: - from plyer import notification - + try: + from plyer import notification + except ImportError: + print( + "Plyer is not installed; install it for desktop notifications to be enabled" + ) + exit(1) notification.notify( app_name=APP_NAME, app_icon=ICON_PATH, diff --git a/fastanime/libs/rofi/__init__.py b/fastanime/libs/rofi/__init__.py index 13522a3..bef920d 100644 --- a/fastanime/libs/rofi/__init__.py +++ b/fastanime/libs/rofi/__init__.py @@ -2,8 +2,6 @@ import subprocess from shutil import which from sys import exit -from plyer import notification - from fastanime import APP_NAME from ...constants import ICON_PATH @@ -35,6 +33,13 @@ class RofiApi: choice = result.stdout.strip() if not choice: + try: + from plyer import notification + except ImportError: + print( + "Plyer is not installed; install it for desktop notifications to be enabled" + ) + exit(1) notification.notify( app_name=APP_NAME, app_icon=ICON_PATH, @@ -64,6 +69,13 @@ class RofiApi: choice = result.stdout.strip() if not choice or choice not in options: + try: + from plyer import notification + except ImportError: + print( + "Plyer is not installed; install it for desktop notifications to be enabled" + ) + exit(1) notification.notify( app_name=APP_NAME, app_icon=ICON_PATH, @@ -91,6 +103,13 @@ class RofiApi: choice = result.stdout.strip() if not choice: + try: + from plyer import notification + except ImportError: + print( + "Plyer is not installed; install it for desktop notifications to be enabled" + ) + exit(1) notification.notify( app_name=APP_NAME, app_icon=ICON_PATH, @@ -120,6 +139,13 @@ class RofiApi: user_input = result.stdout.strip() if not user_input: + try: + from plyer import notification + except ImportError: + print( + "Plyer is not installed; install it for desktop notifications to be enabled" + ) + exit(1) notification.notify( app_name=APP_NAME, app_icon=ICON_PATH, diff --git a/pyproject.toml b/pyproject.toml index 2819daa..7250491 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,10 @@ click = "^8.1.7" inquirerpy = "^0.3.4" thefuzz = "^0.22.1" requests = "^2.32.3" -plyer = "^2.1.0" +plyer = { version = "^2.1.0", optional = true } + +[tool.poetry.extras] +full = ["plyer"] mpv = "^1.0.7" [tool.poetry.group.dev.dependencies]