Skip to content

Honor depth limits and include directories in recursive find - #411

Open
shcheklein wants to merge 18 commits into
fix/fs-create-directoriesfrom
fix/fs-find-traversal
Open

shcheklein wants to merge 18 commits into
fix/fs-create-directoriesfrom
fix/fs-find-traversal

Conversation

@shcheklein

@shcheklein shcheklein commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Fixes #325. This PR builds on #409 and #408.

find() honors maxdepth and withdirs, sorts both output formats, and warns callers using the deprecated positional boolean detail. Cached folder IDs allow warm traversal across multiple levels in one Drive request. Current parent links determine the returned paths.

The filesystem extra requires fsspec 2024.2.0 or newer. The Ubuntu Python 3.11 job tests that minimum. Bounded glob expansion delegates to fsspec. The tests cover depth 1 through 3, glob expansion, sorting, file and directory mounts, and exact cold and warm request counts. The wide fixture takes seven requests cold and six warm.

@shcheklein shcheklein left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated review of 31de6118ae3e7d21aeb05d7e3a83bdadbfdf1720.

Good fix for maxdepth, withdirs, glob, and expand_path (including fsspec>=2021.07.0 maxdepth=0 and positional find(path, True) compatibility). Inline comments focus on simplifying find() (it doubled from ~48 to ~99 lines mainly due to duplicated self.info(path) fallbacks for untyped mount IDs), avoiding extra info() calls on directories with only subdirectories, and a key-vs-entry["name"] trailing-slash mismatch when detail=True, withdirs=True.

Comment thread pydrive2/fs/spec.py Resolved
Comment thread pydrive2/fs/spec.py Resolved
Comment thread pydrive2/fs/spec.py Resolved
Comment thread pydrive2/test/test_fs_listing.py Resolved

@shcheklein shcheklein left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated re-review of 1dc810a85e2268d42dad294c541740083ae99102 (from scratch).

Big improvement—the duplicated self.info() fallback is gone, key == entry["name"] is now consistent via _directory_entry, known_dir = True in the loop avoids extra stat calls on subdirs-only mounts, and the unit + live tests are thorough.

No standalone bugs found; two small cross-PR alignment notes with #409 inline.

Comment thread pydrive2/fs/spec.py Resolved
Comment thread pydrive2/fs/spec.py Resolved
@shcheklein
shcheklein changed the base branch from fix/fs-directory-cache-invalidation to fix/fs-create-directories November 22, 2026 17:50
@shcheklein

Copy link
Copy Markdown
Member Author

I tried AbstractFileSystem.find() with the same simulated Drive tree and checked the returned paths and individual HTTP requests. For 251 folders, the default traversal took 503 requests cold and 252 warm. Batched traversal took 7 cold and 6 warm. On a/b/c/file, the counts were 7 and 4 for the default, and 4 and 1 for PyDrive2. Batching only one level at a time would also take four requests on that warm deep tree.

The implementation keeps batching, uses #408’s resolver and builds paths from the parent IDs Drive returned. Both detailed and names-only results are sorted. Direct find(maxdepth=0) raises ValueError. The compatibility handling for fsspec 2021/2022 is confined to the versions that decrement the depth too early. Tests cover bounded glob expansion, depth 1 through 3 on the minimum and current fsspec, and the cold and warm request counts. Upstream fsspec depth fix

@shcheklein

Copy link
Copy Markdown
Member Author

Raised the fsspec extra to 2024.2.0 and removed the legacy glob and path-expansion implementations. At 2023.1.0, a depth-one recursive expansion of root/* returned a grandchild and made an extra request. The Ubuntu/Python 3.11 CI job now installs the exact minimum. Other jobs exercise the latest compatible release. Positional boolean detail continues to return its previous result with a deprecation warning. The directory-name conventions are documented.

DVC 3.67.1, dvc-objects 5.3.1 and dvc-data 3.18.3 already require fsspec 2024.2.0 or later. The DVC wrapper calls find(path). Its object database returned the same 251 hash objects at the minimum and at fsspec 2026.9.0, using a simulated Drive transport. Standalone PyDrive2 users pinned below 2024.2.0 will need to upgrade fsspec to use the new filesystem extra.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant