pontos.github.script package

Load and run Pontos GitHub Scripts

A Pontos GitHub Script is a Python module that has a github_script coroutine function and optionally a add_script_arguments function. These functions should have the following signatures:

async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int:

def add_script_arguments(parser: ArgumentParser) -> None:

Example:

Example Python module containing a Pontos GitHub Script
def add_script_arguments(parser: ArgumentParser) -> None:
    parser.add_argument("repository")

async def github_script(api: GitHubAsyncRESTApi, args: Namespace) -> int:
    repo = await api.repositories.get(args.repository)
    print(repo.html_url, repo.description)
    return 0
exception pontos.github.script.GitHubScriptError

An error with a GitHub script

pontos.github.script.load_script(script)

A context manager to load a script module.

The script is unloaded when the context manager exits.

Parameters:

script (str | PathLike) – Name or path of the script module to load

Return type:

Generator[module, None, None]

Example

from pontos.github.script import load_script

with load_script("path/to/script.py") as module:
    module.func()

with load_script("some.python.module") as module:
    module.func()
pontos.github.script.run_add_arguments_function(module, parser)

Run a GitHub script add_script_arguments function (if available in the module).

Parameters:
  • module (module) – Module containing the GitHub script add_script_arguments function

  • parser (ArgumentParser) – An ArgumentParser to add additional CLI arguments

Example

from argparse import ArgumentParser
from pontos.github.script import (
    load_script,
    run_github_script_function,
)

parser = ArgumentParser()

with load_script("path/to/script.py") as module:
    run_add_arguments_function(module, parser)

with load_script("some.python.module") as module:
    run_add_arguments_function(module, parser)
pontos.github.script.run_github_script_function(module, token, timeout, args)

Run a github_script function from a Python module

Parameters:
  • module (module) – Module that the GitHub script function contains

  • token (str) – A GitHub token for authentication

  • timeout (float) – Timeout for the GitHub requests in seconds

  • args (Namespace) – Arguments forwarded to the script function

Raises:

GitHubScriptError – If the module doesn’t have a github_script function or if the github_script function is not an async coroutine.

Returns:

The return value of the github_script coroutine

Return type:

int

Example

from pontos.github.script import (
    load_script,
    run_github_script_function,
)

with load_script("path/to/script.py") as module:
    return run_github_script_function(module, token, 60.0, args)

with load_script("some.python.module") as module:
    return run_github_script_function(module, token, 60.0, args)