Skip to content

Commit

Permalink
Merge pull request #79 from datmo/docs-cleanup
Browse files Browse the repository at this point in the history
Docs update with cli, sdk, and examples
  • Loading branch information
asampat3090 committed May 5, 2018
2 parents f75cd9a + 15e73f9 commit 31ce5ed
Show file tree
Hide file tree
Showing 36 changed files with 338 additions and 598 deletions.
7 changes: 5 additions & 2 deletions datmo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""
Bring in all of Datmo's public interfaces
Bring in all of Datmo's public python interfaces
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from version import __version__

__version__ = __version__

import datmo.snapshot
import datmo.task
import datmo.config
import datmo.config
3 changes: 3 additions & 0 deletions datmo/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import sys
from datmo.cli.main import main
sys.exit(main())
24 changes: 2 additions & 22 deletions datmo/cli/command/base.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
#!/usr/bin/python

from datmo.core.util.i18n import get as __
from datmo.cli.driver.parser import Parser
from datmo.core.util.exceptions import ClassMethodNotFound


class BaseCommand(object):
def __init__(self, home, cli_helper):
def __init__(self, home, cli_helper, parser):
self.home = home
self.cli_helper = cli_helper
self.parser = Parser(
prog="datmo",
usage="""
datmo COMMAND [SUBCOMMANDS] ARGS
Datmo is a command line utility to enable tracking of data science projects.
It uses many of the tools you are already familiar with and combines them into a snapshot
which allows you to keep track of 5 components at once
1) Source Code
2) Dependency Environment
3) Large Files
4) Configurations
5) Metrics
command:
""")
self.subparsers = self.parser.add_subparsers(
title="commands", dest="command")
self.parser = parser

def parse(self, args):
self.args = self.parser.parse_args(args)
Expand Down
8 changes: 2 additions & 6 deletions datmo/cli/command/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
class ProjectCommand(BaseCommand):
# NOTE: dal_driver is not passed into the project because it is created
# first by ProjectController and then passed down to all other Controllers
def __init__(self, home, cli_helper):
super(ProjectCommand, self).__init__(home, cli_helper)
init_parser = self.subparsers.add_parser(
"init", help="Initialize project")
init_parser.add_argument("--name", default=None)
init_parser.add_argument("--description", default=None)
def __init__(self, home, cli_helper, parser):
super(ProjectCommand, self).__init__(home, cli_helper, parser)
self.project_controller = ProjectController(home=home)

def init(self, name, description):
Expand Down
30 changes: 2 additions & 28 deletions datmo/cli/command/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,10 @@


class SessionCommand(ProjectCommand):
def __init__(self, home, cli_helper):
super(SessionCommand, self).__init__(home, cli_helper)
def __init__(self, home, cli_helper, parser):
super(SessionCommand, self).__init__(home, cli_helper, parser)
# dest="subcommand" argument will populate a "subcommand" property with the subparsers name
# example "subcommand"="create" or "subcommand"="ls"
snapshot_parser = self.subparsers.add_parser(
"session", help="Session module")
subcommand_parsers = snapshot_parser.add_subparsers(
title="subcommands", dest="subcommand")

create = subcommand_parsers.add_parser("create", help="Create session")
create.add_argument(
"--name", "-m", dest="name", default="", help="Session name")
create.add_argument(
"--current",
dest="current",
action="store_false",
help="Boolean if you want to switch to this session")

delete = subcommand_parsers.add_parser(
"delete", help="Delete a snapshot by id")
delete.add_argument(
"--name", dest="name", help="Name of session to delete")

ls = subcommand_parsers.add_parser("ls", help="List sessions")

checkout = subcommand_parsers.add_parser(
"select", help="Select a session")
checkout.add_argument(
"--name", dest="name", help="Name of session to select")

self.session_controller = SessionController(home=home)

def create(self, **kwargs):
Expand Down
117 changes: 2 additions & 115 deletions datmo/cli/command/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,123 +9,10 @@


class SnapshotCommand(ProjectCommand):
def __init__(self, home, cli_helper):
super(SnapshotCommand, self).__init__(home, cli_helper)
def __init__(self, home, cli_helper, parser):
super(SnapshotCommand, self).__init__(home, cli_helper, parser)
# dest="subcommand" argument will populate a "subcommand" property with the subparsers name
# example "subcommand"="create" or "subcommand"="ls"
snapshot_parser = self.subparsers.add_parser(
"snapshot", help="Snapshot module")
subcommand_parsers = snapshot_parser.add_subparsers(
title="subcommands", dest="subcommand")

create = subcommand_parsers.add_parser(
"create", help="create snapshot")
create.add_argument(
"--message",
"-m",
dest="message",
default=None,
help="message to describe snapshot")
create.add_argument(
"--label",
"-l",
dest="label",
default=None,
help="Label snapshots with a category (e.g. best)")
create.add_argument(
"--session-id",
dest="session_id",
default=None,
help="user given session id")

create.add_argument(
"--task-id",
dest="task_id",
default=None,
help="Specify task id to pull information from")

create.add_argument(
"--code-id",
dest="code_id",
default=None,
help="code id from code object")
create.add_argument(
"--commit-id",
dest="commit_id",
default=None,
help="commit id from source control")

create.add_argument(
"--environment-id",
dest="environment_id",
default=None,
help="environment id from environment object")
create.add_argument(
"--environment-def-path",
dest="environment_def_path",
default=None,
help=
"absolute filepath to environment definition file (e.g. /path/to/Dockerfile)"
)

create.add_argument(
"--file-collection-id",
dest="file_collection_id",
default=None,
help="file collection id for file collection object")
create.add_argument(
"--filepaths",
dest="filepaths",
default=None,
action="append",
help=
"absolute paths to files or folders to include within the files of the snapshot"
)

create.add_argument(
"--config-filename",
dest="config_filename",
default=None,
help="filename to use to search for configuration JSON")
create.add_argument(
"--config-filepath",
dest="config_filepath",
default=None,
help="absolute filepath to use to search for configuration JSON")

create.add_argument(
"--stats-filename",
dest="stats_filename",
default=None,
help="filename to use to search for metrics JSON")
create.add_argument(
"--stats-filepath",
dest="stats_filepath",
default=None,
help="absolute filepath to use to search for metrics JSON")

delete = subcommand_parsers.add_parser(
"delete", help="Delete a snapshot by id")
delete.add_argument("--id", dest="id", help="snapshot id to delete")

ls = subcommand_parsers.add_parser("ls", help="List snapshots")
ls.add_argument(
"--session-id",
dest="session_id",
default=None,
help="Session ID to filter")
ls.add_argument(
"--all",
"-a",
dest="details",
action="store_true",
help="Show detailed snapshot information")

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)

def create(self, **kwargs):
Expand Down
57 changes: 2 additions & 55 deletions datmo/cli/command/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,9 @@


class TaskCommand(ProjectCommand):
def __init__(self, home, cli_helper):
super(TaskCommand, self).__init__(home, cli_helper)

def __init__(self, home, cli_helper, parser):
super(TaskCommand, self).__init__(home, cli_helper, parser)
self.logger = DatmoLogger.get_logger(__name__)
task_parser = self.subparsers.add_parser("task", help="Task module")
subcommand_parsers = task_parser.add_subparsers(
title="subcommands", dest="subcommand")

# Task run arguments
run = subcommand_parsers.add_parser("run", help="Run task")
run.add_argument(
"--gpu",
dest="gpu",
action="store_true",
help="Boolean if you want to run using GPUs")
run.add_argument(
"--ports",
dest="ports",
default=None,
action="append",
type=str,
help="""
Network port mapping during task (e.g. 8888:8888). Left is the host machine port and right
is the environment port available during a run.
""")
# run.add_argument("--data", nargs="*", dest="data", type=str, help="Path for data to be used during the Task")
run.add_argument(
"--env-def",
dest="environment_definition_filepath",
default=None,
type=str,
help=
"Pass in the Dockerfile with which you want to build the environment"
)
run.add_argument(
"--interactive",
dest="interactive",
action="store_true",
help="Run the environment in interactive mode (keeps STDIN open)")
run.add_argument("cmd", nargs="?", default=None)

# Task list arguments
ls = subcommand_parsers.add_parser("ls", help="List tasks")
ls.add_argument(
"--session-id",
dest="session_id",
default=None,
nargs="?",
type=str,
help="Pass in the session id to list the tasks in that session")

# Task stop arguments
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)

def run(self, **kwargs):
Expand Down
6 changes: 3 additions & 3 deletions datmo/cli/command/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# import builtins as __builtin__

import os
import shutil
import tempfile
import platform

from datmo.cli.driver.helper import Helper
from datmo.cli.parser import parser
from datmo.cli.command.project import ProjectCommand


Expand All @@ -29,8 +29,8 @@ def setup_class(self):
test_datmo_dir = os.environ.get('TEST_DATMO_DIR',
tempfile.gettempdir())
self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir)
self.cli = Helper()
self.init = ProjectCommand(self.temp_dir, self.cli)
self.cli_helper = Helper()
self.init = ProjectCommand(self.temp_dir, self.cli_helper, parser)

def teardown_class(self):
pass
Expand Down
6 changes: 4 additions & 2 deletions datmo/cli/command/tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import os
from datmo.cli.driver.helper import Helper
from datmo.cli.parser import parser
from datmo.cli.command.session import SessionCommand
from datmo.cli.command.project import ProjectCommand

Expand All @@ -27,9 +28,10 @@ def setup_class(self):
tempfile.gettempdir())
self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir)
self.cli_helper = Helper()
self.session_command = SessionCommand(self.temp_dir, self.cli_helper)
self.session_command = SessionCommand(self.temp_dir, self.cli_helper,
parser)

init = ProjectCommand(self.temp_dir, self.cli_helper)
init = ProjectCommand(self.temp_dir, self.cli_helper, parser)
init.parse(["init", "--name", "foobar", "--description", "test model"])
init.execute()

Expand Down
8 changes: 5 additions & 3 deletions datmo/cli/command/tests/test_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
to_unicode = str

from datmo.cli.driver.helper import Helper
from datmo.cli.parser import parser
from datmo.cli.command.project import ProjectCommand
from datmo.cli.command.snapshot import SnapshotCommand
from datmo.core.util.exceptions import (ProjectNotInitializedException,
Expand All @@ -41,11 +42,11 @@ def teardown_class(self):
pass

def __set_variables(self):
self.init = ProjectCommand(self.temp_dir, self.cli_helper)
self.init = ProjectCommand(self.temp_dir, self.cli_helper, parser)
self.init.parse(
["init", "--name", "foobar", "--description", "test model"])
self.init.execute()
self.snapshot = SnapshotCommand(self.temp_dir, self.cli_helper)
self.snapshot = SnapshotCommand(self.temp_dir, self.cli_helper, parser)

# Create environment_driver definition
self.env_def_path = os.path.join(self.temp_dir, "Dockerfile")
Expand Down Expand Up @@ -75,7 +76,8 @@ def __set_variables(self):
def test_snapshot_project_not_init(self):
failed = False
try:
self.snapshot = SnapshotCommand(self.temp_dir, self.cli_helper)
self.snapshot = SnapshotCommand(self.temp_dir, self.cli_helper,
parser)
except ProjectNotInitializedException:
failed = True
assert failed
Expand Down

0 comments on commit 31ce5ed

Please sign in to comment.