-
Notifications
You must be signed in to change notification settings - Fork 4
Support for Model output endpoint me.org #332
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
Changes from 1 commit
0b6e138
334e729
56b399c
52d2349
f411043
5305362
69c2f2a
11a5174
87dd853
fcf3a2c
b101645
b344ca3
57d53dc
45e1456
726d4e9
fc4c18b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |||||||||||||||||||||||||||||||||
| from benchcab import internal | ||||||||||||||||||||||||||||||||||
| from benchcab.utils.repo import create_repo | ||||||||||||||||||||||||||||||||||
| from benchcab.model import Model | ||||||||||||||||||||||||||||||||||
| from typing import Optional | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| class ConfigValidationError(Exception): | ||||||||||||||||||||||||||||||||||
|
|
@@ -85,7 +86,7 @@ def read_optional_key(config: dict): | |||||||||||||||||||||||||||||||||
| Parameters | ||||||||||||||||||||||||||||||||||
| ---------- | ||||||||||||||||||||||||||||||||||
| config : dict | ||||||||||||||||||||||||||||||||||
| The configuration file with without optional keys | ||||||||||||||||||||||||||||||||||
| The configuration file with, or without optional keys | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| if "project" not in config: | ||||||||||||||||||||||||||||||||||
|
|
@@ -128,13 +129,47 @@ def read_optional_key(config: dict): | |||||||||||||||||||||||||||||||||
| return config | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def is_valid_model_output_name(name: str) -> Optional[str]: | ||||||||||||||||||||||||||||||||||
| """Validate model output name against github issue standards. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Standard: <digit>-<words-sep-by-dashes> | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Parameters | ||||||||||||||||||||||||||||||||||
| ---------- | ||||||||||||||||||||||||||||||||||
| name: str | ||||||||||||||||||||||||||||||||||
| The model output name | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Returns | ||||||||||||||||||||||||||||||||||
| ------- | ||||||||||||||||||||||||||||||||||
| Optional[str] | ||||||||||||||||||||||||||||||||||
| If model output name does not meet standard, then return error message | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||
| if len(name) == 0: | ||||||||||||||||||||||||||||||||||
| return "Model output name is empty" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if len(name) > 255: | ||||||||||||||||||||||||||||||||||
| return "Model output name has length more than allowed limit on me.org (255)" | ||||||||||||||||||||||||||||||||||
abhaasgoyal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if " " in name: | ||||||||||||||||||||||||||||||||||
| return "Model output name cannot have spaces" | ||||||||||||||||||||||||||||||||||
abhaasgoyal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| name_keywords = name.split("-") | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if not name_keywords[0].isdigit(): | ||||||||||||||||||||||||||||||||||
| return "Model output name does not start with number" | ||||||||||||||||||||||||||||||||||
abhaasgoyal marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if len(name_keywords) == 1: | ||||||||||||||||||||||||||||||||||
| return "Model output name does not contain keyword after number" | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| return "Model output name does not contain keyword after number" | |
| return "Model output name must contain keywords after the initial number. E.g. 123-fixing-met-file-reading-error" |
I also wonder if we want to build an error message that indicates all the mistakes in a given name at once, instead of returning on the first error encountered. Something like the following (incomplete and not formatted for the code):
msg=""
if len(name) == 0:
msg+="Model output name can not be empty.\n"
if len(name) > 255:
msg+="The length of model output name must be shorter than 255 characters.\n"
if msg:
msg+="Example valid name: 123-fixing-met-file-reading-error"
return msgActually, the check on len(name)==0 indicates a problem with the code itself rather than the config I suspect so it might be weird to give a valid name example but I think it's a small inconvenience.
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.
For the check on len(name)==0, I'm trying to treat the function as independent entity from the code (so if the code does have issues in the future, then it would be caught more easily). Let me know if this check is still not needed.
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.
I would revert to the previous implementation but using the name argument in create_repo()
| mo_name = None | |
| if r.get("name"): | |
| mo_name = r["name"] | |
| else: | |
| repo = create_repo( | |
| spec=r["repo"], | |
| path=internal.SRC_DIR / (r["name"] if r.get("name") else Path()), | |
| ) | |
| mo_name = Model(repo).name | |
| mo_name = None | |
| repo = create_repo( | |
| spec=r["repo"], | |
| path=internal.SRC_DIR / (r["name"] if r.get("name") else Path()), | |
| name=r.get("name"), | |
| ) | |
| mo_name = Model(repo).name |
The implementation of Model().__init__() should assign to Model(repo).name:
- the branch name if
nameis not present in the config - the value of
nameif it's present.
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.
To resolve this, I am using r.get("name") both in Repo and Model initialisations since Model cannot determine the name just from Repo (unless it has a mandatory name parameter, which it doesn't for all the sub classes - for example LocalRepo has name but GitRepo doesn't)
repo = create_repo(
spec=r["repo"],
path=internal.SRC_DIR / (r["name"] if r.get("name") else Path()),
)
mo_name = Model(repo, name=r.get("name")).nameFor now, I'm not making it mandatory for Repo to have a name parameter (so usage of r.get("name") twice is fine.
SeanBryan51 marked this conversation as resolved.
Show resolved
Hide resolved
abhaasgoyal marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.