|
1 | | -# Import submodules so that we can expose their __all__ |
2 | | -from mongoengine import ( |
3 | | - document, |
4 | | - errors, |
5 | | - fields, |
6 | | - signals, |
7 | | -) |
8 | | -from mongoengine.synchronous import connection |
9 | | -from mongoengine.base import queryset |
10 | | - |
11 | | -# Import everything from each submodule so that it can be accessed via |
12 | | -# mongoengine, e.g. instead of `from mongoengine.connection import connect`, |
13 | | -# users can simply use `from mongoengine import connect`, or even |
14 | | -# `from mongoengine import *` and then `connect('testdb')`. |
15 | | -from mongoengine.synchronous.connection import * # noqa: F401 |
16 | | -from mongoengine.document import * # noqa: F401 |
17 | | -from mongoengine.errors import * # noqa: F401 |
18 | | -from mongoengine.fields import * # noqa: F401 |
19 | | -from mongoengine.signals import * # noqa: F401 |
| 1 | +""" |
| 2 | +MongoEngine top-level public API. |
| 3 | +
|
| 4 | +Import submodules and re-export their public symbols so that users can write: |
| 5 | +
|
| 6 | + from mongoengine import connect |
| 7 | + from mongoengine import async_connect |
| 8 | + from mongoengine import Document, StringField |
| 9 | + from mongoengine import QuerySet, AsyncQuerySet |
| 10 | +
|
| 11 | +Or simply: |
| 12 | +
|
| 13 | + from mongoengine import * |
| 14 | +
|
| 15 | +Instead of importing from internal submodules. |
| 16 | +
|
| 17 | +This module exposes both synchronous and asynchronous APIs. |
| 18 | +Asynchronous functionality is backed by PyMongo's native async support |
| 19 | +(PyMongo >= 4.14). |
| 20 | +""" |
20 | 21 |
|
| 22 | +from mongoengine import document, errors, fields, signals |
| 23 | + |
| 24 | +# ---- 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 |
| 29 | + |
| 30 | +# ---- 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 |
| 35 | + |
| 36 | +from mongoengine.document import * # noqa: F401,F403 |
| 37 | +from mongoengine.errors import * # noqa: F401,F403 |
| 38 | +from mongoengine.fields import * # noqa: F401,F403 |
| 39 | +from mongoengine.signals import * # noqa: F401,F403 |
| 40 | + |
| 41 | +# ---- public API surface ---- |
21 | 42 | __all__ = ( |
22 | 43 | list(document.__all__) |
23 | 44 | + list(fields.__all__) |
24 | | - + list(connection.__all__) |
| 45 | + + list(_sync_connection.__all__) |
| 46 | + + list(_async_connection.__all__) |
| 47 | + + list(_sync_queryset.__all__) |
| 48 | + + list(_async_queryset.__all__) |
25 | 49 | + list(signals.__all__) |
26 | 50 | + list(errors.__all__) |
27 | 51 | ) |
28 | 52 |
|
| 53 | +# ---- hide internals ---- |
| 54 | +del _sync_connection |
| 55 | +del _async_connection |
| 56 | +del _sync_queryset |
| 57 | +del _async_queryset |
| 58 | + |
29 | 59 | VERSION = (0, 29, 0) |
30 | 60 |
|
31 | 61 |
|
32 | 62 | def get_version(): |
33 | | - """Return the VERSION as a string. |
34 | | -
|
35 | | - For example, if `VERSION == (0, 10, 7)`, return '0.10.7'. |
36 | | - """ |
37 | 63 | return ".".join(map(str, VERSION)) |
38 | 64 |
|
39 | 65 |
|
|
0 commit comments