diff --git a/MANIFEST.in b/MANIFEST.in index be2b437e..b529383f 100644 --- a/MANIFEST.in +++ b/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 \ No newline at end of file +include datmo/VERSION +prune examples +prune docs +prune templates \ No newline at end of file diff --git a/datmo/VERSION b/datmo/VERSION new file mode 100644 index 00000000..e59eb1a6 --- /dev/null +++ b/datmo/VERSION @@ -0,0 +1 @@ +0.0.2-dev \ No newline at end of file diff --git a/datmo/__init__.py b/datmo/__init__.py index 5f0f1759..68b9dfe4 100644 --- a/datmo/__init__.py +++ b/datmo/__init__.py @@ -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 diff --git a/datmo/cli/command/project.py b/datmo/cli/command/project.py index 4493ccf8..98364da8 100644 --- a/datmo/cli/command/project.py +++ b/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 @@ -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__) \ No newline at end of file diff --git a/datmo/cli/command/tests/test_project.py b/datmo/cli/command/tests/test_project.py index 869e6b89..f58ab51d 100644 --- a/datmo/cli/command/tests/test_project.py +++ b/datmo/cli/command/tests/test_project.py @@ -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 @@ -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 diff --git a/datmo/cli/driver/helper.py b/datmo/cli/driver/helper.py index 7e86b28a..1b56cff2 100644 --- a/datmo/cli/driver/helper.py +++ b/datmo/cli/driver/helper.py @@ -17,6 +17,7 @@ def __init__(self): def echo(self, message): print(message) + return message def prompt(self, msg, default=None): try: @@ -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"] diff --git a/datmo/cli/main.py b/datmo/cli/main.py index f0fc2c1a..6f2f1534 100644 --- a/datmo/cli/main.py +++ b/datmo/cli/main.py @@ -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: diff --git a/datmo/cli/parser.py b/datmo/cli/parser.py index 1819e766..47a29b46 100644 --- a/datmo/cli/parser.py +++ b/datmo/cli/parser.py @@ -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") @@ -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", @@ -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") @@ -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", @@ -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") @@ -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") diff --git a/docs/conf.py b/docs/conf.py index 1c58a4cf..bedc51bf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 ------------------------------------------------ diff --git a/setup.py b/setup.py index 4fe8579c..a78fed4c 100644 --- a/setup.py +++ b/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__, diff --git a/version.py b/version.py deleted file mode 100644 index a0fca0e2..00000000 --- a/version.py +++ /dev/null @@ -1 +0,0 @@ -__version__ = '0.0.2-dev' \ No newline at end of file