Skip to content

Commit

Permalink
Merge pull request #70 from pennyfx/new_logger_2
Browse files Browse the repository at this point in the history
Added datmo.core.util.logger
  • Loading branch information
asampat3090 committed May 5, 2018
2 parents 28741ef + cee354e commit f75cd9a
Show file tree
Hide file tree
Showing 33 changed files with 500 additions and 83 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ script:
- bash devtools/travis-ci/test_format_code.sh
after_success:
- echo $TRAVIS_SECURE_ENV_VARS
- coveralls
- coveralls
env:
- LOGGING_LEVEL=DEBUG
15 changes: 14 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Datmo

Guidelines for contributors coming soon.
Guidelines for contributors coming soon.

## Code Style Guidelines
Datmo uses [yapf](https://github.com/google/yapf) to autoformat code.
Expand All @@ -11,6 +11,19 @@ cd <git_root>
yapf -i <python_files changed>
```

If you're using Visual Studio Code and want to run `yapf -i [filename]` on save, install the [Run on Save] extension.(https://marketplace.visualstudio.com/items?itemName=emeraldwalk.RunOnSave)

```json
"emeraldwalk.runonsave": {
"commands": [
{
"match":"\\.py$",
"cmd":"yapf -i ${file}"
}
]
}
```

Our integration tests will fail if code is not formatted correctly

## Documentation Style Guidelines
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ install:
test_script:
- "%PYTHON%/Scripts/pip.exe --version"
- "%PYTHON%/Scripts/pytest "
environment:
- LOGGING_LEVEL=DEBUG
3 changes: 2 additions & 1 deletion datmo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
from __future__ import print_function

import datmo.snapshot
import datmo.task
import datmo.task
import datmo.config
12 changes: 7 additions & 5 deletions datmo/cli/command/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/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
Expand All @@ -10,10 +12,10 @@ def __init__(self, home, 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.
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
Expand All @@ -22,8 +24,8 @@ def __init__(self, home, cli_helper):
3) Large Files
4) Configurations
5) Metrics
command:
command:
""")
self.subparsers = self.parser.add_subparsers(
title="commands", dest="command")
Expand Down
5 changes: 4 additions & 1 deletion datmo/cli/command/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
from datmo.core.util.i18n import get as __
from datmo.cli.command.project import ProjectCommand
from datmo.core.controller.task import TaskController
from datmo.core.util.logger import DatmoLogger


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

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")
Expand Down Expand Up @@ -97,7 +99,8 @@ def run(self, **kwargs):
try:
updated_task_obj = self.task_controller.run(
task_obj.id, snapshot_dict=snapshot_dict)
except:
except Exception as e:
self.logger.error("%s %s" % (e, task_dict))
self.cli_helper.echo(__("error", "cli.task.run", task_obj.id))
return False
return updated_task_obj
Expand Down
4 changes: 2 additions & 2 deletions datmo/cli/command/tests/test_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from datmo.cli.driver.helper import Helper
from datmo.cli.command.project import ProjectCommand
from datmo.cli.command.snapshot import SnapshotCommand
from datmo.core.util.exceptions import ProjectNotInitializedException, \
MutuallyExclusiveArguments
from datmo.core.util.exceptions import (ProjectNotInitializedException,
MutuallyExclusiveArguments)


class TestSnapshot():
Expand Down
18 changes: 16 additions & 2 deletions datmo/cli/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
#!/usr/bin/python

import os
import sys

from datmo.core.util.i18n import get as __
from datmo.cli.driver.helper import Helper
from datmo.cli.command.base import BaseCommand
from datmo.cli.driver.helper import Helper
from datmo.core.util.exceptions import CLIArgumentException
from datmo.core.util.i18n import get as __
from datmo.core.util.logger import DatmoLogger
from datmo.config import Config

#from datmo.core.util.misc_functions import get_logger, create_logger


def main():
cli_helper = Helper()
# Config is required to run first so it can
# initialize/find datmo home directory (.datmo)
# This is required for logging to place the logs in a
# place for the user.
config = Config()

log = DatmoLogger.get_logger(__name__)
log.info("handling command %s", config.home)

# parse_args defaults to [1:] for args, but you need to
# exclude the rest of the args too, or validation will fail
Expand Down
48 changes: 48 additions & 0 deletions datmo/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/python

import logging
from datmo.core.util.logger import DatmoLogger


class Config(object):
"""Datmo Config properties
Parameters
----------
home : string
project home directory
logging_level : int
logging level
Returns
-------
Config
Config Singleton
"""

instance = None

class __InternalConfig:
def __init__(self):
self._home = None
self.logging_level = logging.DEBUG
DatmoLogger.get_logger(__name__).info("initalizing")

@property
def home(self):
return self._home

@home.setter
def home(self, home_path):
self._home = home_path

def __new__(cls): # __new__ always a classmethod
if not Config.instance:
Config.instance = Config.__InternalConfig()
return Config.instance

def __getattr__(self, name):
return getattr(self.instance, name)

def __setattr__(self, name, value):
return setattr(self.instance, name, value)
4 changes: 2 additions & 2 deletions datmo/core/controller/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from datmo.core.util.i18n import get as __
from datmo.core.util import get_class_contructor
from datmo.core.util.json_store import JSONStore
from datmo.core.util.exceptions import InvalidProjectPathException, \
DatmoModelNotInitializedException
from datmo.core.util.exceptions import (InvalidProjectPathException,
DatmoModelNotInitializedException)


class BaseController(object):
Expand Down
9 changes: 4 additions & 5 deletions datmo/core/controller/code/driver/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
from giturlparse import parse

from datmo.core.util.i18n import get as __
from datmo.core.util.exceptions import PathDoesNotExist,\
GitUrlArgumentException, GitExecutionException, \
FileIOException, GitCommitDoesNotExist, \
DatmoFolderInWorkTree
from datmo.core.util.exceptions import (
PathDoesNotExist, GitUrlArgumentException, GitExecutionException,
FileIOException, GitCommitDoesNotExist, DatmoFolderInWorkTree)
from datmo.core.controller.code.driver import CodeDriver


Expand Down Expand Up @@ -330,7 +329,7 @@ def commit(self, options):
Parameters
----------
options: list
options: list
List of strings for the command (e.g. ["-m", "hello"])
Returns
Expand Down
10 changes: 5 additions & 5 deletions datmo/core/controller/code/driver/tests/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
except NameError:
to_unicode = str

from datmo.core.controller.code.driver.git import GitCodeDriver, \
GitHostDriver
from datmo.core.util.exceptions import GitCommitDoesNotExist, \
PathDoesNotExist, GitExecutionException, \
DatmoFolderInWorkTree
from datmo.core.controller.code.driver.git import (GitCodeDriver,
GitHostDriver)
from datmo.core.util.exceptions import (
GitCommitDoesNotExist, PathDoesNotExist, GitExecutionException,
DatmoFolderInWorkTree)


class TestGitCodeDriver():
Expand Down
6 changes: 2 additions & 4 deletions datmo/core/controller/code/tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
to_unicode = str

from datmo.core.controller.project import ProjectController
from datmo.core.controller.code.code import \
CodeController
from datmo.core.util.exceptions import EntityNotFound, \
GitCommitDoesNotExist
from datmo.core.controller.code.code import CodeController
from datmo.core.util.exceptions import (EntityNotFound, GitCommitDoesNotExist)


class TestCodeController():
Expand Down
8 changes: 4 additions & 4 deletions datmo/core/controller/environment/driver/dockerenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from docker import DockerClient

from datmo.core.util.i18n import get as __
from datmo.core.util.exceptions import PathDoesNotExist, \
EnvironmentDoesNotExist, EnvironmentInitFailed, \
EnvironmentExecutionException, FileAlreadyExistsException, \
EnvironmentRequirementsCreateException
from datmo.core.util.exceptions import (
PathDoesNotExist, EnvironmentDoesNotExist, EnvironmentInitFailed,
EnvironmentExecutionException, FileAlreadyExistsException,
EnvironmentRequirementsCreateException)
from datmo.core.controller.environment.driver import EnvironmentDriver


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
to_unicode = str

from datmo.core.controller.environment.driver.dockerenv import DockerEnvironmentDriver
from datmo.core.util.exceptions import EnvironmentInitFailed, \
FileAlreadyExistsException, EnvironmentRequirementsCreateException, \
EnvironmentDoesNotExist
from datmo.core.util.exceptions import (
EnvironmentInitFailed, FileAlreadyExistsException,
EnvironmentRequirementsCreateException, EnvironmentDoesNotExist)


class TestDockerEnv():
Expand Down
4 changes: 2 additions & 2 deletions datmo/core/controller/environment/tests/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from datmo.core.controller.project import ProjectController
from datmo.core.controller.environment.environment import \
EnvironmentController
from datmo.core.util.exceptions import EntityNotFound, \
PathDoesNotExist, EnvironmentDoesNotExist
from datmo.core.util.exceptions import (EntityNotFound, PathDoesNotExist,
EnvironmentDoesNotExist)


class TestEnvironmentController():
Expand Down
4 changes: 2 additions & 2 deletions datmo/core/controller/file/driver/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
to_unicode = str

from datmo.core.util.i18n import get as __
from datmo.core.util.exceptions import PathDoesNotExist, \
FileIOException, FileStructureException
from datmo.core.util.exceptions import (PathDoesNotExist, FileIOException,
FileStructureException)
from datmo.core.controller.file.driver import FileDriver


Expand Down
4 changes: 2 additions & 2 deletions datmo/core/controller/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from datmo.core.controller.base import BaseController
from datmo.core.entity.model import Model
from datmo.core.entity.session import Session
from datmo.core.util.exceptions import SessionDoesNotExistException, \
RequiredArgumentMissing
from datmo.core.util.exceptions import (SessionDoesNotExistException,
RequiredArgumentMissing)


class ProjectController(BaseController):
Expand Down
3 changes: 1 addition & 2 deletions datmo/core/controller/session.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from datmo.core.controller.base import BaseController
from datmo.core.util.i18n import get as __
from datmo.core.util.exceptions import EntityNotFound, \
InvalidOperation
from datmo.core.util.exceptions import (EntityNotFound, InvalidOperation)


class SessionController(BaseController):
Expand Down
6 changes: 3 additions & 3 deletions datmo/core/controller/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from datmo.core.entity.snapshot import Snapshot
from datmo.core.util.i18n import get as __
from datmo.core.util.json_store import JSONStore
from datmo.core.util.exceptions import FileIOException, RequiredArgumentMissing, \
ProjectNotInitializedException, SessionDoesNotExistException, EntityNotFound, \
TaskNotComplete
from datmo.core.util.exceptions import (
FileIOException, RequiredArgumentMissing, ProjectNotInitializedException,
SessionDoesNotExistException, EntityNotFound, TaskNotComplete)


class SnapshotController(BaseController):
Expand Down
5 changes: 3 additions & 2 deletions datmo/core/controller/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from datmo.core.controller.environment.environment import EnvironmentController
from datmo.core.controller.snapshot import SnapshotController
from datmo.core.entity.task import Task
from datmo.core.util.exceptions import TaskRunException, RequiredArgumentMissing, \
ProjectNotInitializedException, PathDoesNotExist
from datmo.core.util.exceptions import (
TaskRunException, RequiredArgumentMissing, ProjectNotInitializedException,
PathDoesNotExist)


class TaskController(BaseController):
Expand Down
8 changes: 4 additions & 4 deletions datmo/core/controller/tests/test_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
from datmo.core.controller.project import ProjectController
from datmo.core.controller.snapshot import SnapshotController
from datmo.core.controller.task import TaskController
from datmo.core.util.exceptions import EntityNotFound, \
EnvironmentDoesNotExist, GitCommitDoesNotExist, \
SessionDoesNotExistException, RequiredArgumentMissing, \
TaskNotComplete, InvalidArgumentType
from datmo.core.util.exceptions import (
EntityNotFound, EnvironmentDoesNotExist, GitCommitDoesNotExist,
SessionDoesNotExistException, RequiredArgumentMissing, TaskNotComplete,
InvalidArgumentType)


class TestSnapshotController():
Expand Down
7 changes: 3 additions & 4 deletions datmo/core/storage/driver/blitzdb_dal_driver.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from blitzdb import Document, queryset
from datetime import datetime

from datmo.core.util.exceptions import EntityNotFound, \
EntityCollectionNotFound, IncorrectTypeException, \
InvalidArgumentType, RequiredArgumentMissing
from datmo.core.util.exceptions import (
EntityNotFound, EntityCollectionNotFound, IncorrectTypeException,
InvalidArgumentType, RequiredArgumentMissing)
from datmo.core.storage.driver import DALDriver


class BlitzDBDALDriver(DALDriver):
def __init__(self, driver_type, connection_string):
super(BlitzDBDALDriver, self).__init__()
self.database_name = 'datmo_db'

if driver_type == "file":
from blitzdb import FileBackend
self.backend = FileBackend(connection_string)
Expand Down

0 comments on commit f75cd9a

Please sign in to comment.