-
Notifications
You must be signed in to change notification settings - Fork 10
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
Added Collection functionality to run cli cmd as collection #113
Closed
Closed
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ class Command: | |
description: str | ||
fn: Callable[..., None] | ||
is_account: bool = False | ||
is_collection: bool = False | ||
is_unauthenticated: bool = False | ||
|
||
def needs_workspace_client(self): | ||
|
@@ -30,6 +31,15 @@ def needs_workspace_client(self): | |
return False | ||
return True | ||
|
||
def run_as_collection(self) -> bool: | ||
if not self.is_collection: | ||
return False | ||
sig = inspect.signature(self.fn) | ||
for param in sig.parameters.values(): | ||
if param.name == "collection_workspace_id": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we implement this on UCX only, for now? |
||
return True | ||
return False | ||
|
||
def prompts_argument_name(self) -> str | None: | ||
sig = inspect.signature(self.fn) | ||
for param in sig.parameters.values(): | ||
|
@@ -53,7 +63,7 @@ def __init__(self, __file: str): | |
self._logger = get_logger(__file) | ||
self._product_info = ProductInfo(__file) | ||
|
||
def command(self, fn=None, is_account: bool = False, is_unauthenticated: bool = False): | ||
def command(self, fn=None, is_account: bool = False, is_unauthenticated: bool = False, is_collection=False): | ||
"""Decorator to register a function as a command.""" | ||
|
||
def register(func): | ||
|
@@ -66,6 +76,7 @@ def register(func): | |
fn=func, | ||
is_account=is_account, | ||
is_unauthenticated=is_unauthenticated, | ||
is_collection=is_collection, | ||
) | ||
return func | ||
|
||
|
@@ -99,9 +110,9 @@ def _route(self, raw): | |
case "float": | ||
kwargs[kwarg] = float(kwargs[kwarg]) | ||
try: | ||
if cmd.needs_workspace_client(): | ||
if cmd.needs_workspace_client() and not cmd.run_as_collection(): | ||
kwargs["w"] = self._workspace_client() | ||
elif cmd.is_account: | ||
elif cmd.is_account or cmd.run_as_collection(): | ||
kwargs["a"] = self._account_client() | ||
prompts_argument = cmd.prompts_argument_name() | ||
if prompts_argument: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
could you add a comment explaining how this would work, i.e. the command should have
is_collection
annotation &collection_workspace_id
is not nullThere 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.
also, our function would always receive
collection_workspace_id
, the difference is that it might be null instead of an integer right?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.
This is my understanding. We mark a method as collection eligible by setting is_collection as True.
Now there are two ways to execute it , if the collection_workspace_id is passed, then create account context and iterate through all workspace context of the collection and run the associated command once for each workspace if collection_workspace_id is not passed, then run it as current installation cmd.
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.
added comments