-
Notifications
You must be signed in to change notification settings - Fork 157
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: add OptionalType
click parameter type
#1406
Conversation
JinMyeong Kim seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
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.
Thanks for your commitment!
I left some reviews
changes/1393.feature.md
Outdated
|
||
|
||
|
||
|
||
|
||
|
||
|
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.
Please remove this blank new lines.
And we write news fragment in one line. Please refer other merged PR's news fragment files.
Fragment files are listed in the release notes and read by users. Please note that!
async with root_ctx.db.begin() as conn: | ||
user_uuid, group_id, _ = await query_userinfo(request, params, conn) | ||
log.debug("Params: {0}", params) | ||
try: | ||
body = json.loads(params["payload"]) | ||
except json.JSONDecodeError: | ||
try: | ||
body = yaml.safe_load(params["payload"]) | ||
body = yaml.safe_load_all(params["payload"]) |
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/ai/backend/client/cli/params.py
Outdated
def convert(self, value, param, ctx): | ||
try: | ||
if isinstance(value, (str, int)) or value == undefined: | ||
return value | ||
except ValueError as e: | ||
self.fail(repr(e), param, ctx) |
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.
def convert(self, value, param, ctx): | |
try: | |
if isinstance(value, (str, int)) or value == undefined: | |
return value | |
except ValueError as e: | |
self.fail(repr(e), param, ctx) | |
def __init__(self, type_: type) -> None: | |
super().__init__() | |
self.type_ = type_ | |
def convert(self, value: Any, param, ctx): | |
if isinstance(value, self.type_) or value is undefined: | |
return value | |
self.fail(f"{value!r} is not valid `{self.type_}` or `undefined`", param, ctx) |
Let OptionalType
handle not only str
and int
types, but also Any given type.
And it is good to pass detail failure messages.
Then, OptionalType
can be used like below
# example
@click.option("--name", type=OptionalType(str), default=undefined, help="Example option.")
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 would be nice to embed an example |
@fregataa Okay! |
tx.AliasedKey(["image", "lang"], default=undefined): UndefChecker | t.Null | t.String, | ||
tx.AliasedKey(["arch", "architecture"], default=DEFAULT_IMAGE_ARCH) | ||
>> "architecture": t.String, | ||
tx.AliasedKey(["type", "sessionType"], default="interactive") | ||
>> "session_type": tx.Enum(SessionTypes), |
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.
When a default value is set in here, the configuration value of the template gets overwritten by this default value.
@@ -538,7 +550,8 @@ def _create_from_template_cmd(docs: str = None): | |||
"-g", | |||
"--group", | |||
metavar="GROUP_NAME", | |||
default=None, |
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.
If a None
value is passed, the group
value gets overwritten with None
, leading to an error.
collected an error log [ERROR] "ai.backend.manager.api.exceptions.InvalidAPIParameters: Missing or invalid API parameters. (Invalid group)" from manager
OptionalType
class to handle undefined
value at cli argumentOptionalType
click parameter type
OptionalType
click parameter typeOptionalType
click parameter type
This PR resolves #1393 , and includes minor fixes to execute follow commands:
./backend.ai sesstpl create -f {template_filepath}
./backend.ai session create-from-template {template_id}
Implement
OptionalType
classOptionalType
serves as a type wrapper that checks forundefined
types.Revise to support for YAML format files and enable the creation of multiple templates.
for
loop when importing YAML file, thesafe_load
function should be replaced with thesafe_load_all
function.example_session_template.json
example_session_template.yaml
In
src/ai/backend/client/func/session_template.py
, I modifedcls()
argument to return the log with multipletemplate_id
like this:Minor fixes
ai/backend/manager/utils.py
before ai/backend/manager/api/session.py
callback_url
insrc/ai/backend/client/func/session.py
ai/backend/client/cli/session.py
before ai/backend/client/func/session.py