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: Make backend discoverable TCTC-3456 #1441

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

lukapeschke
Copy link
Contributor

TCTC-3456

Signed-off-by: Luka Peschke luka.peschke@toucantoco.com

@render
Copy link

render bot commented Jul 29, 2022

Signed-off-by: Luka Peschke <luka.peschke@toucantoco.com>
TCTC-3456

Signed-off-by: Luka Peschke <luka.peschke@toucantoco.com>
@lukapeschke lukapeschke marked this pull request as ready for review August 1, 2022 13:57
@lukapeschke lukapeschke added need review pypika Changes concern the PyPika translator python Pull requests that update Python code proposal and removed 🔨 wip 🔨 ✋ DO NOT REVIEW ✋ labels Aug 1, 2022
Copy link
Member

@davinov davinov left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, it's a very interesting for the architecture of the weaverbird's python module!

Your approach is nice and pragamatic, additive-only. The added features such as the minimum version are useful touches 👍
Yet I feel we kinda already have the same sort of information in the files where we import all steps in each backend that the one you put in the registry. Maybe we can think of something that would use it?
This would be to avoid an unfortunate state when we forget either the decorator or the import in the backend main method.
But this would probably mean reconsidering also how we write backends, maybe with an abstract base for all of them? Happy to discuss alternatives if you feel like it. Otherwise, it could also be a nice first version (if so, we need to update the documentation about how to add a step)

Comment on lines +100 to +102
signature = inspect.signature(fn)
if 'step' in signature.parameters:
return cls._get_step_model(signature.parameters['step'].annotation)
Copy link
Member

Choose a reason for hiding this comment

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

Wow nice use of the inspect module 👍


def register(*args, **kwargs) -> Callable:
called_with_kwargs = bool(kwargs)
step_name = kwargs.pop('step_name', None) or args[0].__name__.replace('translate_', '')
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to add an enum and use everytime an explicit @register(step_name=...) instead of the magic translate_....
We spend way more time reading and refactoring than writing new code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need review proposal pypika Changes concern the PyPika translator python Pull requests that update Python code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants