-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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
- 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
- Define a export_slc context manager which you can use to export the SLC as tar.gz
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
Step 4: If you want to have a python function to deploy the container to the DB, add a subclass of LanguageContainerDeployer
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.