Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

relative-addons-system-2.5.4.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

relative_addons_system-2.5.4-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file relative-addons-system-2.5.4.tar.gz.

File metadata

File hashes

Hashes for relative-addons-system-2.5.4.tar.gz
Algorithm Hash digest
SHA256 18b9514fcf516cb6b3db94f7433c9b95feb284b37abb95171fbddd612d316989
MD5 4bb0a8e0e7387f7300811b9b004219ff
BLAKE2b-256 1b41b2a4bd035f20d8e833ff15bc5b1e09d942d2845b1d19b7c8d6c8f8b68253

See more details on using hashes here.

Provenance

File details

Details for the file relative_addons_system-2.5.4-py3-none-any.whl.

File metadata

File hashes

Hashes for relative_addons_system-2.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3019e750be0cf9e25cad8cd6f931a1303f6b321adf72f14354888d36b5a1994a
MD5 da0dacc5e175575a5760b417af28e6f7
BLAKE2b-256 6f3b946f5479a57d1d82a338d8ce24b6db5360d41268b09f7d6cf6bb9240beaa

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page