Skip to content

educationwarehouse/edwh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

edwh

PyPI - Version PyPI - Python Version


Table of Contents

Installation

pipx install edwh
# or: uvenv install edwh

# or with all plugins:
pipx install[plugins]
# or with specific plugins: 
pipx install[multipass,restic]

# managing plugins later:
edwh plugins
edwh plugin.add multipass
edwh plugin.remove multipass

Usage

# to see all available commands:
ew # or `edwh`
# to see help about a specific namespace:
ew help <namespace> # e.g. `ew help plugin`
# to see help about a specific command:
ew help <command> # e.g. `ew help plugin.list` 

Task Load Order

Commands are loaded in the following order:

  1. EDWH Package:

    • Loaded into the global namespace and its own namespaces (like ew plugins.).
  2. Plugins:

    • Loaded into their own namespaces (like ew mp.).
  3. Current Directory:

    • Loaded into the local. namespace. If it doesn't exist, it traverses up the directory tree
    • (e.g., ../tasks.py, ../../tasks.py).
  4. Other Local Tasks:

    • Other local tasks with their own namespace are loaded (e.g., namespace.tasks.py) and can be invoked with edwh namespace.command.
  5. Personal Global Tasks:

    • Personal global tasks (e.g., ~/.config/edwh/tasks.py) are also loaded into the global namespace, useful for shortcuts, custom aliases, etc. (+ add_alias).
  6. Personal Namespaced Tasks:

    • Personal tasks with their own namespace (e.g., ~/.config/edwh/namespace.tasks.py). Similar to a plugin, but for personal use.

Plugins

Multipass

Restic

Pip Compile

Bundler

Server Provisioning

b2

Locust

sshkey

sshfs

files

whitelabel

devdb

Improvements to @task

The edwh.improved_task decorator enhances the functionality of the standard @task decorator from Invoke by introducing additional features:

  • Flags: You can now specify custom flags for command line arguments. This allows you to define aliases, rename arguments (e.g., using --json for an argument named as_json), and create custom short flags (e.g., --exclude can also be represented as -x).

  • Hookable: The improved task supports hooks that allow you to run additional tasks after the main task execution. If the hookable option is set to True, any tasks found across namespaces with the same name will be executed in sequence, passing along the context and any provided arguments.

The return value of a hookable task will be available in the context under the key result. Using a dictionary as the return value is recommended, as it allows you to merge the results of multiple cascading tasks.

Example Usage

from edwh import improved_task as task


@task(flags={'exclude': ['--exclude', '-x'], 'as_json': ['--json']}, hookable=True)
def process_data(ctx, exclude: str, as_json: bool = False):
    # Task implementation here
    return {
        "data": [],
    }


# other plugin (or local tasks.py) can now also specify 'process_data':
@task()
def process_data(ctx, exclude: str):
    # the cascading function can choose whether to include the arguments `exclude` and `as_json` or not.
    # this can be cherry-picked as long as the names match the arguments of the main function.
    print(
        ctx["result"] # will contain {"data": []}
    )

License

edwh is distributed under the terms of the MIT license.

Changelog

See CHANGELOG.md