Skip to content

Commit

Permalink
add datmo version, datmo --version, datmo -v commands for versi…
Browse files Browse the repository at this point in the history
…ons + moved to common VERSION file included in datmo package build
  • Loading branch information
asampat3090 committed May 5, 2018
1 parent 15e73f9 commit 0982505
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 38 deletions.
6 changes: 4 additions & 2 deletions MANIFEST.in
@@ -1,5 +1,7 @@
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 *
prune examples
include datmo/VERSION
prune examples
prune docs
prune templates
1 change: 1 addition & 0 deletions datmo/VERSION
@@ -0,0 +1 @@
0.0.2-dev
7 changes: 5 additions & 2 deletions datmo/__init__.py
Expand Up @@ -4,9 +4,12 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from version import __version__

__version__ = __version__
import os

datmo_root = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(datmo_root, 'VERSION')) as file:
__version__ = file.read()

import datmo.snapshot
import datmo.task
Expand Down
4 changes: 4 additions & 0 deletions datmo/cli/command/project.py
@@ -1,3 +1,4 @@
from datmo import __version__
from datmo.core.util.i18n import get as __
from datmo.cli.command.base import BaseCommand
from datmo.core.controller.project import ProjectController
Expand All @@ -23,3 +24,6 @@ def init(self, name, description):
"path": self.home
}))
self.project_controller.init(name, description)

def version(self):
return self.cli_helper.echo("datmo version: %s" % __version__)
23 changes: 19 additions & 4 deletions datmo/cli/command/tests/test_project.py
Expand Up @@ -16,6 +16,7 @@
import tempfile
import platform

from datmo import __version__
from datmo.cli.driver.helper import Helper
from datmo.cli.parser import parser
from datmo.cli.command.project import ProjectCommand
Expand All @@ -30,22 +31,36 @@ def setup_class(self):
tempfile.gettempdir())
self.temp_dir = tempfile.mkdtemp(dir=test_datmo_dir)
self.cli_helper = Helper()
self.init = ProjectCommand(self.temp_dir, self.cli_helper, parser)
self.project = ProjectCommand(self.temp_dir, self.cli_helper, parser)

def teardown_class(self):
pass

def test_datmo_init(self):
self.init.parse(
self.project.parse(
["init", "--name", "foobar", "--description", "test model"])
self.init.execute()
self.project.execute()
# test for desired side effects
assert os.path.exists(os.path.join(self.temp_dir, '.datmo'))

def test_datmo_init_invalid_arg(self):
exception_thrown = False
try:
self.init.parse(["init", "--foobar", "foobar"])
self.project.parse(["init", "--foobar", "foobar"])
except Exception:
exception_thrown = True
assert exception_thrown

def test_datmo_version(self):
self.project.parse(["version"])
result = self.project.execute()
# test for desired side effects
assert __version__ in result

def test_datmo_version_invalid_arg(self):
exception_thrown = False
try:
self.project.parse(["version", "--foobar"])
except Exception:
exception_thrown = True
assert exception_thrown
3 changes: 2 additions & 1 deletion datmo/cli/driver/helper.py
Expand Up @@ -17,6 +17,7 @@ def __init__(self):

def echo(self, message):
print(message)
return message

def prompt(self, msg, default=None):
try:
Expand Down Expand Up @@ -71,4 +72,4 @@ def get_command_class(self, command_name):
return command_class[1]

def get_command_choices(self):
return ["init", "snapshot", "task"]
return ["init", "version", "--version", "-v", "snapshot", "task"]
5 changes: 5 additions & 0 deletions datmo/cli/main.py
Expand Up @@ -38,6 +38,11 @@ def main():
command_name = sys.argv[1]
if command_name == "init":
command_name = "project"
elif command_name == "version" or \
command_name == "--version" or \
command_name == "-v":
command_name = "project"
sys.argv[1] = "version"
command_class = \
cli_helper.get_command_class(command_name)
else:
Expand Down
54 changes: 28 additions & 26 deletions datmo/cli/parser.py
Expand Up @@ -21,39 +21,41 @@
subparsers = parser.add_subparsers(title="commands", dest="command")

# Project
init_parser = subparsers.add_parser("init", help="Initialize project")
init_parser = subparsers.add_parser("init", help="initialize project")
init_parser.add_argument("--name", default=None)
init_parser.add_argument("--description", default=None)

version_parser = subparsers.add_parser("version", help="datmo version")

# Session
session_parser = subparsers.add_parser("session", help="Session module")
session_parser = subparsers.add_parser("session", help="session module")
session_subcommand_parsers = session_parser.add_subparsers(
title="subcommands", dest="subcommand")

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

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

session_ls = session_subcommand_parsers.add_parser("ls", help="List sessions")
session_ls = session_subcommand_parsers.add_parser("ls", help="list sessions")

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

# Snapshot
snapshot_parser = subparsers.add_parser("snapshot", help="Snapshot module")
snapshot_parser = subparsers.add_parser("snapshot", help="snapshot module")
snapshot_subcommand_parsers = snapshot_parser.add_subparsers(
title="subcommands", dest="subcommand")

Expand All @@ -70,7 +72,7 @@
"-l",
dest="label",
default=None,
help="Label snapshots with a category (e.g. best)")
help="label snapshots with a category (e.g. best)")
snapshot_create.add_argument(
"--session-id",
dest="session_id",
Expand All @@ -81,7 +83,7 @@
"--task-id",
dest="task_id",
default=None,
help="Specify task id to pull information from")
help="specify task id to pull information from")

snapshot_create.add_argument(
"--code-id", dest="code_id", default=None, help="code id from code object")
Expand Down Expand Up @@ -150,26 +152,26 @@
"--session-id",
dest="session_id",
default=None,
help="Session ID to filter")
help="session id to filter")
snapshot_ls.add_argument(
"--all",
"-a",
dest="details",
action="store_true",
help="Show detailed snapshot information")
help="show detailed snapshot information")

snapshot_checkout = snapshot_subcommand_parsers.add_parser(
"checkout", help="Checkout a snapshot by id")
"checkout", help="checkout a snapshot by id")
snapshot_checkout.add_argument(
"--id", dest="id", default=None, help="Snapshot ID")
"--id", dest="id", default=None, help="snapshot id")

# Task
task_parser = subparsers.add_parser("task", help="Task module")
task_parser = subparsers.add_parser("task", help="task module")
task_subcommand_parsers = task_parser.add_subparsers(
title="subcommands", dest="subcommand")

# Task run arguments
task_run = task_subcommand_parsers.add_parser("run", help="Run task")
task_run = task_subcommand_parsers.add_parser("run", help="run task")
task_run.add_argument(
"--gpu",
dest="gpu",
Expand All @@ -182,7 +184,7 @@
action="append",
type=str,
help="""
Network port mapping during task (e.g. 8888:8888). Left is the host machine port and right
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")
Expand All @@ -191,25 +193,25 @@
dest="environment_definition_filepath",
default=None,
type=str,
help="Pass in the Dockerfile with which you want to build the environment")
help="pass in the Dockerfile with which you want to build the environment")
task_run.add_argument(
"--interactive",
dest="interactive",
action="store_true",
help="Run the environment in interactive mode (keeps STDIN open)")
help="run the environment in interactive mode (keeps STDIN open)")
task_run.add_argument("cmd", nargs="?", default=None)

# Task list arguments
task_ls = task_subcommand_parsers.add_parser("ls", help="List tasks")
task_ls = task_subcommand_parsers.add_parser("ls", help="list tasks")
task_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")
help="pass in the session id to list the tasks in that session")

# Task stop arguments
task_stop = task_subcommand_parsers.add_parser("stop", help="Stop tasks")
task_stop = task_subcommand_parsers.add_parser("stop", help="stop tasks")
task_stop.add_argument(
"--id", dest="id", default=None, type=str, help="Task ID to stop")
"--id", dest="id", default=None, type=str, help="task id to stop")
4 changes: 3 additions & 1 deletion docs/conf.py
Expand Up @@ -22,7 +22,9 @@

sys.path.insert(0, os.path.abspath("../"))

from version import __version__
project_root = "../"
with open(os.path.join(project_root, 'datmo', 'VERSION')) as file:
__version__ = file.read()

# -- General configuration ------------------------------------------------

Expand Down
4 changes: 3 additions & 1 deletion setup.py
@@ -1,11 +1,13 @@
import os
from setuptools import setup, find_packages
from version import __version__

project_root = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(project_root, 'README.md')) as file:
long_description = file.read()

with open(os.path.join(project_root, 'datmo', 'VERSION')) as file:
__version__ = file.read()

setup(
name='datmo',
version=__version__,
Expand Down
1 change: 0 additions & 1 deletion version.py

This file was deleted.

0 comments on commit 0982505

Please sign in to comment.