-
Notifications
You must be signed in to change notification settings - Fork 52
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
Refactor: factorise plugins app implementation #1166
Refactor: factorise plugins app implementation #1166
Conversation
@@ -55,7 +64,7 @@ def _mask_password(connection_params: dict): | |||
return connection_params | |||
|
|||
|
|||
@app.command(name="list") | |||
@app_creator.command(name="list") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using app
will reduce a lot of changes, I don't think we need to to the rename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
class ConnectionAppCreator(SnowTyperCreator): | ||
def create_app(self) -> SnowTyper: | ||
app = SnowTyper( | ||
name="connection", | ||
help="Manages connections to Snowflake.", | ||
) | ||
self.register_commands(app) | ||
return app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we simplify it to something like
app: SnowTyperCreator = SnowTyperCreator.create_app(SnowTyper(
name="connection",
help="Manages connections to Snowflake.",
))
do we really need a custom class for every command group?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could pass **kwargs
from create_app
to the constructor, but then I'd have to modify add_init_command
-like procedures to work with SnowTyperCreator
- I will check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed as discussed
def __init__(self): | ||
self.commands_to_register: List[SnowTyperCommandData] = [] | ||
|
||
def create_app(self) -> SnowTyper: | ||
""" | ||
Returns SnowTyper instance. | ||
""" | ||
raise NotImplementedError() | ||
|
||
def command(self, *args, **kwargs): | ||
def decorator(command): | ||
self.commands_to_register.append( | ||
SnowTyperCommandData(command, args=args, kwargs=kwargs) | ||
) | ||
return command | ||
|
||
return decorator | ||
|
||
def register_commands(self, app: SnowTyper) -> None: | ||
for command in self.commands_to_register: | ||
app.command(*command.args, **command.kwargs)(command.func) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we cannot add this logic to SnowTyper
? What's reasoning behind adding this additional layer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to postpone calling __init__
until error handling would be set up. The problem behind the issue was calling feature flags (which read config.toml) to determine constructor arguments (hidden=FeatureFlag.is_disabled
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed as discussed
kwargs: Dict[str, Any] | ||
|
||
|
||
class SnowTyper: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we name it SnowTyperFactory
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed:
SnowTyper
-> SnowTyperFactory
SnowTyperInstance
-> SnowTyper
.create_app()
-> .create_instance()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- src/snowflake/cli/plugins/nativeapp/version/commands.py also needs these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is already changed :)
) | ||
|
||
app.add_typer(stage_app) # type: ignore | ||
app.add_typer(show_app) # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made it consistent with other plugins (spcs / NADE), but I made the choice between __init__.py
and commands.py
arbitrarily - no strong opinion
╰──────────────────────────────────────────────────────────────────────────────╯ | ||
|
||
''' | ||
# --- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm from NADE
f1027e8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, acking the rebase.
Pre-review checklist
Changes description
Refactor: change SnowTyper into Typer instance fanctory.
Only developer-facing change: we need to call
SnowTyper.create_app()
to get an actual Typer instance.The motivation behind the change is an issue #813, which was caused by reading
config.toml
before error handling was set up