-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matteo Mortari <[email protected]> Co-authored-by: Matteo Mortari <[email protected]> Signed-off-by: Isabella do Amaral <[email protected]>
- Loading branch information
Showing
3 changed files
with
72 additions
and
73 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import typing as t | ||
from pathlib import Path | ||
from textwrap import dedent | ||
|
||
|
||
def get_funcs(models: t.Iterable[Path]) -> t.Iterator[str]: | ||
for path in models: | ||
with path.open() as f: | ||
# skip boilerplate | ||
lines = iter(f.readlines()) | ||
while not next(lines).startswith("package"): | ||
continue | ||
|
||
buf = [] | ||
in_func = False | ||
for raw in lines: | ||
line = raw.rstrip() | ||
if not line and not in_func: | ||
continue | ||
buf.append(line) | ||
if line.startswith("func"): | ||
in_func = True | ||
elif line.startswith("}") and in_func: | ||
in_func = False | ||
yield "\n".join(buf) | ||
buf.clear() | ||
path.unlink() | ||
|
||
|
||
def get_name(func: str) -> str: | ||
# each func is declared as: | ||
# // comment | ||
# func funcName(args) error ... | ||
return func.split("\n")[1].split(" ")[1].split("(")[0] | ||
|
||
|
||
if __name__ == "__main__": | ||
# model registry repo root | ||
root = Path(__file__).parent.parent.resolve() | ||
src = root / "internal/server/openapi" | ||
print( | ||
dedent(""" | ||
/* | ||
* Model Registry REST API | ||
* | ||
* REST API for Model Registry to create and manage ML model metadata | ||
* | ||
* API version: 1.0.0 | ||
* Generated by: OpenAPI Generator (https://openapi-generator.tech) | ||
* | ||
*/ | ||
// File generated by scripts/gen_type_assert.sh - DO NOT EDIT | ||
package openapi | ||
import ( | ||
model "github.com/kubeflow/model-registry/pkg/openapi" | ||
) | ||
""") | ||
) | ||
print( | ||
"\n".join( | ||
sorted( | ||
get_funcs(path for path in src.rglob("model_*.go")), | ||
key=lambda f: get_name(f), | ||
) | ||
) | ||
) |
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