Skip to content

Commit

Permalink
Integrating cookiecutter with MLCube CLI. (#211)
Browse files Browse the repository at this point in the history
Now, instead of running `cookiecutter https://github.com/mlcommons/mlcube_cookiecutter.git` users can run `mlcube create`. The cookiecutter library has not become a project dependency. If it is not installed, the MLCube will print out a message saying this library is not available.
  • Loading branch information
sergey-serebryakov authored Oct 1, 2021
1 parent 49e73ce commit 64ad2db
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion mlcube/mlcube/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
import os
import sys

import click
import logging
import coloredlogs
Expand All @@ -14,6 +13,7 @@
from mlcube.parser import (CliParser, MLCubeDirectory)
from mlcube.platform import Platform
from mlcube.runner import Runner
from mlcube.shell import Shell
from mlcube.system_settings import SystemSettings
from mlcube.validate import Validate

Expand Down Expand Up @@ -271,5 +271,24 @@ def _check_tuple(_tuple: t.Tuple, _name: t.Text, _expected_size: int, _expected_
logger.error("Command failed, command = '%s' error = '%s'", ' '.join(sys.argv), str(e))


@cli.command(name='create',
help='Create a new MLCube using cookiecutter.')
def create() -> None:
""" Create a new MLCube using cookiecutter template.
- MLCube cookiecutter: https://github.com/mlcommons/mlcube_cookiecutter
- Example: https://mlcommons.github.io/mlcube/tutorials/create-mlcube/
"""
mlcube_cookiecutter_url = 'https://github.com/mlcommons/mlcube_cookiecutter'
try:
from cookiecutter.main import cookiecutter
proj_dir: t.Text = cookiecutter(mlcube_cookiecutter_url)
if proj_dir and os.path.isfile(os.path.join(proj_dir, 'mlcube.yaml')):
Shell.run('mlcube', 'describe', '--mlcube', proj_dir)
except ImportError:
print("Cookiecutter library not found.")
print("\tInstall it: pip install cookiecutter")
print(f"\tMore details: {mlcube_cookiecutter_url}")


if __name__ == "__main__":
cli()

0 comments on commit 64ad2db

Please sign in to comment.