Skip to content

Commit b859240

Browse files
authored
Merge pull request #9 from strollby/fix/import-issues
Fix imports for backward compactibility
2 parents d918b1a + 36bc9b1 commit b859240

8 files changed

Lines changed: 74 additions & 44 deletions

File tree

mongoengine/__init__.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,16 @@
2121

2222
from mongoengine import document, errors, fields, signals
2323

24+
2425
# ---- private imports (for __all__ only) ----
25-
from mongoengine.synchronous import connection as _sync_connection
26-
from mongoengine.asynchronous import connection as _async_connection
27-
from mongoengine.synchronous import queryset as _sync_queryset
28-
from mongoengine.asynchronous import queryset as _async_queryset
26+
import mongoengine.base.queryset as _queryset_base
27+
import mongoengine.synchronous as _sync_modules
28+
import mongoengine.asynchronous as _async_modules
2929

3030
# ---- public re-exports ----
31-
from mongoengine.synchronous.connection import * # noqa: F401,F403
32-
from mongoengine.asynchronous.connection import * # noqa: F401,F403
33-
from mongoengine.synchronous.queryset import * # noqa: F401,F403
34-
from mongoengine.asynchronous.queryset import * # noqa: F401,F403
31+
from mongoengine.base.queryset import * # noqa: F401,F403
32+
from mongoengine.synchronous import * # noqa: F401,F403
33+
from mongoengine.asynchronous import * # noqa: F401,F403
3534

3635
from mongoengine.document import * # noqa: F401,F403
3736
from mongoengine.errors import * # noqa: F401,F403
@@ -42,19 +41,17 @@
4241
__all__ = (
4342
list(document.__all__)
4443
+ list(fields.__all__)
45-
+ list(_sync_connection.__all__)
46-
+ list(_async_connection.__all__)
47-
+ list(_sync_queryset.__all__)
48-
+ list(_async_queryset.__all__)
44+
+ list(_queryset_base.__all__)
45+
+ list(_sync_modules.__all__)
46+
+ list(_async_modules.__all__)
4947
+ list(signals.__all__)
5048
+ list(errors.__all__)
5149
)
5250

5351
# ---- hide internals ----
54-
del _sync_connection
55-
del _async_connection
56-
del _sync_queryset
57-
del _async_queryset
52+
del _queryset_base
53+
del _sync_modules
54+
del _async_modules
5855

5956
VERSION = (0, 30, 0)
6057

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
from .connection import *
2-
from .queryset import *
1+
import mongoengine.asynchronous.connection as _connection
32

4-
__all__ = [
5-
list(connection.__all__) + list(queryset.__all__),
6-
]
3+
from .connection import * # noqa: F401,F403
4+
from .queryset import ( # noqa: F401,F403
5+
AsyncQuerySet,
6+
AsyncQuerySetNoCache,
7+
queryset as _queryset,
8+
)
9+
10+
__all__ = list(_connection.__all__) + list(_queryset.__all__)
11+
12+
del _queryset
13+
del _connection

mongoengine/asynchronous/connection.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
from pymongo.errors import ConnectionFailure
77

88
import mongoengine
9-
from mongoengine.common import _check_db_name, convert_read_preference
9+
from mongoengine.common import (
10+
_check_db_name,
11+
convert_read_preference,
12+
DEFAULT_CONNECTION_NAME,
13+
DEFAULT_DATABASE_NAME,
14+
DEFAULT_HOST,
15+
DEFAULT_PORT,
16+
)
1017

1118
__all__ = [
1219
"async_connect",
@@ -15,15 +22,12 @@
1522
"async_get_connection",
1623
"async_get_db",
1724
"async_register_connection",
25+
"DEFAULT_CONNECTION_NAME",
26+
"DEFAULT_DATABASE_NAME",
1827
]
1928

2029
from mongoengine.registry import _CollectionRegistry
2130

22-
DEFAULT_CONNECTION_NAME = "default"
23-
DEFAULT_DATABASE_NAME = "test"
24-
DEFAULT_HOST = "localhost"
25-
DEFAULT_PORT = 27017
26-
2731
READ_PREFERENCE = ReadPreference.PRIMARY
2832

2933
_connection_settings = {}
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
from .constants import *
2-
from .visitor import *
3-
from .transform import *
42
from .field_list import *
53
from .manager import *
4+
from .transform import *
5+
from .visitor import *
66

77
# Expose just the public subset of all imported objects and constants.
88
__all__ = (
9-
list(constants.__all__)
10-
+ list(visitor.__all__)
11-
+ list(transform.__all__)
12-
+ list(field_list.__all__)
13-
+ list(manager.__all__)
9+
"Q",
10+
"queryset_manager",
11+
"QuerySetManager",
12+
"QueryFieldList",
13+
"DO_NOTHING",
14+
"NULLIFY",
15+
"CASCADE",
16+
"DENY",
17+
"PULL",
1418
)

mongoengine/common.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
Nearest,
88
)
99

10+
DEFAULT_CONNECTION_NAME = "default"
11+
DEFAULT_DATABASE_NAME = "test"
12+
DEFAULT_HOST = "localhost"
13+
DEFAULT_PORT = 27017
14+
1015
_class_registry_cache = {}
1116
_field_list_cache = []
1217

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
from .connection import *
2-
from .queryset import *
1+
import mongoengine.synchronous.connection as _connection
32

4-
__all__ = [
5-
list(connection.__all__) + list(queryset.__all__),
6-
]
3+
from .connection import * # noqa: F401,F403
4+
from .queryset import ( # noqa: F401,F403
5+
QuerySet,
6+
QuerySetNoCache,
7+
queryset as _queryset,
8+
)
9+
10+
__all__ = list(_connection.__all__) + list(_queryset.__all__)
11+
12+
del _queryset
13+
del _connection

mongoengine/synchronous/connection.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
from pymongo.errors import ConnectionFailure
77

88
import mongoengine
9-
from mongoengine.common import _check_db_name, convert_read_preference
9+
from mongoengine.common import (
10+
_check_db_name,
11+
convert_read_preference,
12+
DEFAULT_CONNECTION_NAME,
13+
DEFAULT_DATABASE_NAME,
14+
DEFAULT_HOST,
15+
DEFAULT_PORT,
16+
)
1017

1118
__all__ = [
1219
"connect",
@@ -15,14 +22,12 @@
1522
"get_connection",
1623
"get_db",
1724
"register_connection",
25+
"DEFAULT_CONNECTION_NAME",
26+
"DEFAULT_DATABASE_NAME",
1827
]
1928

2029
from mongoengine.registry import _CollectionRegistry
2130

22-
DEFAULT_CONNECTION_NAME = "default"
23-
DEFAULT_DATABASE_NAME = "test"
24-
DEFAULT_HOST = "localhost"
25-
DEFAULT_PORT = 27017
2631

2732
READ_PREFERENCE = ReadPreference.PRIMARY
2833

tests/asynchronous/queryset/test_queryset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pymongo.results import UpdateResult
1212

1313
from mongoengine import *
14+
from mongoengine.asynchronous.queryset import AsyncBaseQuerySet
1415
from mongoengine.base import LazyReference
1516
from mongoengine.base.queryset import (
1617
CASCADE,

0 commit comments

Comments
 (0)