Skip to content

Commit 1e866ed

Browse files
authored
Merge pull request #43 from davidlatwe/fix-init-bson
Fix init bson
2 parents b0c30d6 + 0c0dfb4 commit 1e866ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+428
-409
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ And this project is testing against to:
3333
pip install montydb
3434
```
3535

36-
* optional, to use `bson` in operation (`pymongo` will be installed)
36+
* optional, to use *real* `bson` in operation (`pymongo` will be installed)
37+
38+
*For minimum requirements, `montydb` ships with it's own fork of `ObjectId` in `montydb.types`, so you may ignore this option if `ObjectId` is all you need from `bson`*
3739

3840
```
3941
pip install montydb[bson]
@@ -72,7 +74,7 @@ set_storage(
7274
repository="/db/repo", # dir path for database to live on disk, default is {cwd}
7375
storage="flatfile", # storage name, default "flatfile"
7476
mongo_version="4.0", # try matching behavior with this mongodb version
75-
use_bson=False, # default None, and will try importing pymongo if None
77+
use_bson=False, # default None, and will import pymongo's bson if None or True
7678
7779
# any other kwargs are storage engine settings
7880
#

montydb/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
version_info = (2, 3, 7)
2+
version_info = (2, 3, 8)
33
__version__ = "%i.%i.%i" % version_info
44

55

montydb/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
iteritems,
2929
integer_types,
3030
string_types,
31-
bson_ as bson,
31+
bson,
3232
)
3333

3434
ASCENDING = 1

montydb/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from .engine.update import Updator
1818
from .types import (
1919
abc,
20-
bson_ as bson,
20+
bson,
2121
string_types,
2222
is_duckument_type,
2323
Counter,

montydb/configure.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
_session = {}
2626
_session_default = {
2727
"mongo_version": "4.2",
28-
"use_bson": False,
28+
"use_bson": None,
2929
}
3030
# TODO:
3131
# The mongo version compating may fail if calling `set_storage()` multiple
@@ -194,13 +194,13 @@ def set_storage(
194194
mongo_version (str, optional): Which mongodb version's behavior should
195195
montydb try to match with. Default "4.2", other versions are "3.6",
196196
"4.0".
197-
use_bson (bool, optional): Use bson module. Default `False`.
197+
use_bson (bool, optional): Use bson module. Default `None`.
198198
199199
keyword args:
200200
Other keyword args will be parsed as storage config options.
201201
202202
"""
203-
from .types import bson_ as bson
203+
from .types import bson
204204

205205
storage = storage or DEFAULT_STORAGE
206206

@@ -267,20 +267,26 @@ def provide_storage(repository):
267267

268268

269269
def _bson_init(use_bson):
270-
from .types import bson_ as bson
270+
from .types import bson
271271

272-
if bson.bson_used and not use_bson:
272+
if bson.bson_used is None:
273+
bson.init(use_bson)
274+
275+
elif bson.bson_used and not use_bson:
273276
raise ConfigurationError(
274277
"montydb has been config to use BSON and "
275278
"cannot be changed in current session."
276279
)
280+
277281
elif not bson.bson_used and use_bson:
278282
raise ConfigurationError(
279283
"montydb has been config to opt-out BSON and "
280284
"cannot be changed in current session."
281285
)
286+
282287
else:
283-
bson.init(use_bson)
288+
# bson.bson_used == use_bson
289+
pass
284290

285291

286292
def _mongo_compat(version):

montydb/cursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
from .engine.queries import QueryFilter, ordering
77
from .engine.project import Projector
88
from .types import (
9+
bson,
910
RE_PATTERN_TYPE,
1011
iteritems,
1112
integer_types,
12-
bson_ as bson,
1313
)
1414
from .base import (
1515
validate_boolean,

montydb/engine/queries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
_cmp_decimal,
1313
)
1414
from ..types import (
15+
bson,
1516
RE_PATTERN_TYPE,
1617
integer_types,
1718
string_types,
18-
bson_ as bson,
1919
is_duckument_type,
2020
is_integer_type,
2121
is_pattern_type,

montydb/engine/update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .weighted import Weighted, _cmp_decimal
88
from .queries import QueryFilter, ordering
99
from ..types import (
10-
bson_ as bson,
10+
bson,
1111
string_types,
1212
is_numeric_type,
1313
is_duckument_type,

montydb/engine/weighted.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
from collections import Mapping
44

55
from ..types import (
6+
bson,
67
integer_types,
78
string_types,
8-
bson_ as bson,
99

1010
RE_PATTERN_TYPE,
1111
re_int_flag_to_str,

montydb/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
def init_bson_err():
44
import sys
5-
from .types import bson_ as bson
5+
from .types import bson
66
this = sys.modules[__name__]
77

88
class DocumentTooLarge(bson.InvalidDocument):

0 commit comments

Comments
 (0)