Skip to content

Commit

Permalink
Move plugins out of amulet_editor (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlegiantJGC authored May 7, 2024
1 parent a7eeea0 commit 7694ef2
Show file tree
Hide file tree
Showing 1,577 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/amulet_editor/__pyinstaller/hook-amulet_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
datas = [
*collect_data_files("amulet_editor", excludes=["**/*.ui", "**/*.c", "**/*.pyx"]),
*collect_data_files(
"amulet_editor.plugins",
"builtin_plugins",
include_py_files=True,
excludes=["**/*.ui", "**/*.c", "**/*.pyx", "**/*.pyc"],
),
*copy_metadata("amulet_editor", recursive=True),
]

hiddenimports = [
*collect_submodules("amulet_editor", lambda name: name != "amulet_editor.plugins"),
*collect_submodules("amulet_editor"),
"PySide6",
"OpenGL",
]
16 changes: 14 additions & 2 deletions src/amulet_editor/data/paths/_plugin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import os
import importlib.util

import amulet_editor
from ._application import data_directory


_builtin_plugin_dir: str | None = None


def first_party_plugin_directory() -> str:
return os.path.abspath(os.path.join(amulet_editor.__path__[0], "plugins"))
global _builtin_plugin_dir
if _builtin_plugin_dir is None:
spec = importlib.util.find_spec("builtin_plugins")
if spec is None:
raise RuntimeError
paths = spec.submodule_search_locations
if not paths:
raise RuntimeError
_builtin_plugin_dir = paths[0]
return _builtin_plugin_dir


def third_party_plugin_directory() -> str:
Expand Down
5 changes: 2 additions & 3 deletions src/amulet_editor/data/plugin/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@

"""
Notes:
First party plugins are stored in amulet_editor.plugins
They cannot be imported from that path because the __init__.py disallows it.
First party plugins are stored in builtin_plugins
Third party plugins are imported as a zip and extracted to a writable directory with a UUID as the name.
Custom code loads the plugin package into sys.modules under its package name. Adding amulet_editor.plugins as sources root helps the IDE understand this.
Custom code loads the plugin package into sys.modules under its package name. Adding builtin_plugins as sources root helps the IDE understand this.
TODO: look into generating stub files for the active plugins to help with development on the compiled version.
Plugins can import directly from other plugins to access static classes and functions
"""
Expand Down
1 change: 0 additions & 1 deletion src/amulet_editor/plugins/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations
import os
from typing import Optional

from PySide6.QtCore import QLocale, QCoreApplication

Expand All @@ -16,16 +15,16 @@


# Qt only weekly references this. We must hold a strong reference to stop it getting garbage collected
_translator: Optional[ATranslator] = None
_translator: ATranslator | None = None

home_button: Optional[amulet_team_main_window2.ButtonProxy] = None
home_button: amulet_team_main_window2.ButtonProxy | None = None


def _set_home_layout():
def _set_home_layout() -> None:
amulet_team_main_window2.get_main_window().set_layout(HomeWidget)


def load_plugin():
def load_plugin() -> None:
global _translator, home_button
_translator = ATranslator()
_locale_changed()
Expand All @@ -44,15 +43,15 @@ def load_plugin():
home_button.click()


def _locale_changed():
def _locale_changed() -> None:
_translator.load_lang(
QLocale(),
"",
directory=os.path.join(*amulet_team_home_page.__path__, "resources", "lang"),
)


def unload_plugin():
def unload_plugin() -> None:
amulet_team_main_window2.unregister_widget(HomeWidget)
QCoreApplication.removeTranslator(_translator)

Expand Down
File renamed without changes.
Loading

0 comments on commit 7694ef2

Please sign in to comment.