Skip to main content

Simple execution orchestrator.

Project description

Molot

GitHub Actions PyPI Downloads License: MIT Code style: black

Simple execution orchestrator.

Requirements

Molot requires Python 3.8 or above.

Usage

Create a new orchestration file, e.g. build.py for a build orchestration. Make it executable chmod +x build.py to make it easier to run.

#!/usr/bin/env python3
from molot import *  # pylint: disable=wildcard-import,unused-wildcard-import

# Your targets and environment arguments here

evaluate()

Pylint comment silences editor warnings about wildcard imports, you can alternatively import everything individually.

Now you're ready to run the build script to see the help message:

./build.py

To only see a list of targets and environment arguments, call the built-in list target:

./build.py list

Not very exciting so far, let's learn how to add your own targets and environment arguments.

Targets

Any piece of work that your build needs to perform is defined as a target. Here's a trivial example of a target that executes ls.

@target(
    name="ls",
    description="lists current directory items",
    group="greetings",
    depends=["target1", "target2"]
)
def ls():
    shell("ls")

Parameters explained:

  • name - unique name to reference the target (optional; function name is used by default)
  • description - short description of what the target does displayed in the help message (optional)
  • group - grouping to list target under (optional; listed under "ungrouped" by default)
  • depends - list of other targets that must be executed first (optional)

Since all the parameters are optional, the shortest definition of the same target can be as follows:

@target()
def ls():
    shell("ls")

Here's how you run your new target:

./build.py ls

Dependency Resolution

Now we can define another target hello that depends on ls:

@target(description="say hello", depends=["ls"])
def hello():
    print("hello")

There is basic dependency resolution that checks for circular dependencies and finds all transitive dependency targets to execute before running the one that you called. When you call:

./build.py hello

What actually happens is equivalent to calling:

./build.py ls hello

Environment Arguments

Environment arguments ar a cross between environment variables and arguments. Values can be passed as the former and then overriden as the latter.

Here's how you define one:

ENV = envarg("ENV", default="dev", description="build environment")

Parameters explained:

  • name - unique name for the argument
  • default - default value if none is supplied (optional; None by default)
  • description - short description of what the argument is displayed in the help message (optional)
  • sensitive - indicates the value is sensitive and should be masked (optional)

The argument is evaluated right there (not inside of targets), so you can use that variable straightaway.

It can be set as a regular environment variable:

ENV=dev ./build.py sometarget

Alternatively, it can be passed as an argument:

./build.py sometarget --arg ENV=prod

Finally, you can pass .env file to load:

./build.py sometarget --dotenv /path/to/.env

If both are passed simultaneously, then argument takes precedence over the environment variable.

Examples

See examples for use cases that demonstrate the main features.

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

molot-1.0.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

molot-1.0.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file molot-1.0.0.tar.gz.

File metadata

  • Download URL: molot-1.0.0.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for molot-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f4d6eaa5f245d76bfe9309b17d460ef8f9d897a2288f0dcd71dfe6f4e21b9586
MD5 113920f617c77c110c12b641ebb391b1
BLAKE2b-256 2e143982096a7eb3d49623340d44b692dfdd36904c32f807db2f1a3c25e16311

See more details on using hashes here.

File details

Details for the file molot-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: molot-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for molot-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0da3148485e8f07ee89b4e29271f5908f997f4c7320739188494d9b3583afcb1
MD5 08c72c64aa0f4c34e462765a5175e8fa
BLAKE2b-256 2ae4c8787eb4848eae0f3c662057c1e08e616932a7c9f18f799a2178ff851d34

See more details on using hashes here.

Supported by

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