-
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: Isabella do Amaral <[email protected]>
- Loading branch information
Showing
2 changed files
with
71 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import collections.abc as c | ||
from itertools import islice | ||
from pathlib import Path | ||
from sys import argv | ||
from textwrap import dedent | ||
|
||
|
||
def get_funcs(models: c.Iterable[Path]) -> c.Iterator[str]: | ||
for path in models: | ||
with path.open() as f: | ||
buf = [] | ||
in_func = False | ||
# skip first 14 lines of boilerplate | ||
for raw in islice(f.readlines(), 14, None): | ||
line = raw.rstrip() | ||
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__": | ||
if len(argv) > 1: | ||
root = Path(argv[1]) | ||
assert root.is_dir(), f"{root} is not a directory" | ||
else: | ||
# 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