WIP: Patch open, os and os.path builtins #322
Draft
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.
Right now, libs that use
open
directly,fspath
or just assume paths are strings and can be manipulated don't work withCloudPath
objects. (Related issues: #315, #73, #128)Totally WIP and not sure that we want to introduce and support this, but it may increase compatibility significantly to have the option at least for users to patch the builtin functions.
The biggest limitations are:
path = dir + os.sep + file
)Other potential todos for this PR:
glob
module as wellpandas
has all kinds of formats,rasterio
may be interesting,xarray
has come up,Pillow
may be a common use case)os
functionsos.fspath
to allow returningCloudPath
open = patch_open()
sinceopen
exists as alocal
in the notebook namespaceCurious for your thoughts @jayqi !
Experimental instructions
pip install git+https://github.com/drivendataorg/cloudpathlib@patch-builtins
CLOUDPATHLIB_PATCH_OPEN=True
before any import call tocloudpathlib
open
or third-party libraries that use open.