Skip to content

Commit

Permalink
Merge pull request #12 from datmo/python-module
Browse files Browse the repository at this point in the history
Added python module and moved core code
  • Loading branch information
asampat3090 committed Apr 20, 2018
2 parents 06bc86f + bc56d74 commit b5dcede
Show file tree
Hide file tree
Showing 105 changed files with 769 additions and 523 deletions.
3 changes: 3 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
exclude_paths:
- '**/test/**'
6 changes: 3 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include datmo/controller/environment/driver/templates/baseDockerfile
include datmo/controller/environment/driver/templates/python2Dockerfile
include datmo/controller/environment/driver/templates/python3Dockerfile
include datmo/core/controller/environment/driver/templates/baseDockerfile
include datmo/core/controller/environment/driver/templates/python2Dockerfile
include datmo/core/controller/environment/driver/templates/python3Dockerfile
recursive-include templates *
8 changes: 8 additions & 0 deletions datmo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Bring in all of Datmo's public interfaces
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import datmo.snapshot
6 changes: 3 additions & 3 deletions datmo/cli/command/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datmo.util.i18n import get as _
from datmo.core.util.i18n import get as __
from datmo.cli.driver.parser import Parser
from datmo.util.exceptions import ClassMethodNotFound
from datmo.core.util.exceptions import ClassMethodNotFound


class BaseCommand(object):
Expand Down Expand Up @@ -55,7 +55,7 @@ def execute(self):
del command_args["subcommand"]

if method is None:
raise ClassMethodNotFound(_("error",
raise ClassMethodNotFound(__("error",
"cli.general.method.not_found",
(self.args.command, method)))

Expand Down
10 changes: 5 additions & 5 deletions datmo/cli/command/project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datmo.util.i18n import get as _
from datmo.core.util.i18n import get as __
from datmo.cli.command.base import BaseCommand
from datmo.controller.project import ProjectController
from datmo.core.controller.project import ProjectController


class ProjectCommand(BaseCommand):
Expand All @@ -15,8 +15,8 @@ def __init__(self, home, cli_helper):

def init(self, name, description):
if not name:
name = self.cli_helper.prompt(_("prompt", "cli.project.init.name"))
name = self.cli_helper.prompt(__("prompt", "cli.project.init.name"))
if not description:
description = self.cli_helper.prompt(_("prompt", "cli.project.init.description"))
self.cli_helper.echo(_("info", "cli.project.init", {"name":name, "path": self.home}))
description = self.cli_helper.prompt(__("prompt", "cli.project.init.description"))
self.cli_helper.echo(__("info", "cli.project.init", {"name":name, "path": self.home}))
self.project_controller.init(name, description)
17 changes: 6 additions & 11 deletions datmo/cli/command/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import prettytable

from datmo.util.i18n import get as _
from datmo.core.util.i18n import get as __
from datmo.cli.command.project import ProjectCommand
from datmo.controller.snapshot import SnapshotController
from datmo.util.exceptions import ProjectNotInitializedException
from datmo.core.controller.snapshot import SnapshotController
from datmo.core.util.exceptions import ProjectNotInitializedException


class SnapshotCommand(ProjectCommand):
Expand Down Expand Up @@ -59,15 +59,10 @@ def __init__(self, home, cli_helper):
checkout = subcommand_parsers.add_parser("checkout", help="Checkout a snapshot by id")
checkout.add_argument("--id", dest="id", default=None, help="Snapshot ID")

self.snapshot_controller = SnapshotController(home=home,
dal_driver=self.project_controller.dal_driver)
if not self.project_controller.is_initialized:
raise ProjectNotInitializedException(_("error",
"cli.project",
self.home))
self.snapshot_controller = SnapshotController(home=home)

def create(self, **kwargs):
self.cli_helper.echo(_("info", "cli.snapshot.create"))
self.cli_helper.echo(__("info", "cli.snapshot.create"))

def mutually_exclusive(dictionary, mutually_exclusive_args):
for arg in mutually_exclusive_args:
Expand Down Expand Up @@ -109,7 +104,7 @@ def mutually_exclusive(dictionary, mutually_exclusive_args):
return snapshot_obj.id

def delete(self, **kwargs):
self.cli_helper.echo(_("info", "cli.snapshot.delete"))
self.cli_helper.echo(__("info", "cli.snapshot.delete"))
id = kwargs.get("id", None)
return self.snapshot_controller.delete(id)

Expand Down
35 changes: 15 additions & 20 deletions datmo/cli/command/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
import shlex
import prettytable

from datmo.util.i18n import get as _
from datmo.core.util.i18n import get as __
from datmo.cli.command.project import ProjectCommand
from datmo.controller.task import TaskController
from datmo.util.exceptions import ProjectNotInitializedException
from datmo.core.controller.task import TaskController


class TaskCommand(ProjectCommand):
Expand Down Expand Up @@ -41,15 +40,10 @@ def __init__(self, home, cli_helper):
stop = subcommand_parsers.add_parser("stop", help="Stop tasks")
stop.add_argument("--id", dest="id", default=None, type=str, help="Task ID to stop")

self.task_controller = TaskController(home=home,
dal_driver=self.project_controller.dal_driver)
if not self.project_controller.is_initialized:
raise ProjectNotInitializedException(_("error",
"cli.project",
self.home))
self.task_controller = TaskController(home=home)

def run(self, **kwargs):
self.cli_helper.echo(_("info", "cli.task.run"))
self.cli_helper.echo(__("info", "cli.task.run"))

# Create input dictionaries
snapshot_dict = {
Expand Down Expand Up @@ -88,16 +82,17 @@ def ls(self, **kwargs):
self.cli_helper.echo(t)
return True

def stop(self, **kwargs):
id = kwargs.get('id', None)
try:
task_delete_dict = {"id": id}
self.task_controller.delete(**task_delete_dict)
except Exception:
self.cli_helper.echo(_("error",
"cli.task.delete"))
return False
return True
# TODO: implement with proper task controller function
# def stop(self, **kwargs):
# id = kwargs.get('id', None)
# try:
# task_delete_dict = {"id": id}
# self.task_controller.delete(**task_delete_dict)
# except Exception:
# self.cli_helper.echo(__("error",
# "cli.task.delete"))
# return False
# return True



Expand Down
20 changes: 5 additions & 15 deletions datmo/cli/command/test/test_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from datmo.cli.driver.helper import Helper
from datmo.cli.command.project import ProjectCommand
from datmo.cli.command.snapshot import SnapshotCommand
from datmo.util.exceptions import ProjectNotInitializedException
from datmo.core.util.exceptions import ProjectNotInitializedException


class TestSnapshot():
Expand Down Expand Up @@ -67,10 +67,12 @@ def __set_variables(self):
f.write(str("test"))

def test_snapshot_project_not_init(self):
failed = False
try:
self.snapshot = SnapshotCommand(self.temp_dir, self.cli_helper)
except ProjectNotInitializedException:
assert True
failed = True
assert failed

def test_datmo_snapshot_create(self):
self.__set_variables()
Expand Down Expand Up @@ -237,16 +239,4 @@ def test_datmo_snapshot_checkout(self):
])

result = self.snapshot.execute()
assert result

def test_datmo_snapshot_checkout_invalid_arg(self):
self.__set_variables()
exception_thrown = False
try:
self.snapshot.parse([
"snapshot",
"checkout"
"--foobar","foobar"])
except Exception:
exception_thrown = True
assert exception_thrown
assert result
100 changes: 52 additions & 48 deletions datmo/cli/command/test/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
from datmo.cli.driver.helper import Helper
from datmo.cli.command.project import ProjectCommand
from datmo.cli.command.task import TaskCommand
from datmo.util.exceptions import ProjectNotInitializedException, \
EntityNotFound
from datmo.core.util.exceptions import ProjectNotInitializedException


class TestTaskCommand():
Expand Down Expand Up @@ -51,10 +50,12 @@ def __set_variables(self):
f.write(str("FROM datmo/xgboost:cpu"))

def test_task_project_not_init(self):
failed = False
try:
self.task = TaskCommand(self.temp_dir, self.cli_helper)
except ProjectNotInitializedException:
assert True
failed = True
assert failed

def test_datmo_task_run(self):
self.__set_variables()
Expand Down Expand Up @@ -126,51 +127,54 @@ def test_datmo_task_ls_invalid_arg(self):
exception_thrown = True
assert exception_thrown

def test_datmo_task_stop(self):
self.__set_variables()

test_command = ["sh", "-c", "echo yo"]
test_ports = "8888:8888"
test_dockerfile = os.path.join(self.temp_dir, "Dockerfile")

self.task.parse([
"task",
"run",
"--gpu",
"--ports", test_ports,
"--env-def", test_dockerfile,
"--interactive",
test_command
])

test_task_id = self.task.execute()

self.task.parse([
"task",
"stop",
"--id", test_task_id
])

# test for desired side effects
assert self.task.args.id == test_task_id

# test when task id is passed to stop it
task_stop_command = self.task.execute()
assert task_stop_command == True

# Passing wrong task id
test_task_id = "task_id"
self.task.parse([
"task",
"stop",
"--id", test_task_id
])

# test when wrong task id is passed to stop it
try:
self.task.execute()
except EntityNotFound:
assert True
# TODO: implement with proper task controller
# def test_datmo_task_stop(self):
# self.__set_variables()
#
# test_command = ["sh", "-c", "echo yo"]
# test_ports = "8888:8888"
# test_dockerfile = os.path.join(self.temp_dir, "Dockerfile")
#
# self.task.parse([
# "task",
# "run",
# "--gpu",
# "--ports", test_ports,
# "--env-def", test_dockerfile,
# "--interactive",
# test_command
# ])
#
# test_task_id = self.task.execute()
#
# self.task.parse([
# "task",
# "stop",
# "--id", test_task_id
# ])
#
# # test for desired side effects
# assert self.task.args.id == test_task_id
#
# # test when task id is passed to stop it
# task_stop_command = self.task.execute()
# assert task_stop_command == True
#
# # Passing wrong task id
# test_task_id = "task_id"
# self.task.parse([
# "task",
# "stop",
# "--id", test_task_id
# ])
#
# # test when wrong task id is passed to stop it
# failed = False
# try:
# self.task.execute()
# except:
# failed = True
# assert failed

def test_datmo_task_stop_invalid_arg(self):
self.__set_variables()
Expand Down
6 changes: 3 additions & 3 deletions datmo/cli/driver/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import importlib
import inspect

from datmo.util.i18n import get as _
from datmo.util.exceptions import ArgumentException
from datmo.core.util.i18n import get as __
from datmo.core.util.exceptions import ArgumentException


class Helper():
Expand Down Expand Up @@ -48,7 +48,7 @@ def get_command_class(self, command_name):
try:
command_class = importlib.import_module(command_path)
except ImportError as ex:
self.echo(_("error", "cli.general", ex.message))
self.echo(__("error", "cli.general", ex.message))
sys.exit()

all_members = inspect.getmembers(command_class)
Expand Down
2 changes: 1 addition & 1 deletion datmo/cli/driver/parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import argparse

from datmo.util.exceptions import UnrecognizedCLIArgument
from datmo.core.util.exceptions import UnrecognizedCLIArgument

class Parser(argparse.ArgumentParser):
"""
Expand Down
10 changes: 5 additions & 5 deletions datmo/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
import sys

from datmo.util.i18n import get as _
from datmo.core.util.i18n import get as __
from datmo.cli.driver.helper import Helper
from datmo.cli.command.base import BaseCommand
from datmo.util.exceptions import CLIArgumentException
from datmo.core.util.exceptions import CLIArgumentException


def main():
Expand All @@ -27,19 +27,19 @@ def main():
try:
command_instance = command_class(os.getcwd(), cli_helper)
except TypeError as ex:
cli_helper.echo(_("error", "cli.general", str(ex)))
cli_helper.echo(__("error", "cli.general", str(ex)))
sys.exit()

try:
command_instance.parse(sys.argv[1:])
except CLIArgumentException as ex:
cli_helper.echo(_("error", "cli.general", str(ex)))
cli_helper.echo(__("error", "cli.general", str(ex)))
sys.exit()

try:
command_instance.execute()
except Exception as ex:
cli_helper.echo(_("error", "cli.general", str(ex)))
cli_helper.echo(__("error", "cli.general", str(ex)))

if __name__ == "__main__":
main()

0 comments on commit b5dcede

Please sign in to comment.