Skip to content

Commit

Permalink
fix: New Extension structure and template (nightly)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlin7 committed Jun 29, 2024
1 parent 2a86577 commit e062c43
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 19 deletions.
12 changes: 9 additions & 3 deletions extensions/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@

import typing

from biscuit.extensions import Extension

if typing.TYPE_CHECKING:
from biscuit import ExtensionsAPI
from biscuit.api import ExtensionsAPI

# 4. Create a class named `Extension` as follows:


class DevMode:
class DevMode(Extension):
"""Dev Mode extension for Biscuit (author: @billyeatcookies)
Contributes:
- notifies user that dev mode is enabled
"""

def __init__(self, api: ExtensionsAPI) -> None:
self.api = api
super().__init__(api)

self.api.logger.info(f"This is a sample log!")

def install(self) -> None:
self.api.notifications.info(f"Dev mode is enabled!")


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 = "biscuit-editor"
version = "2.99.9"
version = "2.99.10"
description = "A lightweight, fast, and extensible code editor with a growing community"
authors = ["Billy <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/biscuit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.99.9"
__version__ = "2.99.10"
__version_info__ = tuple([int(num) for num in __version__.split(".")])

from .main import *
6 changes: 5 additions & 1 deletion src/biscuit/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ def register(self, name: str, extension: object) -> None:
"""Register an extension"""

self.base.extensions_manager.register_installed(name, extension)
# extension.install()

def register_extension(self, name: str, extension: object) -> None:
"""Register an extension"""

self.register(name, extension)
3 changes: 2 additions & 1 deletion src/biscuit/extensions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .extensions import *
from .extension import Extension
from .extensions import ExtensionManager
20 changes: 13 additions & 7 deletions src/biscuit/extensions/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import requests

from biscuit.views.extensions.extension import Extension
from biscuit.views.extensions.extension import ExtensionGUI

if typing.TYPE_CHECKING:
from biscuit import App
Expand Down Expand Up @@ -54,7 +54,7 @@ def install_extension_from_name(self, name: str) -> bool:
data = self.fetched[name]

t = self.run_fetch_extension(
Extension(self.base.extensions_view.results, name, data)
ExtensionGUI(self.base.extensions_view.results, name, data)
)
t.join()

Expand Down Expand Up @@ -136,7 +136,7 @@ def fetch_extensions(self) -> None:
# TODO add further loops for folders
self.fetch_queue.put((name, data))

def run_fetch_extension(self, ext: Extension) -> None:
def run_fetch_extension(self, ext: ExtensionGUI) -> None:
"""Called from the Extension View to fetch an extension."""

if ext.installed:
Expand All @@ -148,7 +148,7 @@ def run_fetch_extension(self, ext: Extension) -> None:
t.start()
return t

def fetch_extension(self, ext: Extension) -> None:
def fetch_extension(self, ext: ExtensionGUI) -> None:
"""Fetch an extension from the repository."""

try:
Expand All @@ -158,7 +158,7 @@ def fetch_extension(self, ext: Extension) -> None:
except:
ext.set_unavailable()

def save_extension(self, ext: Extension, response: requests.Response) -> None:
def save_extension(self, ext: ExtensionGUI, response: requests.Response) -> None:
"""Save a fetched extension. Saves the extension and loads it."""

with open(ext.file, "w") as fp:
Expand All @@ -170,7 +170,7 @@ def save_extension(self, ext: Extension, response: requests.Response) -> None:
self.base.logger.info(f"Fetching extension '{ext.name}' successful.")
self.base.notifications.info(f"Extension '{ext.name}' has been installed!")

def remove_extension(self, ext: Extension) -> None:
def remove_extension(self, ext: ExtensionGUI) -> None:
"""Remove an extension from the system."""

try:
Expand Down Expand Up @@ -236,7 +236,7 @@ def load_extensions(self):
extension_module.setup(self.base.api)

self.base.logger.info(f"Extension '{ext}' loaded.")
except ImportError as e:
except Exception as e:
self.base.logger.error(f"Failed to load extension '{ext}': {e}")
self.base.notifications.error(f"Extension '{ext}' failed: see logs.")
if ext in self.installed:
Expand All @@ -246,6 +246,12 @@ def register_installed(self, name: str, extension: object) -> None:
"""Register an installed extension."""

self.installed[name] = extension
try:
extension.install()
except Exception as e:
print("no install method !!!!!!!!!!!!")
# most likely the extension does not implement the install method
...

def queue_installed_extensions(self) -> None:
for extension_file in os.listdir(self.base.extensionsdir):
Expand Down
2 changes: 1 addition & 1 deletion src/biscuit/views/extensions/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .results import Results


class Extension(Frame):
class ExtensionGUI(Frame):
"""Extension item in the Extensions view.
The Extension class represents an extension item in the Extensions view.
Expand Down
8 changes: 4 additions & 4 deletions src/biscuit/views/extensions/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
from biscuit.common.ui import ScrollableFrame

from ..drawer_item import NavigationDrawerViewItem
from .extension import Extension
from .extension import ExtensionGUI
from .placeholder import ExtensionsPlaceholder

if typing.TYPE_CHECKING:
from biscuit.extensions import ExtensionManager


class ExtensionsList(ScrollableFrame):
items: list[Extension]
items: list[ExtensionGUI]

def __init__(self, master, *args, **kwargs) -> None:
super().__init__(master, *args, **kwargs)
Expand Down Expand Up @@ -78,7 +78,7 @@ def refresh(self, *_) -> None:
def gui_refresh_loop(self) -> None:
if not self.fetch_queue.empty():
name, data = self.fetch_queue.get()
ext = Extension(self, name, data)
ext = ExtensionGUI(self, name, data)
self.extension_list.add(ext, fill=tk.X)

self.after(5, self.gui_refresh_loop)
Expand All @@ -91,7 +91,7 @@ def clear(self, *_) -> None:

self.fetching.set()

def set_selected(self, extension: Extension) -> None:
def set_selected(self, extension: ExtensionGUI) -> None:
for widget in self.extension_list.items:
if widget == extension:
widget.select()
Expand Down

0 comments on commit e062c43

Please sign in to comment.