Skip to content

Commit

Permalink
Merge pull request #56 from numberoverzero/docs-13-reimagined
Browse files Browse the repository at this point in the history
Closes #13
  • Loading branch information
numberoverzero committed Aug 11, 2016
2 parents 78c6c43 + 772339f commit 13a17c0
Show file tree
Hide file tree
Showing 33 changed files with 1,469 additions and 2,689 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ cov:
scripts/individual_coverage.sh

docs:
rm -rf docs/_build
rm -rf docs/_build
cd docs && $(MAKE) html
firefox docs/_build/html/index.html
1 change: 1 addition & 0 deletions bloop/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def render(self, renderer):
nref = renderer.name_ref(self.column, path=self.path)
vref = renderer.value_ref(self.column, self.value,
dumped=self.dumped, path=self.path)
# TODO special handling for == and != when value dumps to None
comparator = self.comparator_strings[self.comparator]
return "({} {} {})".format(nref, comparator, vref)

Expand Down
29 changes: 8 additions & 21 deletions bloop/engine.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import collections
import collections.abc

import declare

from .client import Client
Expand All @@ -23,16 +20,6 @@
}


def set_of(objs):
"""wrap single elements in a set"""
if isinstance(objs, str): # pragma: no cover
return {objs}
elif isinstance(objs, collections.abc.Iterable):
return set(objs)
else:
return {objs}


def value_of(column):
"""value_of({'S': 'Space Invaders'}) -> 'Space Invaders'"""
return next(iter(column.values()))
Expand Down Expand Up @@ -118,7 +105,7 @@ def _update(self, obj, attrs, expected, context=None, **kwargs):
value = load(column.typedef, value, context=context, **kwargs)
setattr(obj, column.model_name, value)

def bind(self, *, base):
def bind(self, base):
"""Create tables for all models subclassing base"""
# If not manually configured, use a default bloop.Client
# with the default boto3.client("dynamodb")
Expand Down Expand Up @@ -160,8 +147,8 @@ def is_verified(model):
self.type_engine.register(column.typedef)
self.type_engine.bind(context={"engine": self})

def delete(self, objs, *, condition=None, atomic=None):
objs = set_of(objs)
def delete(self, *objs, condition=None, atomic=None):
objs = set(objs)
for obj in objs:
if obj.Meta.abstract:
raise AbstractModelException(obj)
Expand All @@ -176,7 +163,7 @@ def delete(self, objs, *, condition=None, atomic=None):
self.client.delete_item(item)
clear(obj)

def load(self, objs, consistent=None):
def load(self, *objs, consistent=None):
"""Populate objects from dynamodb, optionally using consistent reads.
If any objects are not found, raises NotModified with the attribute
Expand All @@ -203,7 +190,7 @@ class HashAndRange(bloop.new_base()):
# For an in-depth breakdown of the loading algorithm,
# see docs/dev/internal.rst::Loading
consistent = config(self, "consistent", consistent)
objs = set_of(objs)
objs = set(objs)
for obj in objs:
if obj.Meta.abstract:
raise AbstractModelException(obj)
Expand Down Expand Up @@ -260,8 +247,8 @@ def query(self, obj, consistent=None):
engine=self, mode="query", model=model, index=index, strict=self.config["strict"], select=select,
consistent=config(self, "consistent", consistent))

def save(self, objs, *, condition=None, atomic=None):
objs = set_of(objs)
def save(self, *objs, condition=None, atomic=None):
objs = set(objs)
for obj in objs:
if obj.Meta.abstract:
raise AbstractModelException(obj)
Expand All @@ -287,5 +274,5 @@ def scan(self, obj, consistent=None):
if model.Meta.abstract:
raise AbstractModelException(model)
return Filter(
engine=self, mode="query", model=model, index=index, strict=self.config["strict"], select=select,
engine=self, mode="scan", model=model, index=index, strict=self.config["strict"], select=select,
consistent=config(self, "consistent", consistent))
8 changes: 4 additions & 4 deletions bloop/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def validate_key_for(model, index, key):
class Filter:
def __init__(
self, *, engine, mode, model, index, strict, select, select_attributes=None, prefetch=0,
consistent=False, forward=True, limit=0, key=None, filter=None):
consistent=False, forward=True, limit=None, key=None, filter=None):
self.engine = engine
self.mode = mode
self.model = model
Expand All @@ -158,7 +158,7 @@ def __init__(
self._prefetch = prefetch
self._consistent = consistent
self._forward = forward
self._limit = limit
self._limit = limit or 0

self._key = key
self._filter = filter
Expand Down Expand Up @@ -390,12 +390,12 @@ def __iter__(self):
return self

def __next__(self):
# Still have buffered elements available
# still have buffered elements available
if len(self._buffer) > 0:
return self._buffer.popleft()

# Refill the buffer until we hit the limit, or Dynamo stops giving us continue tokens.
while (not self.exhausted) and (len(self._buffer) < self._prefetch):
while (not self.exhausted) and len(self._buffer) < self._prefetch:
response = self._call(self._prepared_request)
continuation_token = response.get("LastEvaluatedKey", None)
self._prepared_request["ExclusiveStartKey"] = continuation_token
Expand Down
16 changes: 3 additions & 13 deletions bloop/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,18 @@ def _bind(self, model):


class GlobalSecondaryIndex(Index):
def __init__(self, *,
hash_key=None, range_key=None, read_units=1, write_units=1, name=None, projection=None,
**kwargs):
if hash_key is None:
raise ValueError("Must specify a hash_key for a GlobalSecondaryIndex")
if projection is None:
raise INVALID_PROJECTION
def __init__(self, *, projection, hash_key, range_key=None, read_units=1, write_units=1, name=None, **kwargs):
super().__init__(hash_key=hash_key, range_key=range_key, name=name, projection=projection, **kwargs)
self.write_units = write_units
self.read_units = read_units


class LocalSecondaryIndex(Index):
""" LSIs don't have individual read/write units """
def __init__(self, *, range_key=None, name=None, projection=None, **kwargs):
# Hash key MUST be the table hash, pop any other values
def __init__(self, *, projection, range_key, name=None, **kwargs):
# Hash key MUST be the table hash; do not specify
if "hash_key" in kwargs:
raise ValueError("Can't specify the hash_key of a LocalSecondaryIndex")
if range_key is None:
raise ValueError("Must specify a range_key for a LocalSecondaryIndex")
if projection is None:
raise INVALID_PROJECTION
if ("write_units" in kwargs) or ("read_units" in kwargs):
raise ValueError("A LocalSecondaryIndex does not have its own read/write units")
super().__init__(range_key=range_key, name=name, projection=projection, **kwargs)
Expand Down
6 changes: 5 additions & 1 deletion bloop/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,16 @@ def setup_columns(meta):
raise ValueError("Model hash_key over-specified")
meta.hash_key = column
meta.keys.add(column)
elif column.range_key:
if column.range_key:
if meta.range_key:
raise ValueError("Model range_key over-specified")
meta.range_key = column
meta.keys.add(column)
column.model = meta.model
# Don't throw when they're both None (could be abstract)
# but absolutely throw when they're both the same Column instance.
if meta.hash_key and (meta.hash_key is meta.range_key):
raise ValueError("hash_key and range_key must be different columns")


def setup_indexes(meta):
Expand Down
5 changes: 2 additions & 3 deletions bloop/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@ class Model(Base):
"""
python_type = arrow.Arrow
default_timezone = "UTC"

def __init__(self, timezone=None):
self.timezone = timezone or DateTime.default_timezone
def __init__(self, timezone="utc"):
self.timezone = timezone
super().__init__()

def dynamo_load(self, value, *, context, **kwargs):
Expand Down
12 changes: 12 additions & 0 deletions docs/_static/custom.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
div.sphinxsidebar {
width: 240px;
}

/*
Changed in 1.4b1
https://github.com/sphinx-doc/sphinx/pull/2301
https://github.com/sphinx-doc/sphinx/commit/b55b690d0f808be1371d4424d758dbd446fb5b98
*/
div.body p, div.body dd, div.body li, div.body blockquote {
-moz-hyphens: manual;
-ms-hyphens: manual;
-webkit-hyphens: manual;
hyphens: manual;
}
8 changes: 7 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@
html_theme = 'alabaster'

html_theme_options = {
'github_button': 'true',
'github_user': 'numberoverzero',
'github_repo': 'bloop',
'github_banner': True,
'travis_button': True,

'github_type': 'star',
'github_count': 'true',

'fixed_sidebar': True,

'show_powered_by': False,
'analytics_id': 'UA-65843067-1'
}
Expand Down
Loading

0 comments on commit 13a17c0

Please sign in to comment.