Skip to content

Commit

Permalink
build(deps): bump pymongo from 3.12.1 to 4.0.1 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] authored Feb 10, 2022
1 parent ed97b51 commit 68ed20a
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 206 deletions.
45 changes: 4 additions & 41 deletions anjani/util/db/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AsyncClient(AsyncBaseProperty):

def __init__(self, *args: Any, **kwargs: Any) -> None:
kwargs.update(
{"driver": DriverInfo(name="AsyncIOMongoDB", version="staging", platform="AsyncIO")}
{"driver": DriverInfo("AsyncIOMongoDB", version="staging", platform="AsyncIO")}
)
dispatch = MongoClient(*args, **kwargs)

Expand All @@ -70,6 +70,9 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
def __getitem__(self, name: str) -> AsyncDatabase:
return AsyncDatabase(self, self.dispatch[name])

def __hash__(self) -> int:
return hash(self.address)

async def close(self) -> None:
await util.run_sync(self.dispatch.close)

Expand Down Expand Up @@ -236,34 +239,6 @@ def is_mongos(self) -> bool:
def is_primary(self) -> bool:
return self.dispatch.is_primary

@property
def local_threshold_ms(self) -> int:
return self.dispatch.local_threshold_ms

@property
def max_bson_size(self) -> int:
return self.dispatch.max_bson_size

@property
def max_idle_time_ms(self) -> Optional[int]:
return self.dispatch.max_idle_time_ms

@property
def max_message_size(self) -> int:
return self.dispatch.max_message_size

@property
def max_pool_size(self) -> int:
return self.dispatch.max_pool_size

@property
def max_write_batch_size(self) -> int:
return self.dispatch.max_write_batch_size

@property
def min_pool_size(self) -> int:
return self.dispatch.min_pool_size

@property
def nodes(self) -> FrozenSet[Set[Tuple[str, int]]]:
return self.dispatch.nodes
Expand All @@ -272,22 +247,10 @@ def nodes(self) -> FrozenSet[Set[Tuple[str, int]]]:
def primary(self) -> Optional[Tuple[str, int]]:
return self.dispatch.primary

@property
def retry_reads(self) -> bool:
return self.dispatch.retry_reads

@property
def retry_writes(self) -> bool:
return self.dispatch.retry_writes

@property
def secondaries(self) -> Set[Tuple[str, int]]:
return self.dispatch.secondaries

@property
def server_selection_timeout(self) -> int:
return self.dispatch.server_selection_timeout

@property
def topology_description(self) -> TopologyDescription:
return self.dispatch.topology_description
6 changes: 3 additions & 3 deletions anjani/util/db/client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from contextlib import asynccontextmanager
from time import monotonic as monotonic_time
from typing import (
TYPE_CHECKING,
Any,
Expand All @@ -26,7 +27,6 @@
)

from pymongo.client_session import ClientSession, SessionOptions
from pymongo.monotonic import time as monotonic_time
from pymongo.read_concern import ReadConcern
from pymongo.write_concern import WriteConcern

Expand Down Expand Up @@ -111,12 +111,12 @@ async def with_transaction(
# 99% Of this code from motor's lib

def _within_time_limit(s: float) -> bool:
return monotonic_time.time() - s < 120
return monotonic_time() - s < 120

def _max_time_expired_error(exc: PyMongoError) -> bool:
return isinstance(exc, OperationFailure) and exc.code == 50

start_time = monotonic_time.time()
start_time = monotonic_time()
while True:
async with self.start_transaction(
read_concern=read_concern,
Expand Down
44 changes: 4 additions & 40 deletions anjani/util/db/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from typing import Any, List, MutableMapping, Optional, Tuple, Union

from bson import CodecOptions
from bson.son import SON
from bson.timestamp import Timestamp
from pymongo import IndexModel
from pymongo.collation import Collation
Expand All @@ -40,7 +39,7 @@
from .client_session import AsyncClientSession
from .command_cursor import AsyncLatentCommandCursor
from .cursor import AsyncCursor, AsyncRawBatchCursor, Cursor
from .types import JavaScriptCode, ReadPreferences, Request
from .types import ReadPreferences, Request


class AsyncCollection(AsyncBaseProperty):
Expand Down Expand Up @@ -68,6 +67,9 @@ def __getitem__(self, name: str) -> "AsyncCollection":
)
)

def __hash__(self) -> int:
return hash((self.database, self.name))

def aggregate(
self,
pipeline: List[MutableMapping[str, Any]],
Expand Down Expand Up @@ -316,24 +318,6 @@ async def index_information(
self.dispatch.index_information, session=session.dispatch if session else session
)

async def inline_map_reduce(
self,
mapping: JavaScriptCode,
reduce: JavaScriptCode,
*,
full_response: bool = False,
session: Optional[AsyncClientSession] = None,
**kwargs: Any,
) -> MutableMapping[str, Any]:
return await util.run_sync(
self.dispatch.inline_map_reduce,
mapping,
reduce,
full_response=full_response,
session=session.dispatch if session else session,
**kwargs,
)

async def insert_many(
self,
documents: List[MutableMapping[str, Any]],
Expand Down Expand Up @@ -371,26 +355,6 @@ def list_indexes(
self, self.dispatch.list_indexes, session=session.dispatch if session else session
)

async def map_reduce(
self,
mapping: JavaScriptCode,
reduce: JavaScriptCode,
out: Union[str, MutableMapping[str, Any], SON],
*,
full_response: bool = False,
session: Optional[AsyncClientSession] = None,
**kwargs: Any,
) -> MutableMapping[str, Any]:
return await util.run_sync(
self.dispatch.map_reduce,
mapping,
reduce,
out,
full_response=full_response,
session=session.dispatch if session else session,
**kwargs,
)

async def options(
self, session: Optional[AsyncClientSession] = None
) -> MutableMapping[str, Any]:
Expand Down
4 changes: 2 additions & 2 deletions anjani/util/db/command_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ def _on_started(
if self.dispatch._CommandCursor__data or not self.dispatch.alive: # skipcq: PYL-W0212
# _get_more is complete.
original_future.set_result(
len(self.dispatch._CommandCursor__data)
) # skipcq: PYL-W0212
len(self.dispatch._CommandCursor__data) # skipcq: PYL-W0212
)
else:
# Send a getMore.
fut = super()._get_more()
Expand Down
4 changes: 1 addition & 3 deletions anjani/util/db/cursor_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ def _to_list(
# Return early if the task was cancelled.
if future.done():
return
collection = self.collection
fix_outgoing = collection.database._fix_outgoing # skipcq: PYL-W0212

if length is None:
n = result
Expand All @@ -121,7 +119,7 @@ def _to_list(

i = 0
while i < n:
the_list.append(fix_outgoing(self._data().popleft(), collection))
the_list.append(self._data().popleft())
i += 1

reached_length = length is not None and len(the_list) >= length
Expand Down
3 changes: 3 additions & 0 deletions anjani/util/db/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def __init__(self, client: "AsyncClient", database: Database) -> None:
def __getitem__(self, name) -> AsyncCollection:
return AsyncCollection(Collection(self.dispatch, name))

def __hash__(self) -> int:
return hash((self.client, self.name))

def aggregate(
self,
pipeline: List[MutableMapping[str, Any]],
Expand Down
1 change: 0 additions & 1 deletion anjani/util/db/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
SecondaryPreferred,
)

JavaScriptCode = TypeVar("JavaScriptCode", bound=str)
ReadPreferences = Union[Primary, PrimaryPreferred, Secondary, SecondaryPreferred, Nearest]
Request = Union[DeleteOne, InsertOne, ReplaceOne]
Results = TypeVar("Results")
Loading

0 comments on commit 68ed20a

Please sign in to comment.