question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add stdlib-compatible shim layer.

See original GitHub issue

@martindurant This is a trial-balloon issue for this idea, mostly to see if fsspec is the “right” place for this feature and/or if I’ve missed an existing implementation. If so, I’ve a working proof-of-concept built off an older version of dask that could serve as a starting-point PR.

fsspec is a great module for new development or projects built on the existing dask ecosystem and enables an amazing S3-is-my-filesystem paradigm. However, the vast majority of projects make use of the python’s built-in file operations, and are tightly coupled to a local filesystem. This causes major development friction when integrating existing third-party libraries into a project, as one almost invariably needs to work out an integration-specific flow between local files and remote storage.

One can workaround this problem with FUSE-based mounts, however this complexifies deployment and containerization. Alternatively, any of several (fsspec, smart_open, pyfilesystem2, et. al.) filesystem abstractions could be used, but updating a third-party component to an alternative filesystem interface is a painful and risky development lift. One either needs to maintain a private fork 😳 or open a massive and risky PR 😬.

I’ve found that a solid majority of filesystem use cases are covered by a relatively small set of operations, all of which is already covered by fsspec. By providing strictly-compatible shims for a small set of the stdlib (eg: open, os.path.exists, os.remove, glob.glob, shutil.rmtree, et. al.) and then swapping these via import level changes one can quickly teach most libraries to seamlessly interact with all the file systems supported by fsspec.

This shim layer would mandate strict adherence to standard library semantics for local file operations, likely by directly forwarding all local paths into the standard library and forwarding non-local paths through fsspec-based implementations. The explicit goal would be to enable a majority of basic use cases, deferring to fsspec interfaces for more robust integration and/or specialized use cases. This would turn fsspec into a massively useful layer for updating existing systems to cloud-compatible storage, as updating a library to support s3 and gcsfs would be as simple as:

try:
    from fsspec.stdlib import open
    import fsspec.stdlib.os.path as os.path
    import fsspec.stdlib.shutil as shutil
except ImportError:
    import os.path
    import shutil

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
ghostcommented, Nov 15, 2019

Here’s a (mostly) pathlib compatible wrapper that I’m using. I take it there’s not a ton of interest, so I’ll just throw it out there as a gist in case it is of use to anyone.

0reactions
martindurantcommented, Apr 14, 2020

Yes, please, someone wrap this as a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add stdlib-compatible shim layer. · Issue #114 - GitHub
I've found that a solid majority of filesystem use cases are covered by a relatively small set of operations, all of which is...
Read more >
Demystifying Shims - or - Using the App Compat Toolkit to ...
Creating an Application Compatibility Shim​​ It is a very small size and once executed, will always be associated with that executable on that ......
Read more >
Shim layer C++. shim layer for library | by Poby's Home | Medium
Simple replacement layer that replace gnu library. Application // test.cpp #include <stdio.h> #include <stdlib.h>int main( ...
Read more >
opam - stdlib-shims - OCaml
Backport some of the new stdlib features to older compiler, such as the Stdlib module. This allows projects that require compatibility with ...
Read more >
History - importlib-metadata - Read the Docs
Added a compatibility shim to prevent failures on beta releases of Python before the signature changed to accept the “context” parameter on ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found