Skip to content

Commit

Permalink
Sort recipe in DGL-Go (#3781)
Browse files Browse the repository at this point in the history
* add

* remove

* fix

* rework the readme and some changes

* add png

* update png

* add recipe get

* sort recipe list and remove copy

* fix

Co-authored-by: Minjie Wang <[email protected]>
Co-authored-by: Quan (Andy) Gan <[email protected]>
  • Loading branch information
3 people authored Feb 28, 2022
1 parent 869991d commit 7ab1034
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions dglgo/dglgo/cli/recipe_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,20 @@ def list_recipes():
typer.echo("="*len(header))
typer.echo(header)
typer.echo("="*len(header))
output_list = []
for file in file_list:
cfg = yaml.safe_load(Path(file).open("r"))
typer.echo("| {:<30} | {:<18} | {:<20} |".format(file.name, cfg["pipeline_name"], cfg["data"]["name"]))
output_list.append({
"file_name": file.name,
"pipeline_name": cfg["pipeline_name"],
"dataset_name": cfg["data"]["name"]
})
# sort by pipeline, if same sort by dataset, if same sort by file name
output_list.sort(key=lambda f: (f["pipeline_name"], f["dataset_name"], f["file_name"]))
for f in output_list:
typer.echo("| {:<30} | {:<18} | {:<20} |".format(f["file_name"], f["pipeline_name"], f["dataset_name"]))
typer.echo("="*len(header))

def copy_recipes(dir: str = typer.Option("dglgo_example_recipes", help="directory name for recipes")):
file_current_dir = Path(__file__).resolve().parent
recipe_dir = file_current_dir.parent.parent / "recipes"
current_dir = Path(os.getcwd())
new_dir = current_dir / dir
new_dir.mkdir(parents=True, exist_ok=True)
for file in recipe_dir.glob("*.yaml"):
shutil.copy(file, new_dir)
print("Example recipes are copied to {}".format(new_dir.absolute()))

def get_recipe(recipe_name: Optional[str] = typer.Argument(None, help="The recipe filename to get, e.q. nodepred_citeseer_gcn.yaml")):
if recipe_name is None:
typer.echo("Usage: dgl recipe get [RECIPE_NAME] \n")
Expand All @@ -47,7 +46,6 @@ def get_recipe(recipe_name: Optional[str] = typer.Argument(None, help="The recip

recipe_app = typer.Typer(help="Get example recipes")
recipe_app.command(name="list", help="List all available example recipes")(list_recipes)
recipe_app.command(name="copy", help="Copy all available example recipes to current directory")(copy_recipes)
recipe_app.command(name="get", help="Copy the recipe to current directory")(get_recipe)

if __name__ == "__main__":
Expand Down

0 comments on commit 7ab1034

Please sign in to comment.