Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions docs/upgrading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,8 @@ used it can fetch the metadata at the start of the method:
The ``revoke_uri`` client setting is no longer read. A settings file that
still has it keeps working.

The filesystem's ``find()`` takes ``maxdepth`` as its second argument, as
other fsspec filesystems do. Pass ``detail`` by keyword:
``fs.find(path, detail=True)``. ``fs.find(path, True)`` raises ``TypeError``.

.. _Drive v2 to v3 reference: https://developers.google.com/workspace/drive/api/guides/v2-to-v3-reference
12 changes: 4 additions & 8 deletions pydrive2/fs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import tempfile
import threading
import time
import warnings
from collections import deque
from contextlib import contextmanager, nullcontext
from dataclasses import dataclass, field
Expand Down Expand Up @@ -1152,15 +1151,12 @@ def _walk_folders(self, start, start_ids, generation, maxdepth, fields):
def find(
self, path, maxdepth=None, withdirs=False, detail=False, **kwargs
):
# PyDrive2 historically accepted a boolean detail as its second argument.
# PyDrive2 1.x took detail as the second argument, and True is 1.
if isinstance(maxdepth, bool):
warnings.warn(
"Positional detail is deprecated. Pass detail=True or detail=False.",
DeprecationWarning,
stacklevel=2,
raise TypeError(
"find() takes maxdepth as its second argument. "
f"Pass detail by keyword: find(path, detail={maxdepth})."
)
detail = detail or maxdepth
maxdepth = None
root, base = self._split_mounted_path(path)
if maxdepth is not None and maxdepth < 1:
raise ValueError("maxdepth must be at least 1")
Expand Down
32 changes: 16 additions & 16 deletions pydrive2/test/test_fs_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,22 +557,22 @@ def test_expanding_a_bounded_glob_does_not_list_children(mock_drive, pattern):
assert "'root' in parents" in query(lookup)["q"][0]


def test_find_legacy_positional_detail_and_invalid_depth(mock_drive):
item = {
"name": "file",
"id": "F",
"mimeType": "text/plain",
"parents": ["root"],
}
page = response({"files": [item]})
drive, _ = mock_drive(page, page)
fs = filesystem(drive)
with pytest.warns(DeprecationWarning, match="detail"):
legacy = fs.find("root", True)
assert legacy == fs.find("root", detail=True)
for depth in (0, -1):
with pytest.raises(ValueError, match="maxdepth"):
fs.find("root", maxdepth=depth)
@pytest.mark.parametrize(
("maxdepth", "error", "message"),
[
(True, TypeError, "detail=True"),
(False, TypeError, "detail=False"),
(0, ValueError, "maxdepth"),
(-1, ValueError, "maxdepth"),
],
)
def test_find_with_a_depth_that_is_not_a_positive_number_raises_before_listing(
mock_drive, maxdepth, error, message
):
drive, requests = mock_drive()
with pytest.raises(error, match=message):
filesystem(drive).find("root", maxdepth)
assert requests == []


@pytest.mark.parametrize("bare", [True, False])
Expand Down