Skip to content

Commit

Permalink
Added more documentation, enabled futures consistently across modules…
Browse files Browse the repository at this point in the history
…, and fixed some formatting errors
  • Loading branch information
fuzeman committed May 8, 2017
1 parent 7e7cf29 commit 8b2ba92
Show file tree
Hide file tree
Showing 68 changed files with 606 additions and 45 deletions.
2 changes: 2 additions & 0 deletions byte/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import, division, print_function

from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
13 changes: 9 additions & 4 deletions byte/base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
"""Base models module."""

from __future__ import absolute_import, division, print_function


class BaseExpression(object):
"""Base class for expressions."""

def execute(self, item):
"""Execute expression.
:param item: Item
:type item: byte.model.Model
"""
Expand All @@ -15,18 +20,18 @@ class BaseProperty(object):

def get(self, obj):
"""Get property value from object.
:param obj: Item
:type obj: byte.model.Model
"""
raise NotImplementedError

def set(self, obj, value):
"""Set property value on object.
:param obj: Item
:type obj: byte.model.Model
:param value: Value
:type value: any
"""
Expand Down
8 changes: 5 additions & 3 deletions byte/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

"""Contains the collection structure for the storage of keyed items."""

from __future__ import absolute_import, division, print_function

from byte.core.plugin.manager import PluginManager
from byte.executors.core.base import Executor
from byte.model import Model
Expand All @@ -24,7 +26,7 @@ class CollectionLoadError(CollectionError):


class CollectionModelError(CollectionError):
""""Collection model violation."""
"""Collection model violation."""


class CollectionParseError(CollectionError):
Expand All @@ -47,10 +49,10 @@ def __init__(self, model_or_uri=None, uri=None, model=None, executor=None, plugi
:param model: Collection data model
:type model: class
:param executor: Collection executor
:type executor: byte.executors.core.base.Executor or type
:param plugins: List of plugins to enable for the collection (if :code:`None` is provided
all plugins will be enabled)
:type plugins: list
Expand Down
2 changes: 2 additions & 0 deletions byte/compilers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import, division, print_function

from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
3 changes: 3 additions & 0 deletions byte/compilers/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Core compilers package."""

from __future__ import absolute_import, division, print_function
4 changes: 4 additions & 0 deletions byte/compilers/core/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""Base compiler module."""

from __future__ import absolute_import, division, print_function

from byte.core.helpers.resolve import resolve_tuples
from byte.core.helpers.validate import is_list_of
from byte.core.plugin.base import Plugin
Expand Down
5 changes: 5 additions & 0 deletions byte/compilers/core/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""Compiler models module."""

from __future__ import absolute_import, division, print_function


class Operation(object):
pass

Expand Down
2 changes: 2 additions & 0 deletions byte/compilers/operation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Operation compiler module."""

from __future__ import absolute_import, division, print_function

from byte.compilers.core.base import CompilerPlugin
Expand Down
3 changes: 3 additions & 0 deletions byte/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Core package."""

from __future__ import absolute_import, division, print_function
3 changes: 3 additions & 0 deletions byte/core/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Byte helpers package."""

from __future__ import absolute_import, division, print_function
26 changes: 26 additions & 0 deletions byte/core/helpers/resolve.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
"""Resolve helper functions module."""

from __future__ import absolute_import, division, print_function


def resolve_list(value):
"""Resolve list (convert provided value if not list).
:param value: Value
:type value: any
"""
if value is None:
return []

Expand All @@ -9,6 +19,14 @@ def resolve_list(value):


def resolve_tuple(value, default=None):
"""Resolve tuple (convert provided value if not tuple).
:param value: Value
:type value: any
:param default: Default tuple function
:type default: function
"""
if value is None:
return tuple()

Expand All @@ -23,6 +41,14 @@ def resolve_tuple(value, default=None):


def resolve_tuples(items, default=None):
"""Resolve list of tuples (convert provided value if not list of tuples).
:param items: Value
:type items: any
:param default: Default tuple function
:type default: function
"""
if items is None:
return []

Expand Down
21 changes: 21 additions & 0 deletions byte/core/helpers/validate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
"""Validation helper functions module."""

from __future__ import absolute_import, division, print_function


def is_list_of(items, value_type):
"""Validate list :code:`items` match :code:`value_type`.
:param items: Items
:type items: list
:param value_type: Value type
:type value_type: class
"""
if not isinstance(items, list):
return False

Expand All @@ -14,6 +27,14 @@ def match():


def is_tuple_of(items, value_type):
"""Validate tuple :code:`items` match :code:`value_type`.
:param items: Items
:type items: tuple
:param value_type: Value type
:type value_type: class
"""
if not isinstance(items, tuple):
return False

Expand Down
22 changes: 21 additions & 1 deletion byte/core/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
from byte.core.models.reader import Reader
"""Core models package."""

from __future__ import absolute_import, division, print_function

from byte.core.models.task.base import Task, ReadTask, SelectTask, WriteTask
from byte.core.models.task.simple import SimpleTask, SimpleReadTask, SimpleSelectTask, SimpleWriteTask
from byte.core.models.task.stream import StreamTask, StreamReadTask, StreamSelectTask, StreamWriteTask

__all__ = (
'Task',
'ReadTask',
'SelectTask',
'WriteTask',

'SimpleTask',
'SimpleReadTask',
'SimpleSelectTask',
'SimpleWriteTask',

'StreamTask',
'StreamReadTask',
'StreamSelectTask',
'StreamWriteTask'
)
3 changes: 3 additions & 0 deletions byte/core/models/task/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Task model package."""

from __future__ import absolute_import, division, print_function
11 changes: 10 additions & 1 deletion byte/core/models/task/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""Task base module."""

from __future__ import absolute_import, division, print_function

__all__ = (
'Task',
'ReadTask',
Expand All @@ -9,7 +13,7 @@ class Task(object):
class State(object):
created = 0
started = 1
closed = 2
closed = 2 # noqa

def __init__(self, executor):
self.executor = executor
Expand All @@ -35,18 +39,23 @@ def state(self):
raise NotImplementedError

def open(self):
"""Open task."""
raise NotImplementedError

def execute(self):
"""Execute task."""
raise NotImplementedError

def close(self):
"""Close task."""
raise NotImplementedError

def __enter__(self):
"""Enter task context (execute task)."""
return self

def __exit__(self, exc_type, exc_val, exc_tb):
"""Exit task context (close task)."""
self.close()


Expand Down
4 changes: 4 additions & 0 deletions byte/core/models/task/simple.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""Simple task module."""

from __future__ import absolute_import, division, print_function

from byte.compilers.core.models import InsertOperation
from byte.core.models.task.base import Task, ReadTask, SelectTask, WriteTask

Expand Down
4 changes: 4 additions & 0 deletions byte/core/models/task/stream.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""Stream task module."""

from __future__ import absolute_import, division, print_function

from byte.core.models.task.base import Task
from byte.core.models.task.simple import SimpleTask, SimpleReadTask, SimpleSelectTask, SimpleWriteTask

Expand Down
3 changes: 3 additions & 0 deletions byte/core/plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Plugin package."""

from __future__ import absolute_import, division, print_function
11 changes: 8 additions & 3 deletions byte/core/plugin/base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""Plugin base module."""

from __future__ import absolute_import, division, print_function


class Plugin(object):
class Meta(object):
kind = None
Expand All @@ -11,6 +16,6 @@ def validate(cls, plugin):
return True

class Priority(object):
Low = 1000
Medium = 0
High = -1000
Low = 1000 # noqa
Medium = 0 # noqa
High = -1000 # noqa
10 changes: 7 additions & 3 deletions byte/core/plugin/manager.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from byte.core.plugin.base import Plugin
"""Plugin manager module."""

from __future__ import absolute_import, division, print_function

from byte import __path__ as byte_path
from byte.compilers.core.base import CompilerPlugin
from byte.core.plugin.base import Plugin
from byte.executors.core.base import ExecutorPlugin
from byte.formats.core.base import CollectionFormatPlugin, DocumentFormatPlugin
import byte

import imp
import inspect
Expand Down Expand Up @@ -48,7 +52,7 @@ def __init__(self, modules=None):
def discover(self, packages=('compilers', 'executors', 'formats')):
scanned_paths = set()

for search_path in byte.__path__:
for search_path in byte_path:
search_path = os.path.normcase(os.path.normpath(
os.path.realpath(search_path)
))
Expand Down
4 changes: 4 additions & 0 deletions byte/executors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""Executors package."""

from __future__ import absolute_import, division, print_function

from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
3 changes: 3 additions & 0 deletions byte/executors/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""Executors core package."""

from __future__ import absolute_import, division, print_function
15 changes: 15 additions & 0 deletions byte/executors/core/base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
"""Executor base package."""

from __future__ import absolute_import, division, print_function

from byte.executors.core.base.executor import Executor, ExecutorPlugin
from byte.executors.core.base.format import FormatExecutor, FormatExecutorPlugin
from byte.executors.core.base.simple import SimpleExecutor, SimpleExecutorPlugin

__all__ = (
'Executor',
'ExecutorPlugin',

'FormatExecutor',
'FormatExecutorPlugin',

'SimpleExecutor',
'SimpleExecutorPlugin'
)
4 changes: 4 additions & 0 deletions byte/executors/core/base/executor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""Executor base module."""

from __future__ import absolute_import, division, print_function

from byte.core.helpers.resolve import resolve_tuples
from byte.core.helpers.validate import is_list_of
from byte.core.plugin.base import Plugin
Expand Down
4 changes: 4 additions & 0 deletions byte/executors/core/base/format.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""Format base module."""

from __future__ import absolute_import, division, print_function

from byte.executors.core.base.simple import SimpleExecutor, SimpleExecutorPlugin


Expand Down
4 changes: 4 additions & 0 deletions byte/executors/core/base/simple.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""Simple executor base module."""

from __future__ import absolute_import, division, print_function

from byte.executors.core.base.executor import Executor, ExecutorPlugin


Expand Down
8 changes: 8 additions & 0 deletions byte/executors/core/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
"""Executor models package."""

from __future__ import absolute_import, division, print_function

from byte.executors.core.models.revision import Revision

__all__ = (
'Revision',
)
Loading

0 comments on commit 8b2ba92

Please sign in to comment.