Skip to content

Commit

Permalink
Merge pull request #47 from cloudblue/transformation_extensions
Browse files Browse the repository at this point in the history
Add transformation extensions
  • Loading branch information
ffaraone authored Nov 4, 2022
2 parents d19b0ee + cf83a5a commit 59029dc
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 8 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand All @@ -37,11 +37,11 @@ jobs:
needs: [test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python 3.10
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
Expand All @@ -25,7 +25,7 @@ jobs:
run: |
poetry run pytest
- name: Extract tag name
uses: actions/github-script@v3
uses: actions/github-script@v6
id: tag
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions connect/eaas/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
ACCOUNT_SETTINGS_PAGE_ATTR_NAME = '_eaas_account_settings_page'
MODULE_PAGES_ATTR_NAME = '_eaas_module_pages'
ADMIN_PAGES_ATTR_NAME = '_eaas_admin_pages'
TRANSFORMATION_ATTR_NAME = '_eaas_transformation_info'
13 changes: 13 additions & 0 deletions connect/eaas/core/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
GUEST_ENDPOINT_ATTR_NAME,
MODULE_PAGES_ATTR_NAME,
SCHEDULABLE_INFO_ATTR_NAME,
TRANSFORMATION_ATTR_NAME,
VARIABLES_INFO_ATTR_NAME,
)

Expand Down Expand Up @@ -121,5 +122,17 @@ def wrapper(cls):
return wrapper


def transformation(name, description, edit_dialog_ui):
def wrapper(cls):
setattr(cls, TRANSFORMATION_ATTR_NAME, {
'name': name,
'description': description,
'edit_dialog_ui': edit_dialog_ui,
'class_fqn': f'{cls.__module__}.{cls.__name__}',
})
return cls
return wrapper


router = InferringRouter()
web_app = cbv
35 changes: 35 additions & 0 deletions connect/eaas/core/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
GUEST_ENDPOINT_ATTR_NAME,
MODULE_PAGES_ATTR_NAME,
SCHEDULABLE_INFO_ATTR_NAME,
TRANSFORMATION_ATTR_NAME,
VARIABLES_INFO_ATTR_NAME,
)
from connect.eaas.core.decorators import router
Expand Down Expand Up @@ -149,3 +150,37 @@ def setup_anvil_callables(self):
fn = functools.partial(_invoke, value)
fn.__name__ = value.__name__
anvil.server.callable(fn)


class TransformationBase:

def __init__(
self,
input_columns,
output_columns,
stream,
client,
config,
logger,
transformation_settings=None,
installation_client=None,
installation=None,
cache=None,
):
self.client = client
self.config = config
self.logger = logger

self.installation_client = installation_client
self.installation = installation

self.input_columns = input_columns
self.output_columns = output_columns
self.stream = stream

self.transformation_settings = transformation_settings
self.cache = cache

@classmethod
def get_transformation_info(cls):
return getattr(cls, TRANSFORMATION_ATTR_NAME, None)
8 changes: 8 additions & 0 deletions connect/eaas/core/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ class Schedulable(BaseModel):
description: str


class Transformation(BaseModel):
class_fqn: str
name: str
description: str
edit_dialog_ui: str


class Repository(BaseModel):
readme_url: Optional[str]
changelog_url: Optional[str]
Expand All @@ -154,6 +161,7 @@ class SetupRequest(BaseModel):
variables: Optional[list]
schedulables: Optional[List[Schedulable]]
anvil_callables: Optional[list]
transformations: Optional[List[Transformation]]
audience: Optional[List[Literal['vendor', 'distributor', 'reseller']]]
repository: Optional[Repository]
runner_version: Optional[str]
Expand Down
28 changes: 28 additions & 0 deletions tests/connect/eaas/core/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
guest,
module_pages,
schedulable,
transformation,
variables,
web_app,
)
from connect.eaas.core.extension import (
_invoke,
AnvilApplicationBase,
EventsApplicationBase,
TransformationBase,
WebApplicationBase,
)

Expand Down Expand Up @@ -483,3 +485,29 @@ def test_guest(self):
},
'admins': [{'label': 'Admin page', 'url': '/static/admin.html'}],
}


def test_get_transformation_info():

@transformation(
name='my transformation',
description='The my transformation',
edit_dialog_ui='/static/my_settings.html',
)
class MyExtension(TransformationBase):
pass

ext = MyExtension(
input_columns=['one', 'two'],
output_columns=['one_dot', 'two_dot'],
stream={},
client=None,
config=None,
logger=None,
)

transformations = ext.get_transformation_info()
assert transformations['name'] == 'my transformation'
assert transformations['description'] == 'The my transformation'
assert transformations['edit_dialog_ui'] == '/static/my_settings.html'
assert 'MyExtension' in transformations['class_fqn']
10 changes: 10 additions & 0 deletions tests/connect/eaas/core/test_proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Task,
TaskInput,
TaskOptions,
Transformation,
WebTaskOptions,
)

Expand Down Expand Up @@ -122,6 +123,12 @@
'anvil_callables': [
{'method': 'method_name', 'summary': 'Summary', 'description': 'Description'},
],
'transformations': [{
'name': 'Name',
'description': 'Description',
'edit_dialog_ui': '/static/edit.html',
'class_fqn': 'package.ABC',
}],
'repository': {
'readme_url': 'https://read.me',
'changelog_url': 'https://change.log',
Expand Down Expand Up @@ -252,6 +259,8 @@ def test_deserialize_setup_request_message_with_vars_and_schedulables():
assert isinstance(message.data.schedulables[0], Schedulable)
assert message.data.variables[0]['foo'] == msg_data['data']['variables'][0]['foo']
assert message.data.variables[0]['bar'] == msg_data['data']['variables'][0]['bar']
assert message.data.transformations == msg_data['data']['transformations']
assert isinstance(message.data.transformations[0], Transformation)


def test_deserialize_v1_shutdown():
Expand Down Expand Up @@ -315,6 +324,7 @@ def test_deserialize_v1_setup_request_data():

expected_data = copy.deepcopy(SETUP_REQUEST_DATA)
expected_data['anvil_callables'] = None
expected_data['transformations'] = None

assert isinstance(message, Message)
assert message.version == 1
Expand Down

0 comments on commit 59029dc

Please sign in to comment.