Skip to content

Commit 64ad2db

Browse files
Integrating cookiecutter with MLCube CLI. (#211)
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.
1 parent 49e73ce commit 64ad2db

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

mlcube/mlcube/__main__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44
import os
55
import sys
6-
76
import click
87
import logging
98
import coloredlogs
@@ -14,6 +13,7 @@
1413
from mlcube.parser import (CliParser, MLCubeDirectory)
1514
from mlcube.platform import Platform
1615
from mlcube.runner import Runner
16+
from mlcube.shell import Shell
1717
from mlcube.system_settings import SystemSettings
1818
from mlcube.validate import Validate
1919

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

273273

274+
@cli.command(name='create',
275+
help='Create a new MLCube using cookiecutter.')
276+
def create() -> None:
277+
""" Create a new MLCube using cookiecutter template.
278+
- MLCube cookiecutter: https://github.com/mlcommons/mlcube_cookiecutter
279+
- Example: https://mlcommons.github.io/mlcube/tutorials/create-mlcube/
280+
"""
281+
mlcube_cookiecutter_url = 'https://github.com/mlcommons/mlcube_cookiecutter'
282+
try:
283+
from cookiecutter.main import cookiecutter
284+
proj_dir: t.Text = cookiecutter(mlcube_cookiecutter_url)
285+
if proj_dir and os.path.isfile(os.path.join(proj_dir, 'mlcube.yaml')):
286+
Shell.run('mlcube', 'describe', '--mlcube', proj_dir)
287+
except ImportError:
288+
print("Cookiecutter library not found.")
289+
print("\tInstall it: pip install cookiecutter")
290+
print(f"\tMore details: {mlcube_cookiecutter_url}")
291+
292+
274293
if __name__ == "__main__":
275294
cli()

0 commit comments

Comments
 (0)