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

feat(sdk): improve docs + code clarity #12422

Merged
merged 5 commits into from
Jan 23, 2025
Merged
Changes from 1 commit
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
Next Next commit
improve source/sink api docs
hsheth2 committed Jan 21, 2025
commit c8d6d96d0bfdd9d7d1c7534d591336286b09204b
3 changes: 3 additions & 0 deletions metadata-ingestion/src/datahub/ingestion/api/decorators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import abc
from dataclasses import dataclass
from enum import Enum, auto
from typing import Callable, Dict, Optional, Type
@@ -25,6 +26,8 @@ def wrapper(cls: Type) -> Type:
# add the create method only if it has not been overridden from the base Source.create method
cls.create = classmethod(default_create)

abc.update_abstractmethods(cls)

return cls

return wrapper
12 changes: 12 additions & 0 deletions metadata-ingestion/src/datahub/ingestion/api/sink.py
Original file line number Diff line number Diff line change
@@ -110,16 +110,28 @@ def __init__(self, ctx: PipelineContext, config: SinkConfig):
self.__post_init__()

def __post_init__(self) -> None:
"""Hook called after the sink's main initialization is complete.
Sink subclasses can override this method to customize initialization.
"""
pass

@classmethod
def create(cls, config_dict: dict, ctx: PipelineContext) -> "Self":
return cls(ctx, cls.get_config_class().parse_obj(config_dict))

def handle_work_unit_start(self, workunit: WorkUnit) -> None:
"""Called at the start of each new workunit.
This method is deprecated and will be removed in a future release.
"""
pass

def handle_work_unit_end(self, workunit: WorkUnit) -> None:
"""Called at the end of each workunit.
This method is deprecated and will be removed in a future release.
"""
pass

@abstractmethod
9 changes: 2 additions & 7 deletions metadata-ingestion/src/datahub/ingestion/api/source.py
Original file line number Diff line number Diff line change
@@ -400,13 +400,8 @@ class Source(Closeable, metaclass=ABCMeta):
ctx: PipelineContext

@classmethod
def create(cls, config_dict: dict, ctx: PipelineContext) -> Self:
# Technically, this method should be abstract. However, the @config_class
# decorator automatically generates a create method at runtime if one is
# not defined. Python still treats the class as abstract because it thinks
# the create method is missing. To avoid the class becoming abstract, we
# can't make this method abstract.
raise NotImplementedError('sources must implement "create"')
@abstractmethod
def create(cls, config_dict: dict, ctx: PipelineContext) -> Self: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not a concern anymore because of the added abc.update_abstractmethods(cls) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup that's the idea. but abc.update_abstractmethods was only added in python 3.10, so I might need to revert this


def get_workunit_processors(self) -> List[Optional[MetadataWorkUnitProcessor]]:
"""A list of functions that transforms the workunits produced by this source.