Skip to content

Commit

Permalink
Update v0.8.6
Browse files Browse the repository at this point in the history
Merge pull request #47 from romanin-rf/dev
  • Loading branch information
romanin-rf authored Dec 17, 2023
2 parents d138e55 + d999bb6 commit 99f232c
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 29 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
- name: Building wheel
run: |
poetry update
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

| Version | Date | Tag | Changelog |
| ------- | ---- | --- | --------- |
| [v0.8.6](https://github.com/romanin-rf/SeaPlayer/releases/tag/v0.8.6) | 17.12.2023 | **STABLE** | - Added new methods for `seaplayer.plug.pluginloader.PluginLoaderConfigManager`: **remove_plugin** & **remove_plugin_by_name_id**<br>- Added new command for `seaplug`: **unload**<br>- Added version message for `seaplug`<br>- Fixed typing for: `seaplayer.plug.pluginloader.PluginLoader.search_plugins_paths` & `seaplayer.plug.pluginloader.PluginLoader.aio_search_plugins_paths`<br>- Replaced option `--recreate` with `--overwrite` in `seaplayer.plug.cli.cli.creating`<br>- Replaced option `--rewrite` with `--overwrite` in `seaplayer.plug.cli.cli.loading` |
| [v0.8.5](https://github.com/romanin-rf/SeaPlayer/releases/tag/v0.8.5) | 16.12.2023 | **STABLE** | - Added support for **python3.8**<br>- Added `on_ready` abstract methods for plugins<br>- Added new widgets: `PopUpWindow`, `WaitButton`<br>- Fixed method `add_sounds_to_list`<br>- Fixed `seaplayer.plug.cli`<br>- Fixed `build.py`<br>- Updated all child custom modules |
| [v0.8.4](https://github.com/romanin-rf/SeaPlayer/releases/tag/v0.8.4) | 11.12.2023 | **DEPRECATED** | - Added widgets: `Rheostat`, `ClickableLabel`<br>- Added widget: Rheostat<br>- Added a new widget: `PopUp`<br>- Fixed all language<br>- More attempts to make `Confiturate` screen clearer<br>- Moved all `CSS` from `objects.tcss` to `DEFAULT_CSS` separately for each widget |
| [v0.8.3](https://github.com/romanin-rf/SeaPlayer/releases/tag/v0.8.3) | 10.12.2023 | **STABLE** | - Added plugin `VKMusic`<br>- Added priority system for codecs<br>- Added system handhers of value<br>- Fixed `build.py`<br>- Moved method `load_plugin_info` in `seaplayer.plug.pluginloader` |
Expand Down
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.8.5"
version = "0.8.6"
description = "SeaPlayer is a player that works in the terminal."
repository = "https://github.com/romanin-rf/SeaPlayer"
authors = ["Romanin <[email protected]>"]
Expand Down
49 changes: 36 additions & 13 deletions seaplayer/plug/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from rich.live import Live
# > Local Import's
from .exceptions import *
from .vars import CREATE_DEFAULT_CODE
from ...units import PLUGINS_CONFIG_PATH, PLUGINS_DIRPATH
from ..pluginbase import PluginInfo
from ..pluginloader import PluginLoaderConfigManager
Expand All @@ -14,7 +13,15 @@
is_config_inited,
get_plugins_info,
raise_exception,
is_plugin_dirpath
is_plugin_dirpath,
search_plugin_info,
get_plugin_dirpath_by_name_id
)
from .units import (
CREATE_DEFAULT_CODE,
__prog_name__,
__prog_title__,
__prog_version__
)

# ! Init
Expand Down Expand Up @@ -84,18 +91,19 @@ def listing():
type=str, default=None
)
@click.option(
"--recreate", "recreate",
"--overwrite", "-o", "overwrite",
help="Ignores if there is already a plugin in the folder and overwrites it.",
is_flag=True, default=False
)
def creating(dirpath: str, recreate: bool, **kwargs: str):
def creating(dirpath: str, overwrite: bool, **kwargs: str):
dirpath = os.path.abspath(dirpath)
try:
if (not is_plugin_dirpath(dirpath)) or recreate:
if (not is_plugin_dirpath(dirpath)) or overwrite:
info = PluginInfo(**kwargs)

with open(os.path.join(dirpath, "info.json"), "w", encoding="utf-8") as file:
file.write(info.model_dump_json())

with open(os.path.join(dirpath, "__init__.py"), "w", encoding="utf-8") as file:
file.write(CREATE_DEFAULT_CODE)

Expand All @@ -108,33 +116,47 @@ def creating(dirpath: str, recreate: bool, **kwargs: str):
@click.command("load", help="Load the plugin into the SeaPlayer plugins directory.")
@click.argument("dirpath", type=click.Path(True, False))
@click.option(
"--rewrite", "-w", "rewrite",
"--overwrite", "-o", "overwrite",
help="Delete if it exists and overwrite.",
is_flag=True, default=False
)
def loading(dirpath: str, rewrite: bool):
def loading(dirpath: str, overwrite: bool):
dirpath = os.path.abspath(dirpath)
if is_plugin_dirpath(dirpath):
with Live("[yellow]Loading...[/yellow]", console=console) as l:
to_path = os.path.join(PLUGINS_DIRPATH, os.path.basename(dirpath))
if rewrite: shutil.rmtree(to_path, ignore_errors=True)
shutil.copytree(
dirpath,
to_path,
dirs_exist_ok=True
)
if overwrite:
shutil.rmtree(to_path, ignore_errors=True)
shutil.copytree(dirpath, to_path, dirs_exist_ok=True)
init_config()
l.update("[yellow]Plugin [green]loaded[/green]![/yellow]", refresh=True)
else:
raise_exception(console, IsNotPluginDirectoryError, dirpath)

@click.command("unload", help="Removing the plugin from the SeaPlayer.")
@click.argument("plugin_name_id")
def unloading(plugin_name_id: str):
plugin_dirpath = get_plugin_dirpath_by_name_id(plugin_name_id)
if plugin_dirpath is not None:
shutil.rmtree(plugin_dirpath, ignore_errors=True)
if plugin_config.exists_plugin_by_name_id(plugin_name_id):
plugin_config.remove_plugin_by_name_id(plugin_name_id)
console.print("[yellow]Plugin [red]unloaded[/red].[/yellow]")
else:
raise_exception(console, PluginNotExistsError, plugin_name_id)

# ! Main Group
@click.group
@click.option(
"--init-config", "initialization_config",
help="Forced (re)initialisation of the config.",
is_flag=True, default=False
)
@click.version_option(
version=__prog_version__,
package_name=__prog_name__,
prog_name=__prog_title__
)
def main(initialization_config: bool):
if (not is_config_inited()) or initialization_config:
init_config()
Expand All @@ -145,3 +167,4 @@ def main(initialization_config: bool):
main.add_command(listing)
main.add_command(creating)
main.add_command(loading)
main.add_command(unloading)
16 changes: 15 additions & 1 deletion seaplayer/plug/cli/functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from rich.console import Console
# > Typing
from typing import List
from typing import List, Optional
# > Local Import's
from .functions import *
from ..pluginbase import PluginInfo
Expand Down Expand Up @@ -44,6 +44,20 @@ def get_plugins_info() -> List[PluginInfo]:
console.print_exception()
return plugins_infos

def search_plugin_info(name_id: str) -> Optional[PluginInfo]:
for plugin_info in get_plugins_info():
if plugin_info.name_id == name_id:
return plugin_info

def get_plugin_dirpath_by_name_id(name_id: str) -> Optional[str]:
for plugin_init_path, plugin_info_path, plugin_deps_path in PluginLoader.search_plugins_paths():
try:
plugin_info = load_plugin_info(plugin_info_path)
if plugin_info.name_id == name_id:
return os.path.dirname(plugin_init_path)
except:
console.print_exception()

def is_plugin_dirpath(dirpath: str) -> bool:
try:
assert os.path.exists(dirpath)
Expand Down
17 changes: 17 additions & 0 deletions seaplayer/plug/cli/units.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# ! Metadata
__prog_name__ = 'seaplug'
__prog_title__ = 'SeaPlayer Plugins System CLI'
__prog_version__ = '0.3.0'
__prog_author__ = 'Romanin'
__prog_email__ = '[email protected]'

# ! Vars
CREATE_DEFAULT_CODE = """\
from seaplayer.plug import PluginBase
class Plugin(PluginBase):
pass
__plugin__ = Plugin
"""
8 changes: 0 additions & 8 deletions seaplayer/plug/cli/vars.py

This file was deleted.

8 changes: 8 additions & 0 deletions seaplayer/plug/pluginloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ def add_plugin(self, info: PluginInfo) -> None:
self.config.plugins_enable[info.name_id] = True
self.refresh()

def remove_plugin(self, info: PluginInfo) -> None:
del self.config.plugins_enable[info.name_id]
self.refresh()

def remove_plugin_by_name_id(self, name_id: str) -> None:
del self.config.plugins_enable[name_id]
self.refresh()

def is_enable_plugin(self, info: PluginInfo) -> bool:
for name_id, enable in self.config.plugins_enable.items():
if name_id == info.name_id:
Expand Down
6 changes: 4 additions & 2 deletions seaplayer/plug/pluginloader.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class PluginLoaderConfigManager:
def exists_plugin(self, info: PluginInfo) -> bool: ...
def exists_plugin_by_name_id(self, name_id: str) -> bool: ...
def add_plugin(self, info: PluginInfo) -> None: ...
def remove_plugin(self, info: PluginInfo) -> None: ...
def remove_plugin_by_name_id(self, name_id: str) -> None: ...
def is_enable_plugin(self, info: PluginInfo) -> bool: ...
def disable_plugin(self, info: PluginInfo) -> None: ...
def disable_plugin_by_name_id(self, name_id: str) -> None: ...
Expand Down Expand Up @@ -77,9 +79,9 @@ class PluginLoader:
...

@staticmethod
async def aio_search_plugins_paths() -> AsyncGenerator[Tuple[INIT_FILE_PATH, INFO_FILE_PATH, DEPS_FILE_PATH]]: ...
async def aio_search_plugins_paths() -> AsyncGenerator[Tuple[INIT_FILE_PATH, INFO_FILE_PATH, Optional[DEPS_FILE_PATH]]]: ...
@staticmethod
def search_plugins_paths() -> Generator[Tuple[INIT_FILE_PATH, INFO_FILE_PATH, DEPS_FILE_PATH], Any, None]: ...
def search_plugins_paths() -> Generator[Tuple[INIT_FILE_PATH, INFO_FILE_PATH, Optional[DEPS_FILE_PATH]], Any, None]: ...

# ! App Specific Methods
def on_bindings(self) -> Generator[Binding, Any, None]: ...
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.8.5"
__version__ = "0.8.6"
__author__ = "Romanin"
__email__ = "[email protected]"
__url__ = "https://github.com/romanin-rf/SeaPlayer"
Expand Down

0 comments on commit 99f232c

Please sign in to comment.