Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Experiment] extending features with addition pip package #2168

Draft
wants to merge 3 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions dlt/feature/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try:
from dlt_example_plugin.feature import SupportsExtendedFeature as SupportsFeature
from dlt_example_plugin.feature import ExtendedFeature as Feature
except ImportError:
from dlt.feature.reference import SupportsSimpleFeature as SupportsFeature
from dlt.feature.impl import SimpleFeature as Feature


def get_feature() -> SupportsFeature:
return Feature()
6 changes: 6 additions & 0 deletions dlt/feature/impl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from dlt.feature.reference import SupportsSimpleFeature


class SimpleFeature(SupportsSimpleFeature):
def calculate(self, a: int, b: int) -> int:
return a + b
5 changes: 5 additions & 0 deletions dlt/feature/reference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from typing import Protocol


class SupportsSimpleFeature(Protocol):
def calculate(self, a: int, b: int) -> int: ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing import TYPE_CHECKING

from dlt.feature.impl import SimpleFeature
from dlt.feature.reference import SupportsSimpleFeature


# extend interface
class SupportsExtendedFeature(SupportsSimpleFeature):
# add new method
def more_calculation(self, a: int, b: int) -> int: ...


# extend implementation
class ExtendedFeature(SupportsExtendedFeature, SimpleFeature):
# override a method
def calculate(self, a: int, b: int) -> int:
return a * b

# add a new method
def more_calculation(self, a: int, b: int) -> int:
return a**b
13 changes: 12 additions & 1 deletion tests/plugins/test_plugin_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def plugin_install():
sys.path.remove(temp_dir)
shutil.rmtree(temp_dir)
importlib.reload(importlib.metadata)
del container[plugins.PluginContext]
if plugins.PluginContext in container:
del container[plugins.PluginContext]




def test_example_plugin() -> None:
Expand Down Expand Up @@ -83,3 +86,11 @@ def test_cli_hook(script_runner: ScriptRunner) -> None:
assert result.returncode == -55
assert "Plugin overwrote init command" in result.stdout
assert "INIT_DOCS_URL" in result.stdout


def test_extended_feature():
from dlt.feature import get_feature

feature = get_feature()
assert feature.calculate(3, 3) == 9
assert feature.more_calculation(3, 3) == 27
5 changes: 5 additions & 0 deletions tests/plugins/test_simple_feature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def test_simple_feature():
from dlt.feature import get_feature

feature = get_feature()
assert feature.calculate(3, 3) == 6
Loading