Repository navigation
Export Google files as Office files in the filesystem - #472
Draft
shcheklein wants to merge 3 commits into
Draft
shcheklein wants to merge 3 commits into
shcheklein wants to merge 3 commits into
Conversation
Reads of Docs, Sheets, Slides and Drawings now export .docx, .xlsx, .pptx and .svg, as Drive's web app and rclone do. get() adds the extension when it names the local file after the Drive item. A recursive get() follows shortcuts to files and skips Forms, shortcuts to folders and shortcuts whose target is gone, with a warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved destination-name collisions can silently overwrite downloads, while nested fs.get() calls corrupt thread-local state and can raise AttributeError after successful transfers.
2 open issues
What changed in this PR
This PR makes filesystem reads export Google files as Office files or SVG, while leaving the core API unchanged.
Changes:
- Adds format-aware downloads and local filename extensions.
- Follows file shortcuts and skips unsupported items during recursive downloads.
- Documents the behavior and adds live and offline tests.
| File | Description |
|---|---|
pydrive2/test/test_fs.py |
Tests live exports and shortcut handling. |
pydrive2/test/test_fs_unit.py |
Tests naming, bare-ID exports, and missing targets. |
pydrive2/test/test_fs_registration.py |
Updates bare-ID request expectations. |
pydrive2/fs/spec.py |
Implements export formats, shortcut resolution, and download naming. |
docs/upgrading.rst |
Explains the filesystem behavior change. |
docs/fsspec.rst |
Documents exports, shortcuts, and read semantics. |
Review effort: Balanced
A Doc named "a" and a file named "a.docx" both save as a.docx; get() now skips the second with a warning instead of overwriting the first. A get() started from a callback inside another get() no longer clears the outer call's state. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A shortcut whose target is gone no longer blocks a later file that saves under the same local name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The filesystem now exports Google files the way Drive's web app and rclone do (rclone's default
--drive-export-formats docx,xlsx,pptx,svg).Before and after
root/reportsholds a Doc, a Sheet, a Slides deck, a Drawing, a Form, a shortcut to the Doc, a shortcut to a folder anddata.txt.Before (main): the copy stops at
doc-linkwithApiRequestError: 400 The requested conversion is not supported. Main exports every item it can't download astext/plain, and Drive refuses that for shortcuts, Sheets, Drawings and Forms. By then the copy has writtenlocal/reports/data.txtandlocal/reports/doc, anddocholds the Doc's plain text with a BOM.After:
Other reads follow the same rule:
fs.cat_file("root/reports/doc")andfs.open(...)return the.docxbytes. Before, they returned the Doc's text.cat_file,openorget_fileof a Form or a folder shortcut raisesFileNotDownloadableError. Before, it raised a 400ApiRequestError.FileNotDownloadableErrorwhen you read it directly. A recursivegetskips it with a warning.GetContentString(mimetype="text/plain")still returns a Doc's text.Choices
ls,findandinfoshowdoc, notdoc.docx.getadds the extension only when the local name is the Drive name, sofs.get(fs.find(p), "local/")andcat_file(path)work on every listed path. A different local name is used exactly as given:fs.get("root/reports/doc", "local/notes")writeslocal/notes. rclone showsdoc.docxin listings and matches either name on lookup. Doing that here would change path resolution for every operation, so this PR doesn't. (Question 1)reportand a filereport.docxboth save asreport.docx. Oneget()keeps the first one it saves and skips the other with a warning, like rclone's "Duplicate object found in source - ignoring".shortcutDetails(targetId,targetMimeType), so following a shortcut costs no extra request. Only a shortcut opened by its own ID needs one morefiles.get..docx. Main opened by ID with 1 request; this PR makes it 2 on the first open.get_fileby ID already read this metadata on main. (Question 3)Questions for review
doc.docx, as rclone does? That is a larger change, to name lookups across all operations.open()OK? The alternative keeps 1 request and exports a Doc opened by ID as text, so not every read would follow the same rule.Tests
The new live tests failed on main in a test-only run: run 47481052404. All 4 failed:
the recursive get stopped at the 400 conversion error;
cat_fileof a Doc started withb'\xef\xbb'instead ofPK;cat_fileof a Form and of a folder shortcut raised a 400ApiRequestError.Live: a recursive
getof a folder with a Doc, Sheet, Slides, Drawing, Form, file shortcut, folder shortcut and plain file.cat_fileof a Doc starts withPK.cat_fileof a Form or a folder shortcut raisesFileNotDownloadableError. The Google files are created blank, so each export stays far below Drive's 10 MB limit.Offline:
get(directory destination, same name, own name);openof a Doc exports.docx;FileNotDownloadableError;Updated tests:
shortcutDetailsfield;test_open_by_file_idand the two open block-size tests, for the metadata request;test_newer_listing_determines_which_id_a_warm_read_uses. Its stale listing shows only a folder at the path, so that read now raisesIsADirectoryErrorinstead of downloading the folder's ID.Follow-up
Shortcuts to link-shared files that need
shortcutDetails.targetResourceKeyaren't handled. The filesystem doesn't send resource keys for any listed item, on main either, so that is a separate change.Overlap with other drafts
test_cat_file_of_a_google_doc_returns_its_textandtest_cat_file_of_a_shortcut_or_a_sheet_raises_file_not_downloadabledescribe the behaviour this PR replaces. When I rebase this PR on Fail clearly on shortcuts and refused exports; du from one listing #460, I'll drop those two tests.mime_typeto_ListedChild. This PR uses the same field name._gdrive_get_fileand_gdrive_open_file. Recursive get and copy use the IDs from their listing, without a lookup per file #468 changes howgetlooks up items. Whichever merges second carries_Download(the ID and export type) into the new code.Docs: a new "Google files and shortcuts" section in
docs/fsspec.rst, and a note indocs/upgrading.rst.🤖 Generated with Claude Code