Skip to content

Commit

Permalink
adding env setup in cli command
Browse files Browse the repository at this point in the history
  • Loading branch information
shabazpatel committed Jun 4, 2018
1 parent b537d12 commit 355b53c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
14 changes: 14 additions & 0 deletions datmo/cli/command/environment.py
Expand Up @@ -19,6 +19,20 @@ def environment(self):
self.parse(["--help"])
return True

def setup(self, **kwargs):
libraries = kwargs.get("libraries", None)
available_libraries = self.environment_controller.get_current_libraries()
if not libraries:
for index, library in enumerate(available_libraries):
self.cli_helper.echo("(%s) %s" % (index+1, library))
libraries = self.cli_helper.prompt(
__("prompt", "cli.environment.setup.libraries"))
if libraries in available_libraries:
options = {"libraries": libraries}
return self.environment_controller.setup(options=options)
else:
self.cli_helper.echo(__("error", "cli.environment.setup.argument", libraries))

def create(self, **kwargs):
self.cli_helper.echo(__("info", "cli.environment.create"))
environment_obj = self.environment_controller.create(kwargs)
Expand Down
15 changes: 15 additions & 0 deletions datmo/cli/command/tests/test_environment.py
Expand Up @@ -53,6 +53,21 @@ def __set_variables(self):
self.environment_command = EnvironmentCommand(self.temp_dir,
self.cli_helper)

def test_environment_setup(self):
# Setup the environement by passing libraries
self.__set_variables()
datmo_environment_folder = os.path.join(self.temp_dir,
"datmo_environment")

definition_filepath = os.path.join(datmo_environment_folder,
"Dockerfile")
test_libraries = 'xgboost:cpu'
self.environment_command.parse(["environment", "setup", "--libraries", test_libraries])
result = self.environment_command.execute()

assert result and os.path.isfile(definition_filepath) and \
"datmo" in open(definition_filepath, "r").read()

def test_environment_create(self):
# 1) Environment definition file in `datmo_environment` folder
# 2) Environment definition file passed as an option
Expand Down
11 changes: 11 additions & 0 deletions datmo/cli/parser.py
Expand Up @@ -52,6 +52,17 @@ def get_datmo_parser():
environment_subcommand_parsers = environment_parser.add_subparsers(
title="subcommands", dest="subcommand")

environment_setup = environment_subcommand_parsers.add_parser(
"setup", help="setup environment")
environment_setup.add_argument(
"--libraries",
dest="libraries",
default=None,
type=str,
help=
"libraries/framework to be used for environment (e.g. xgboost:cpu)"
)

environment_create = environment_subcommand_parsers.add_parser(
"create", help="create environment")
environment_create.add_argument(
Expand Down
4 changes: 4 additions & 0 deletions datmo/core/util/lang/en.py
Expand Up @@ -37,6 +37,8 @@
"{foo} - {bar}",
"cli.general.tuple.test":
"%s, %s",
"cli.environment.setup.argument":
"No library exists with this name: %s",
"cli.environment.create":
"Creating a new environment",
"cli.environment.create.success":
Expand Down Expand Up @@ -328,6 +330,8 @@
"trace": {},
"fatal": {},
"prompt": {
"cli.environment.setup.libraries":
"Please choose one of the above images",
"cli.project.init.name":
"Enter name for the project",
"cli.project.init.description":
Expand Down

0 comments on commit 355b53c

Please sign in to comment.