Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 0.7.2.post6 #22

Merged
merged 1 commit into from
Nov 29, 2023
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: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "SeaPlayer"
version = "0.7.2.post5"
version = "0.7.2.post6"
description = "SeaPlayer is a player that works in the terminal."
repository = "https://github.com/romanin-rf/SeaPlayer"
authors = ["Romanin <semina054@gmail.com>"]
Expand Down
26 changes: 20 additions & 6 deletions seaplayer/objects/Log.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from rich.console import Console
from textual.widgets import RichLog
# > Typing
from typing import TypeVar
# > Local Import's
from ..functions import rich_exception

# ! Vars
console = Console()

# ! Types
RETURN = TypeVar('RETURN')

Expand All @@ -20,11 +24,21 @@ def __init__(self, chap_max_width: int=8, enable_logging: bool=True, **kwargs):

super().__init__(**kwargs)

def write_log(self, chap: str, msg: str, *, chap_color: str="green") -> None:
def write_log(self, chap: str, msg: str, *, chap_color: str="green", in_console: bool=False) -> None:
if self.enable_logging:
self.write(f"[[{chap_color}]{chap.center(self.chap_max_width)}[/]]: {msg}", shrink=False)
text = f"[[{chap_color}]{chap.center(self.chap_max_width)}[/]]: {msg}"
self.write(text, shrink=False)
if in_console:
console.print(text)

def info(self, msg: str, *, in_console: bool=False) -> None:
self.write_log("INFO", msg, chap_color="green", in_console=in_console)

def error(self, msg: str, *, in_console: bool=False) -> None:
self.write_log("ERROR", msg, chap_color="red", in_console=in_console)

def warn(self, msg: str, *, in_console: bool=False) -> None:
self.write_log("WARN", msg, chap_color="orange", in_console=in_console)

def info(self, msg: str) -> None: self.write_log("INFO", msg, chap_color="green")
def error(self, msg: str) -> None: self.write_log("ERROR", msg, chap_color="red")
def warn(self, msg: str) -> None: self.write_log("WARN", msg, chap_color="orange")
def exception(self, e: Exception) -> None: self.write_log("ERROR", rich_exception(e), chap_color="red")
def exception(self, e: Exception, *, in_console: bool=False) -> None:
self.write_log("ERROR", rich_exception(e), chap_color="red", in_console=in_console)
5 changes: 1 addition & 4 deletions seaplayer/plug/pipw.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ def __init__(self) -> None:
self.python_path = sys.executable

def __call__(self, *args: str) -> str:
return subprocess.check_output(
[self.python_path, "-m", "pip", *args],
stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL
).decode(errors="ignore")
return subprocess.check_output([self.python_path, "-m", "pip", *args]).decode(errors="ignore")

def install(self, *args: str) -> str:
return self.__call__("install", *args)
Expand Down
39 changes: 22 additions & 17 deletions seaplayer/plug/pluginloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import asyncio
from pathlib import Path
from pydantic import BaseModel
from rich.console import Console
# > ImportLib
from importlib.util import spec_from_file_location, module_from_spec
# > Typing
Expand All @@ -21,6 +22,9 @@
GLOB_PLUGINS_DEPS_SEARCH
)

# ! Vars
console = Console()

# ! Types
class PluginModuleType(ModuleType):
plugin_main: Type[PluginBase]
Expand Down Expand Up @@ -123,7 +127,7 @@ def enable_plugin_by_name_id(self, name_id: str) -> None:
# ! Plugin Loader Class
class PluginLoader:
__title__: str = "PluginLoader"
__version__: str = "0.2.0"
__version__: str = "0.2.6"
__author__: str = "Romanin"
__email__: str = "semina054@gmail.com"

Expand Down Expand Up @@ -205,44 +209,45 @@ def load_plugin_info(path: str) -> PluginInfo:
return PluginInfo.model_validate_json(data)

def on_init(self) -> None:
self.app.info(f"{self.__title__} [#00ffee]v{self.__version__}[/#00ffee] from {self.__author__} ({self.__email__})")
self.app.info(f"{self.__title__} [#00ffee]v{self.__version__}[/#00ffee] from {self.__author__} ({self.__email__})", in_console=True)
plugins_paths = list(self.search_plugins_paths())
self.app.info(f"Found plugins : {repr([os.path.basename(os.path.dirname(i[0])) for i in plugins_paths])}")
self.app.info(f"Initialization plugins...")
self.app.info(f"Found plugins : {repr([os.path.basename(os.path.dirname(i[0])) for i in plugins_paths])}", in_console=True)
self.app.info(f"Initialization plugins...", in_console=True)
for init_path, info_path, deps_path in plugins_paths:
info = None
try:
info = self.load_plugin_info(info_path)
if not self.config.exists_plugin(info):
self.config.add_plugin(info)
self.app.info(f"{info.name} ({repr(info.name_id)}) > New plugin added to config!")
self.app.info(f"{info.name} ({repr(info.name_id)}) > New plugin added to config!", in_console=True)
if self.config.is_enable_plugin(info):
self.app.info(f"{info.name} ({repr(info.name_id)}) > Plugin is [green]enabled[/green]!")
self.app.info(f"{info.name} ({repr(info.name_id)}) > Plugin is [green]enabled[/green]!", in_console=True)
if deps_path is not None:
self.app.info(f"{info.name} ({repr(info.name_id)}) > Installing plugin dependencies...")
self.app.info(f"[#8700af]pip.install[/#8700af]:\n{pip.install_requirements(deps_path, True)}")
self.app.info(f"{info.name} ({repr(info.name_id)}) > Installed!")
self.app.info(f"{info.name} ({repr(info.name_id)}) > Importing in SeaPlayer...")
self.app.info(f"{info.name} ({repr(info.name_id)}) > Installing plugin dependencies...", in_console=True)
pip.install_requirements(deps_path, True)
self.app.info(f"{info.name} ({repr(info.name_id)}) > Installed!", in_console=True)
self.app.info(f"{info.name} ({repr(info.name_id)}) > Importing in SeaPlayer...", in_console=True)
plugin_module = load_module(init_path)
plugin = plugin_from_module(self.app, self, info, plugin_module)
self.app.info(f"{info.name} ({repr(info.name_id)}) > Imported!")
self.app.info(f"{info.name} ({repr(info.name_id)}) > Imported!", in_console=True)
try:
plugin.on_init()
except:
self.app.error(f"Failed to do [green]`on_init`[/green] in: {plugin.info}")
self.app.error(f"Failed to do [green]`on_init`[/green] in: {plugin.info}", in_console=True)
self.on_plugins.append(plugin)
else:
self.app.info(f"{info.name} ({repr(info.name_id)}) > Plugin is [red]disabled[/red]!")
self.app.info(f"{info.name} ({repr(info.name_id)}) > Plugin is [red]disabled[/red]!", in_console=True)
self.off_plugins.append(info)
except Exception as e:
self.error_plugins.append( (info_path, init_path) )
if info is not None:
self.app.error(f"Failed to load plugin: {repr(info)}")
self.app.error(f"Failed to load plugin: {repr(info)}", in_console=True)
else:
self.app.error(f"Failed to load plugin: {repr(os.path.basename(os.path.dirname(info_path)))}")
self.app.error(f"Failed to load plugin: {repr(os.path.basename(os.path.dirname(info_path)))}", in_console=True)
raise e
self.app.info(f"Plugins loaded ([green]ON [/green]) : {repr(self.on_plugins)}")
self.app.info(f"Plugins loaded ([red]OFF[/red]) : {repr(self.off_plugins)}")
self.app.info(f"Plugins loaded ([green]ON [/green]) : {repr(self.on_plugins)}", in_console=True)
self.app.info(f"Plugins loaded ([red]OFF[/red]) : {repr(self.off_plugins)}", in_console=True)
self.app.info(f"---", in_console=True)

def on_run(self) -> None:
for i in self.on_plugins:
Expand Down
2 changes: 1 addition & 1 deletion seaplayer/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# ! Metadata
__title__ = "SeaPlayer"
__version__ = "0.7.2.post5"
__version__ = "0.7.2.post6"
__author__ = "Romanin"
__email__ = "semina054@gmail.com"
__url__ = "https://github.com/romanin-rf/SeaPlayer"
Expand Down