Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traits, basic documents, utility fields. #26

Merged
merged 106 commits into from
May 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
e41dc98
Merge branch 'release/1.0.0'
amcgregor Nov 21, 2016
9d2996e
Merge branch 'develop'
amcgregor Nov 28, 2016
af0020b
Merge branch 'develop'
amcgregor Nov 28, 2016
f579bfa
String stripping and case conversion.
amcgregor Jan 3, 2017
49dee18
Markdown field.
amcgregor Jan 3, 2017
b16635a
Core traits.
amcgregor Jan 3, 2017
bb71a4e
utcnow shortcut.
amcgregor Jan 3, 2017
3f11577
"Basic" document classes.
amcgregor Jan 3, 2017
6dd177e
Simplification.
amcgregor Jan 5, 2017
e0507e5
Add Derived trait, temporarily deactivate Owned trait.
amcgregor Feb 1, 2017
41c6e8a
Owned, Identified, Localized, and Derived traits.
amcgregor Feb 1, 2017
87bc49b
Merge branch 'master' into feature/traits
amcgregor Feb 1, 2017
63efa4d
Corrections for modern renderer.
amcgregor Feb 1, 2017
af2c998
Added Identified trait registration.
amcgregor Feb 1, 2017
079f64f
Path field.
amcgregor Feb 1, 2017
07b3b06
Cleanup.
amcgregor Feb 1, 2017
cda6067
Updated pre-commit config.
amcgregor Feb 3, 2017
69e9c86
Make use of Path field, pass through keyword args.
amcgregor Feb 3, 2017
5d9d8aa
Cleanup.
amcgregor Feb 17, 2017
82af703
Generalized programmers' representation.
amcgregor Feb 17, 2017
2d5db4f
Automatic calculation of import reference.
amcgregor Feb 17, 2017
db16fde
Improved minifying plugin name lookup for PluginReference fields.
amcgregor Feb 17, 2017
8c99f0f
Cleanup.
amcgregor Feb 17, 2017
5f89ec5
Armour against version differences.
amcgregor Feb 17, 2017
c78db6a
Armour against version differences.
amcgregor Feb 17, 2017
cc66120
Test fixes, again preserves the ability to read/write field attribute…
amcgregor Feb 17, 2017
7fb3a6f
Test corrections.
amcgregor Feb 18, 2017
efdb5ea
Full document test coverage.
amcgregor Feb 19, 2017
fb73f20
Collation testing is hard if Travis runs old MongoDB.
amcgregor Feb 19, 2017
e97b84a
Markdown field simplification.
amcgregor Feb 19, 2017
4345604
Force update cffi for pypy.
amcgregor Feb 19, 2017
684c363
Need newer version of Pypy on Travis.
amcgregor Feb 19, 2017
9189326
Cleanup.
amcgregor Feb 19, 2017
b04fdbe
To-Markdown protocol support.
amcgregor Feb 19, 2017
7483212
Added Path field tests.
amcgregor Feb 19, 2017
91da02c
Removal of debugging code.
amcgregor Feb 19, 2017
e79fd97
Attribute adjustment correction.
amcgregor Feb 19, 2017
26b5b31
Utility test coverage.
amcgregor Feb 19, 2017
b22e344
Test error condition.
amcgregor Feb 19, 2017
4b403fb
Derived trait tests.
amcgregor Feb 19, 2017
83f2810
Expires trait tests, logic corrections, and consistent use of TZ-awar…
amcgregor Feb 19, 2017
c0f92d9
Non-written defualt of None, additional test coverage.
amcgregor Feb 19, 2017
4e5001d
Added query fragment generator.
amcgregor Feb 20, 2017
4884bb0
Adjustments to $and merging.
amcgregor Feb 20, 2017
ffd5e94
Logic correction, tests for publication test.
amcgregor Feb 20, 2017
46f84b2
Published tests, query generation.
amcgregor Feb 20, 2017
05606c5
Remove Owned trait; it's silly.
amcgregor Feb 20, 2017
8a9c5e9
Added missing $and tests.
amcgregor Feb 21, 2017
5cbfcfe
Add Translated field reference.
amcgregor Feb 21, 2017
58329ce
Switch test logging capture plugin to eliminate warnings.
amcgregor Feb 21, 2017
b4bdec4
Added test time step debugger integration.
amcgregor Feb 21, 2017
c7af725
Test resturcturing and temporary disabling.
amcgregor Feb 21, 2017
123bba6
Added Localized alias-alike field and blank line cleanup.
amcgregor Feb 21, 2017
7b7ff7e
Remove redundant tests.
amcgregor Feb 22, 2017
0841197
Modifications to simplify reference/nested types to single types or u…
amcgregor Feb 22, 2017
667b84e
Removal of personally useful, but not universal step debugger.
amcgregor Feb 22, 2017
df16167
Test corrections, additional coverage, dead code removal.
amcgregor Feb 22, 2017
8122eda
Full complex coverage.
amcgregor Feb 22, 2017
833271b
Add newer CPython version, skip capped collection tests on Pypy.
amcgregor Feb 22, 2017
61035c6
Make production checks too, just in case.
amcgregor Feb 22, 2017
e55c158
Nested referencing fix, test coverage.
amcgregor Feb 22, 2017
ff99196
Correctly work out dynamic document referencing for embeds, and chain…
amcgregor Feb 22, 2017
e65dec2
Re-enable disabled translatable query test.
amcgregor Feb 22, 2017
38df590
Initial "active collection" class-level query helpers.
amcgregor Mar 1, 2017
b69dab7
zomfgwtfkkkbbw ._.
amcgregor Mar 1, 2017
068451f
Reference correction.
amcgregor Mar 1, 2017
b952a7f
Correction for slightly changed exceptions.
amcgregor Mar 1, 2017
61240bd
Cleanup.
amcgregor Mar 1, 2017
07ef74a
Output cleanup.
amcgregor Mar 5, 2017
8d989ee
Parametric adjustments for expanded push with options.
amcgregor Mar 5, 2017
233ba1f
Merge branch 'develop' into feature/traits
amcgregor Mar 5, 2017
ec8e2a6
HChildren working heirarchy.
amcgregor Mar 5, 2017
083094c
Test correction.
amcgregor Mar 5, 2017
6fc3031
Updated MongoDB.
amcgregor Mar 5, 2017
c5573c4
Fill in missing blanks.
amcgregor Mar 5, 2017
1f5f814
Disable authentication.
amcgregor Mar 5, 2017
88f9bf3
Another heirarchy complete.
amcgregor Mar 7, 2017
c1389fa
Typo correction.
amcgregor Mar 7, 2017
8aef6dc
Correction for not-deep-enough reference.
amcgregor Mar 7, 2017
504f4fa
Ancestors heirarchical storage and tests.
amcgregor Mar 7, 2017
0bfe994
HPath tests, some cleanup.
amcgregor Mar 13, 2017
b171ae5
Additional attach_to test.
amcgregor Mar 13, 2017
f8bb736
HNested query tests.
amcgregor Mar 13, 2017
e017029
Nested set detachment.
amcgregor Mar 13, 2017
adfacc2
Attach (unattached bare node) and attach_to (unattached graph node) i…
amcgregor Mar 13, 2017
1d648cc
Cleanup, test naming correction.
amcgregor Mar 21, 2017
5616312
Temporarily removed heir. structures.
amcgregor May 9, 2017
c1a7e09
Swap translated (unused) for positional.
amcgregor May 9, 2017
9f1e393
Isolated active collection behaviours into own trait.
amcgregor May 9, 2017
cb3f0f1
Correction for capped collection tests.
amcgregor May 9, 2017
b1022bc
Remove Stateful trait for now, clean up docstrings.
amcgregor May 9, 2017
c20dc36
Updated docs, some minor security.
amcgregor May 9, 2017
1898e82
Test naming, coverage.
amcgregor May 10, 2017
8da81bd
Additional support for $push $each.
amcgregor May 10, 2017
ce628bd
Full parametric helper update coverage for extended $push support.
amcgregor May 10, 2017
b0fa8fa
Removed experimental "basic documents".
amcgregor May 10, 2017
b878bca
Add tests for identified document (in)equality comparison.
amcgregor May 10, 2017
79a6475
Dead code removal.
amcgregor May 10, 2017
7e6a043
Terminology change; `recreate` is now `drop`.
amcgregor May 10, 2017
e3e493d
Updated for latest usage.
amcgregor May 10, 2017
0fa9591
Array and Embed default value handling to reduce boilerplate lambdas,…
amcgregor May 10, 2017
97517da
Attempt to work around (and confirm) Pypy 5.4.1 issue.
amcgregor May 10, 2017
c33eede
Subclass MutableMapping to work around Pypy issue more fundamentally.
amcgregor May 10, 2017
a5e32e9
Remove bug-testing patch.
amcgregor May 10, 2017
224a31b
Add index drop test case.
amcgregor May 10, 2017
815c07b
Bulk of remainder of Queryable tests.
amcgregor May 10, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 30 additions & 30 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
- repo: https://github.com/pre-commit/pre-commit-hooks.git
sha: c8a1c91c762b8e24fdc5a33455ec10662f523328
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-byte-order-marker
- id: check-docstring-first
- id: check-merge-conflict
- id: check-symlinks
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: check-json
- id: check-xml
- id: check-yaml
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
sha: v1.0.9
hooks:
- id: python-safety-dependencies-check
- repo: https://github.com/Lucas-C/pre-commit-hooks-bandit
sha: v1.0.1
hooks:
- id: python-bandit-vulnerability-check
- repo: local
hooks:
- id: py.test
name: py.test
language: system
entry: sh -c py.test
files: ''
- repo: https://github.com/pre-commit/pre-commit-hooks.git
sha: 46251c9523506b68419aefdf5ff6ff2fbc4506a4
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-byte-order-marker
- id: check-docstring-first
- id: check-merge-conflict
- id: check-symlinks
- id: debug-statements
- id: detect-private-key
- id: end-of-file-fixer
- id: check-json
- id: check-xml
- id: check-yaml
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
sha: v1.1.0
hooks:
- id: python-safety-dependencies-check
- repo: https://github.com/Lucas-C/pre-commit-hooks-bandit
sha: v1.0.3
hooks:
- id: python-bandit-vulnerability-check
- repo: local
hooks:
- id: py.test
name: py.test
language: system
entry: sh -c py.test
files: ''
20 changes: 9 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ language: python
sudo: false
cache: pip

addons:
apt:
sources:
- mongodb-upstart
- mongodb-3.2-precise
packages:
- mongodb-org-server
- mongodb-org-shell

branches:
except:
- /^[^/]+/.+$/
Expand All @@ -19,13 +10,20 @@ branches:

python:
- "2.7"
- "pypy"
- "pypy-5.4.1"
- "3.3"
- "3.4"
- "3.5"
- "3.6"

before_install:
- wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.1.tgz -O /tmp/mongodb.tgz
- tar -xvf /tmp/mongodb.tgz
- mkdir /tmp/data
- ${PWD}/mongodb-linux-x86_64-3.4.1/bin/mongod --dbpath /tmp/data --bind_ip 127.0.0.1 --noauth &> /dev/null &

install:
- travis_retry pip install --upgrade setuptools pip pytest pytest-cov codecov 'setuptools_scm>=1.9'
- travis_retry pip install --upgrade setuptools pip pytest pytest-cov codecov 'setuptools_scm>=1.9' cffi
- pip install -e '.[development,logger]'

script:
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ veryclean: clean
rm -rvf *.egg-info .packaging

test: develop
./setup.py test
@clear
@pytest

release:
./setup.py register sdist bdist_wheel upload ${RELEASE_OPTIONS}
Expand Down
49 changes: 35 additions & 14 deletions example/readme.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,56 @@
# encoding: utf-8

# Imports.

from pymongo import MongoClient

from marrow.mongo import Document, Index
from marrow.mongo import Index
from marrow.mongo.field import Array, Number, ObjectId, String
from marrow.mongo.trait import Queryable


# Connect to the test database on the local machine.

db = MongoClient().test

collection = MongoClient().test.collection
collection.drop()

# Define an Account object model and associated metadata.

class Account(Document):
class Account(Queryable):
__collection__ = 'collection'

username = String(required=True)
name = String()
locale = String(default='en-CA-u-tz-cator-cu-CAD', assign=True)
age = Number()

id = ObjectId('_id', assign=True)
tag = Array(String(), default=lambda: [], assign=True)
tag = Array(String(), assign=True)

_username = Index('username', unique=True)


# Bind it to a database, then (re-)create the collection including indexes.

collection = Account.bind(db).create_collection(drop=True)


# Create a new record; this record is unsaved...

alice = Account('amcgregor', "Alice Bevan-McGregor", age=27)
print(alice.id) # Already has an ID.
print(alice.id.generation_time) # This even includes the creation time.

Account._username.create_index(collection)
print(alice.id) # It already has an ID, however!
print(alice.id.generation_time) # This includes the creation time.


# Inserting it will add it to the storage back-end; the MongoDB database.

result = alice.insert_one()

assert result.acknowledged and result.inserted_id == alice


# Now you can query Account objects for one with an appropriate username.

result = collection.insert_one(alice)
assert result.acknowledged and result.inserted_id == alice.id
record = Account.find_one(username='amcgregor')

record = collection.find_one(Account.username == 'amcgregor')
record = Account.from_mongo(record)
print(record.name) # Alice Bevan-McGregor
print(record.name) # Alice Bevan-McGregor; it's already an Account instance.
4 changes: 3 additions & 1 deletion marrow/mongo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
from .core import Document, Field, Index, __version__ # noqa
from .query import Q, Ops, Filter, Update
from .param import F, P, S, U
from .util import Registry
from .util import Registry, utcnow

document = sys.modules['marrow.mongo.document'] = Registry('marrow.mongo.document')
field = sys.modules['marrow.mongo.field'] = Registry('marrow.mongo.field')
trait = sys.modules['marrow.mongo.trait'] = Registry('marrow.mongo.trait')


__all__ = [
'Document',
Expand Down
Loading