Skip to content

Provide a step-by-step guide, how to develop a python extension #89

@tkilias

Description

@tkilias

Provide a step-by-step guide, how to develop a python extension

Draft:

Step 1: Define and Build the Language Container using a Poetry Project
see: https://github.com/exasol/transformers-extension/blob/main/exasol_transformers_extension/deployment/language_container.py

  1. Define a language_container_factory context manager
@contextmanager
def language_container_factory():
with LanguageContainerBuilder(CONTAINER_NAME) as container_builder:
    project_directory = find_path_backwards("pyproject.toml", __file__).parent
    container_builder.prepare_flavor(project_directory)
    yield container_builder

  1. Define a export_slc context manager which you can use to export the SLC as tar.gz

see https://github.com/exasol/transformers-extension/blob/cd6c6bfde2bf58d2d02d95589ec65e925cf0414a/exasol_transformers_extension/deployment/language_container.py#L32

Step 2: Using the slc factory context manager with pytest-slc

In the readme of the pytest-slc project we have an example, which explains it
https://github.com/exasol/pytest-plugins/tree/main/pytest-slc

but for short, you have to implement two fixtures

@pytest.fixture(scope='session')
def language_alias():
    return "MY_LANGUAGE_ALIAS"

@pytest.fixture(scope='session')
def slc_builder(use_onprem, use_saas):
    if use_onprem or use_saas:
        with language_container_factory() as container_builder:
            yield container_builder
    else:
        yield None

and then you can use the slc in your test with

def test_something_with_slc(deployed_slc):
    ...

deployed_slc returns the language alias which you need to use to create your script with.

Step 3: If you are using nox as task runner in your project, add a nox task to export the slc using the context manager

see https://github.com/exasol/transformers-extension/blob/cd6c6bfde2bf58d2d02d95589ec65e925cf0414a/noxfile.py#L21

Step 4: If you want to have a python function to deploy the container to the DB, add a subclass of LanguageContainerDeployer

see https://github.com/exasol/transformers-extension/blob/main/exasol_transformers_extension/deployment/te_language_container_deployer.py

In TeLanguageContainerDeployer, we download the the SLC from the Github Releases with download_from_github_and_run, but is specific to how we release extensions,. With the run method, you can also deploy a local file.

Step 5: If you want to have python cli to deploy the SLC in the DB, you can take the following as inspiration

https://github.com/exasol/transformers-extension/blob/main/exasol_transformers_extension/deploy.py

About the usage of the CLI for the SLC deployment you can find more information on the following page:
https://github.com/exasol/python-extension-common/blob/main/doc/user_guide/user-guide.md#language-container-deployer

Some explanation around:


ver_formatter = ParameterFormatters()
ver_formatter.set_formatter(CONTAINER_URL_ARG, TeLanguageContainerDeployer.SLC_URL_FORMATTER)
ver_formatter.set_formatter(CONTAINER_NAME_ARG, TeLanguageContainerDeployer.SLC_NAME)
formatters = {StdParams.version: ver_formatter}

The SLC deployment CLI can download the Container for a specific version from a URL, if the option --version is provided, otherwise the --container-file needs to be provided. As I wrote, we are using this for downloading the SLC from GitHub releases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationUser guides, tutorials, specifications

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions