Easier way to manage your project addons
Project description
Relative Addons System
This is a special system that allows you to manage your addons in runtime.
The library has caching that allows it to work faster
Definitions
Addon - directory that contains addon.json
and __init__.py
addon.json is a json
file that describes addon and must contain name
, author
,
description
and version
(strings)
Usage examples
from pathlib import Path
from RelativeAddonsSystem import RelativeAddonsSystem, Addon, AddonMeta
# Init addons system
system = RelativeAddonsSystem(Path(__file__).parent / "addons", auto_install_requirements=True)
# return list of Addon objects
addons: list[Addon] = system.get_all_addons()
if len(addons) < 1:
print("No addons found")
else:
for addon in addons:
# loaded meta(AddonMeta) from ADDON_DIR/addon.json
meta: AddonMeta = addon.meta
print("Working with", meta.name, "at", addon.path.absolute())
# Check dependencies
if not addon.check_requirements(alert=False):
print("Installing addon dependencies")
# Install dependencies
installed: list[str] = addon.install_requirements()
print("Successfully installed addon dependencies (", ", ".join(installed), ")")
else:
print("Addon dependencies already satisfied")
# Get addon module
module = addon.module # ADDON_DIR / __init__.py module
...
In this example, we have listed all addons and installed their dependencies if they were not already installed.
We can also disable or enable addons:
from pathlib import Path
from RelativeAddonsSystem import RelativeAddonsSystem, Addon
# Init addons system
system = RelativeAddonsSystem(Path(__file__).parent / "addons", auto_install_requirements=True)
addons: list[Addon] = system.get_enabled_addons() # get all enabled addons
if len(addons) > 0:
addon: Addon = addons[0] # first addon from list
addon.disable() # disable addon
...
addon.enable() # enable addon
Or import and re-import the module (useful when we have updated your addon):
from pathlib import Path
from RelativeAddonsSystem import RelativeAddonsSystem, Addon
# Init addons system
system = RelativeAddonsSystem(Path(__file__).parent / "addons", auto_install_requirements=True)
addons: list[Addon] = system.get_enabled_addons() # get all enabled addons
if len(addons) > 0:
addon: Addon = addons[0] # first addon from list
module = addon.module
... # Work with module
# Reimport module
module = addon.reload_module()
... # Work with module
We can also change the metadata in your code:
from pathlib import Path
from RelativeAddonsSystem import RelativeAddonsSystem, Addon, AddonMeta
# Init addons system
system = RelativeAddonsSystem(Path(__file__).parent / "addons", auto_install_requirements=True)
addons: list[Addon] = system.get_enabled_addons() # get all enabled addons
if len(addons) > 0:
addon: Addon = addons[0] # first addon from list
meta: AddonMeta = addon.meta
meta.set("version", "1.2")
meta.save()
Or set specific data into the addon's storage:
from pathlib import Path
from RelativeAddonsSystem import RelativeAddonsSystem, Addon
from RelativeAddonsSystem.utils import Storage
# Init addons system
system = RelativeAddonsSystem(Path(__file__).parent / "addons", auto_install_requirements=True)
addons: list[Addon] = system.get_enabled_addons() # get all enabled addons
if len(addons) > 0:
addon: Addon = addons[0] # first addon from list
# Loaded the ADDON_DIR/ADDON_NAME-storage.json file
storage: Storage = addon.get_storage()
storage.set("api_version", "1.2")
storage.save()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for relative-addons-system-2.6.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 193ee25403d7a0de3050b7784d7f848271952d4c5e135655821fcfa6d5b953dc |
|
MD5 | 313ba5b002bb0b91d0b9319acb7c5b54 |
|
BLAKE2b-256 | eb24fcbfe6220cf749bf0166b31a66a5a6cb0c031c77e1309cccff9816ea3c31 |
Hashes for relative_addons_system-2.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c20c2615bf43e731d2f1ed016c19aa6e74d1453bdebd6f18af6a952cd6b2d936 |
|
MD5 | f764075fb267397469f890f5c7bc6542 |
|
BLAKE2b-256 | b1a8f25eae6a877e2833f68873e4b39d11e41fe32a05d2e2800955aaa7957fe2 |