Skip to content

Commit

Permalink
Merge pull request #20 from datmo/task-client
Browse files Browse the repository at this point in the history
adding client task with test
  • Loading branch information
asampat3090 committed Apr 26, 2018
2 parents 620a4f8 + 83a0efd commit e26b1ee
Show file tree
Hide file tree
Showing 47 changed files with 1,363 additions and 417 deletions.
3 changes: 2 additions & 1 deletion datmo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
from __future__ import division
from __future__ import print_function

import datmo.snapshot
import datmo.snapshot
import datmo.task
8 changes: 4 additions & 4 deletions datmo/cli/command/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ def mutually_exclusive(dictionary, mutually_exclusive_args):

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

def ls(self, **kwargs):
session_id = kwargs.get('session_id',
Expand Down Expand Up @@ -135,8 +135,8 @@ def ls(self, **kwargs):
return True

def checkout(self, **kwargs):
id = kwargs.get("id", None)
return self.snapshot_controller.checkout(id)
snapshot_id = kwargs.get("id", None)
return self.snapshot_controller.checkout(snapshot_id)



Expand Down
13 changes: 6 additions & 7 deletions datmo/cli/command/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def run(self, **kwargs):
kwargs['environment_definition_filepath']
}

if type(kwargs['cmd']) is not list:
if not isinstance(kwargs['cmd'], list):
kwargs['cmd'] = shlex.split(kwargs['cmd'])

task_dict = {
Expand Down Expand Up @@ -89,22 +89,21 @@ def ls(self, **kwargs):
return True

def stop(self, **kwargs):
id = kwargs.get('id', None)
task_stop_dict = {"id": id}
task_id = kwargs.get('id', None)
self.cli_helper.echo(__("info",
"cli.task.stop",
id))
task_id))
try:
result = self.task_controller.stop(**task_stop_dict)
result = self.task_controller.stop(task_id)
if not result:
self.cli_helper.echo(__("error",
"cli.task.stop",
id))
task_id))
return result
except:
self.cli_helper.echo(__("error",
"cli.task.stop",
id))
task_id))
return False


Expand Down
5 changes: 3 additions & 2 deletions datmo/cli/command/test/test_project.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Tests for Init
Tests for Project Commands
"""
from __future__ import division
from __future__ import print_function
Expand All @@ -19,7 +19,8 @@
from datmo.cli.driver.helper import Helper
from datmo.cli.command.project import ProjectCommand

class TestInit():

class TestProject():
def setup_class(self):
# provide mountable tmp directory for docker
tempfile.tempdir = '/tmp'
Expand Down
13 changes: 9 additions & 4 deletions datmo/cli/command/test/test_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
import os
import shutil
import tempfile
from io import open
try:
to_unicode = unicode
except NameError:
to_unicode = str

from datmo.cli.driver.helper import Helper
from datmo.cli.command.project import ProjectCommand
Expand Down Expand Up @@ -46,25 +51,25 @@ def __set_variables(self):
self.env_def_path = os.path.join(self.temp_dir,
"Dockerfile")
with open(self.env_def_path, "w") as f:
f.write(str("FROM datmo/xgboost:cpu"))
f.write(to_unicode(str("FROM datmo/xgboost:cpu")))

# Create config
self.config_filepath = os.path.join(self.snapshot.home,
"config.json")
with open(self.config_filepath, "w") as f:
f.write(str("{}"))
f.write(to_unicode(str("{}")))

# Create stats
self.stats_filepath = os.path.join(self.snapshot.home,
"stats.json")
with open(self.stats_filepath, "w") as f:
f.write(str("{}"))
f.write(to_unicode(str("{}")))

# Create test file
self.filepath = os.path.join(self.snapshot.home,
"file.txt")
with open(self.filepath, "w") as f:
f.write(str("test"))
f.write(to_unicode(str("test")))

def test_snapshot_project_not_init(self):
failed = False
Expand Down
7 changes: 6 additions & 1 deletion datmo/cli/command/test/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
import os
import shutil
import tempfile
from io import open
try:
to_unicode = unicode
except NameError:
to_unicode = str

from datmo.cli.driver.helper import Helper
from datmo.cli.command.project import ProjectCommand
Expand Down Expand Up @@ -47,7 +52,7 @@ def __set_variables(self):
env_def_path = os.path.join(self.temp_dir,
"Dockerfile")
with open(env_def_path, "w") as f:
f.write(str("FROM datmo/xgboost:cpu"))
f.write(to_unicode(str("FROM datmo/xgboost:cpu")))

def test_task_project_not_init(self):
failed = False
Expand Down
9 changes: 7 additions & 2 deletions datmo/cli/driver/test/test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import os
import sys
import tempfile
from io import open
try:
to_unicode = unicode
except NameError:
to_unicode = str

# TODO: include builtin libraries for the appropriate Python
# try:
Expand All @@ -16,9 +21,9 @@
# # Python 3
# import builtins as __builtin__


from datmo.cli.driver.helper import Helper


class TestHelper():
# https://stackoverflow.com/questions/35851323/pytest-how-to-test-a-function-with-input-call/36377194

Expand All @@ -42,7 +47,7 @@ def test_prompt(self):
test_message = 'foobar'
with open(os.path.join(self.temp_dir,
"test.txt"), "w") as f:
f.write(test_message)
f.write(to_unicode(test_message))

with open(os.path.join(self.temp_dir,
"test.txt"), "r") as f:
Expand Down
10 changes: 5 additions & 5 deletions datmo/core/controller/code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ def list(self):
# TODO: Add time filters
return self.dal.code.query({})

def delete(self, id):
def delete(self, code_id):
"""Delete all traces of Code object
Parameters
----------
id : str
code_id : str
code object id to remove
Returns
Expand All @@ -93,11 +93,11 @@ def delete(self, id):
DoesNotExistException
if the specified Code does not exist.
"""
code_obj = self.dal.code.get_by_id(id)
code_obj = self.dal.code.get_by_id(code_id)
if not code_obj:
raise DoesNotExistException(__("error",
"controller.code.delete",
id))
"controller.code.delete",
code_id))
# Remove code reference
delete_code_success = self.code_driver.delete_ref(code_obj.commit_id)
# Delete code object
Expand Down
21 changes: 13 additions & 8 deletions datmo/core/controller/code/driver/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
import shutil
import subprocess
import semver
from io import open
try:
to_unicode = unicode
except NameError:
to_unicode = str
from giturlparse import parse

from datmo.core.util.i18n import get as __
Expand Down Expand Up @@ -141,7 +146,7 @@ def create_ref(self, commit_id=None):
".git/refs/datmo/",
commit_id)
with open(code_ref_path, "w") as f:
f.write(commit_id)
f.write(to_unicode(commit_id))
return commit_id

def exists_ref(self, commit_id):
Expand Down Expand Up @@ -226,7 +231,7 @@ def ensure_datmo_files_ignored(self):
try:
if not self.exists_datmo_files_ignored():
with open(exclude_file, "a") as f:
f.write("\n.datmo/*\n")
f.write(to_unicode("\n.datmo/*\n"))
except Exception as e:
raise FileIOException(__("error",
"controller.code.driver.git.ensure_code_refs_dir",
Expand Down Expand Up @@ -693,12 +698,12 @@ def create_git_netrc(self, username, password):
netrc_filepath = os.path.join(self.home, ".netrc")
netrc_file = open(netrc_filepath, "w")
netrc_file.truncate()
netrc_file.write("machine %s" % (self.host))
netrc_file.write("\n")
netrc_file.write("login " + str(username))
netrc_file.write("\n")
netrc_file.write("password " + str(password))
netrc_file.write("\n")
netrc_file.write(to_unicode("machine %s" % (self.host)))
netrc_file.write(to_unicode("\n"))
netrc_file.write(to_unicode("login " + str(username)))
netrc_file.write(to_unicode("\n"))
netrc_file.write(to_unicode("password " + str(password)))
netrc_file.write(to_unicode("\n"))
netrc_file.close()
return True

Expand Down

0 comments on commit e26b1ee

Please sign in to comment.