Skip to content

Commit

Permalink
Merge pull request #1 from datmo/update-doc
Browse files Browse the repository at this point in the history
Update doc strings and normalize formatting
  • Loading branch information
asampat3090 committed Apr 8, 2018
2 parents fb697e9 + aa15c60 commit 953b48d
Show file tree
Hide file tree
Showing 43 changed files with 496 additions and 72 deletions.
1 change: 1 addition & 0 deletions datmo/cli/command/test/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import shutil
import tempfile

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

Expand Down
1 change: 1 addition & 0 deletions datmo/cli/command/test/test_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import shutil
import tempfile

from datmo.cli.driver.helper import Helper
from datmo.cli.command.project import ProjectCommand
from datmo.cli.command.snapshot import SnapshotCommand
Expand Down
1 change: 1 addition & 0 deletions datmo/cli/driver/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
import importlib
import inspect

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

Expand Down
3 changes: 2 additions & 1 deletion datmo/cli/driver/parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import sys
import argparse

from datmo.util.exceptions import UnrecognizedCLIArgument

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

from datmo.util.i18n import get as _
from datmo.cli.driver.helper import Helper
from datmo.cli.command.base import BaseCommand
Expand Down
95 changes: 91 additions & 4 deletions datmo/controller/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

from datmo.storage.local.driver.driver_type import DriverType
from datmo.util.i18n import get as _
from datmo.util import get_class_contructor
Expand All @@ -8,6 +9,35 @@


class BaseController(object):
"""
BaseController is used to setup the repository. It serves as the basis for all other Controller objects
Attributes
----------
home : str
Filepath for the location of the project
dal_driver : DataDriver object
This is an instance of a storage DAL driver
dal
model
current_session
code_driver
file_driver
environment_driver
is_initialized
Methods
-------
dal_instantiate()
Instantiate a version of the DAL
get_or_set_default(key, default_value)
Returns value adn sets to default if no value present
config_loader(key)
Return the config dictionary based on key
get_config_defaults()
Return the configuration defaults
"""

def __init__(self, home, dal_driver=None):
self.home = home
Expand All @@ -33,19 +63,43 @@ def __init__(self, home, dal_driver=None):
# TODO: Currently local for differnet controller objects do NOT sync within one session.
# TODO: Fix local such that it syncs within one session between controller objects
def dal(self):
"""
Property that is maintained in memory
Returns
-------
DAL
"""
if self._dal == None:
self._dal = self.dal_instantiate()
return self._dal

@property
def model(self):
"""
Property that is maintained in memory
Returns
-------
Model
"""
if self._model == None:
model_id = self.settings.get('model_id')
self._model = self.dal.model.get_by_id(model_id) if model_id else None
return self._model

@property
def current_session(self):
"""
Property that is maintained in memory
Returns
-------
Session
"""
if not self.model:
raise DatmoModelNotInitializedException(_("error",
"controller.base.current_session"))
Expand All @@ -56,27 +110,60 @@ def current_session(self):

@property
def code_driver(self):
"""
Property that is maintained in memory
Returns
-------
CodeDriver
"""
if self._code_driver == None:
module_details = self.config_loader("controller.code.driver")
self._code_driver = module_details["constructor"](**module_details["options"])
return self._code_driver

@property
def file_driver(self):
"""
Property that is maintained in memory
Returns
-------
FileDriver
"""
if self._file_driver == None:
module_details = self.config_loader("controller.file.driver")
self._file_driver = module_details["constructor"](**module_details["options"])
return self._file_driver

@property
def environment_driver(self):
"""
Property that is maintained in memory
Returns
-------
EnvironmentDriver
"""
if self._environment_driver == None:
module_details = self.config_loader("controller.environment.driver")
self._environment_driver = module_details["constructor"](**module_details["options"])
return self._environment_driver

@property
def is_initialized(self):
"""
Property that is maintained in memory
Returns
-------
bool
True if the project is property initialized else False
"""
if not self._is_initialized:
if self.code_driver.is_initialized and \
self.environment_driver.is_initialized and \
Expand Down Expand Up @@ -114,20 +201,20 @@ def config_loader(self, key):
def get_config_defaults(self):
return {
"controller.code.driver": {
"class_constructor": "datmo.controller.code.driver.git.GitCodeManager",
"class_constructor": "datmo.controller.code.driver.git.GitCodeDriver",
"options": {
"filepath": self.home,
"execpath": "git"
}
},
"controller.file.driver": {
"class_constructor": "datmo.controller.file.driver.local.LocalFileManager",
"class_constructor": "datmo.controller.file.driver.local.LocalFileDriver",
"options": {
"filepath": self.home
}
},
"controller.environment.driver":{
"class_constructor": "datmo.controller.environment.driver.dockerenv.DockerEnvironmentManager",
"class_constructor": "datmo.controller.environment.driver.dockerenv.DockerEnvironmentDriver",
"options": {
"filepath": self.home,
"docker_execpath": "docker",
Expand All @@ -141,7 +228,7 @@ def get_config_defaults(self):
}
},
"storage.local.driver": {
"class_constructor": "datmo.storage.local.driver.blitzdb_driver.BlitzDBDataDriver",
"class_constructor": "datmo.storage.local.driver.blitzdb_driver.BlitzDBDALDriver",
"options": {
"driver_type": "FILE",
"connection_string": os.path.join(self.home, ".datmo/database")
Expand Down
9 changes: 5 additions & 4 deletions datmo/controller/code/driver/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
GitUrlArgumentException, GitExecutionException, \
FileIOException

class GitCodeManager(object):

class GitCodeDriver(object):
"""
TODO: Reimplement functions with robust library: https://github.com/gitpython-developers/GitPython
Git Code Manager for ProjectCommand Code
This CodeDriver manages source control management for the project using git
"""

def __init__(self, filepath, execpath, remote_url=None):
Expand Down Expand Up @@ -42,7 +43,7 @@ def __init__(self, filepath, execpath, remote_url=None):
out.split()[2]))

# TODO: handle multiple remote urls
self.git_host_manager = GitHostManager()
self.git_host_manager = GitHostDriver()

self._is_initialized = self.is_initialized

Expand Down Expand Up @@ -596,7 +597,7 @@ def checkout_code_ref(self, code_id, remote=False):
(code_id, str(e))))


class GitHostManager(object):
class GitHostDriver(object):

def __init__(self, home=os.path.expanduser("~"), host="github"):
self.home = home
Expand Down
26 changes: 14 additions & 12 deletions datmo/controller/code/driver/test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
import os
import shutil
import tempfile
from datmo.controller.code.driver.git import GitCodeManager, \
GitHostManager

class TestGitManager():
from datmo.controller.code.driver.git import GitCodeDriver, \
GitHostDriver


class TestGitCodeDriver():
"""
Checks all functions of the GitCodeManager
Checks all functions of the GitCodeDriver
"""
def setup_method(self):
self.temp_dir = tempfile.mkdtemp(dir="/tmp/")
self.git_code_manager = GitCodeManager(filepath=self.temp_dir, execpath="git")
self.git_code_manager = GitCodeDriver(filepath=self.temp_dir, execpath="git")

def teardown_method(self):
shutil.rmtree(self.temp_dir)
Expand All @@ -31,7 +33,7 @@ def test_init(self):

def test_init_then_instantiation(self):
self.git_code_manager.init()
another_git_code_manager = GitCodeManager(filepath=self.temp_dir, execpath="git")
another_git_code_manager = GitCodeDriver(filepath=self.temp_dir, execpath="git")
result = another_git_code_manager.is_initialized
assert result == True

Expand Down Expand Up @@ -312,9 +314,9 @@ def test_checkout_code_ref(self):



class TestGitHostManager():
class TestGitHostDriver():
"""
Checks all functions of the GitHostManager
Checks all functions of the GitHostDriver
"""
def setup_class(self):
self.netrc_temp_dir = tempfile.mkdtemp("netrc_test")
Expand All @@ -325,22 +327,22 @@ def teardown_class(self):
shutil.rmtree(os.path.join(self.ssh_temp_dir))

def test_netrc(self):
hostm = GitHostManager(self.netrc_temp_dir)
hostm = GitHostDriver(self.netrc_temp_dir)
assert hostm.create_git_netrc("foobar","foo")
hostm = GitHostManager(self.netrc_temp_dir)
hostm = GitHostDriver(self.netrc_temp_dir)
assert os.path.exists(os.path.join(self.netrc_temp_dir, ".netrc"))
assert hostm.https_enabled

def test_ssh_git(self):
hostm = GitHostManager(self.ssh_temp_dir)
hostm = GitHostDriver(self.ssh_temp_dir)
assert hostm.ssh_enabled == False
# If id_rsa already synced with remote account
# if os.path.join(os.path.expanduser("~"), ".ssh", "id_rsa"):
# shutil.copytree(
# os.path.join(os.path.expanduser("~"), ".ssh"),
# os.path.join(self.ssh_temp_dir,".ssh"))
# assert os.path.exists(os.path.join(self.ssh_temp_dir, ".ssh", "id_rsa"))
# hostm = GitHostManager(self.ssh_temp_dir)
# hostm = GitHostDriver(self.ssh_temp_dir)
# assert hostm.ssh_enabled == True


7 changes: 3 additions & 4 deletions datmo/controller/environment/driver/dockerenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
import os
import shutil
import subprocess

from datmo.util.i18n import get as _
from docker import DockerClient

from datmo.util.i18n import get as _
from datmo.util.exceptions import DoesNotExistException, \
EnvironmentInitFailed, EnvironmentExecutionException


class DockerEnvironmentManager(object):
class DockerEnvironmentDriver(object):
"""
This Environment Manager handles Environment management in the Datmo Project using Docker
This EnvironmentDriver handles environment management in the project using docker
"""

def __init__(self, filepath="", docker_execpath="docker", docker_socket="unix:///var/run/docker.sock"):
Expand Down
8 changes: 4 additions & 4 deletions datmo/controller/environment/driver/test/test_dockerenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
import tempfile
import shutil
import uuid
from ..dockerenv import DockerEnvironmentManager

from datmo.controller.environment.driver.dockerenv import DockerEnvironmentDriver
from datmo.util.exceptions import EnvironmentInitFailed


class TestDockerEnv():
# TODO: Add more cases for each test
"""
Checks all functions of the DockerEnvironmentManager
Checks all functions of the DockerEnvironmentDriver
"""
def setup_method(self):
self.temp_dir = tempfile.mkdtemp(dir="/tmp/")
self.docker_environment_manager = \
DockerEnvironmentManager(self.temp_dir, 'docker',
DockerEnvironmentDriver(self.temp_dir, 'docker',
'unix:///var/run/docker.sock')
self.init_result = self.docker_environment_manager.init()
random_text = str(uuid.uuid1())
Expand All @@ -41,7 +41,7 @@ def test_instantiation_and_connected(self):
def test_instantiation_not_connected(self):
thrown = False
try:
DockerEnvironmentManager(self.temp_dir, 'docker','unix:///var/run/fooo')
DockerEnvironmentDriver(self.temp_dir, 'docker', 'unix:///var/run/fooo')
except EnvironmentInitFailed:
thrown = True
assert thrown
Expand Down

0 comments on commit 953b48d

Please sign in to comment.