-
-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
patch Python builtins with PyFilesystem #155
Conversation
No but seriously, this looks great, both for compatibility and usability purposes. (you may not be able to get On later Python versions, you may be interested in patching |
I'm not the best of wizards. This magic isn't easy. If you patch module naively with something like this:
It appears to work for the most part. But! If a module imports thusly:
The I found a solution to this. You can replace the
And then all references to
It was starting to look like my this magic would not work as well as I'd hoped. But then I recalled that I could use the If you call this:
It returned a list objects that contain a reference to the Naturally its not trivial. It's not enough to replace the
So I need to replace any keys where And that seems to work. Although it does require the use of
Because of this dark magic, I think I'm going to make it an external project. And make it Python3 only. Python2 compatibility would literally double the work. Will close this PR shortly. @althonos Don't know if you have any experience monkey patching? Wouldn't want to carry on this way only to find out there is a much simpler solution. |
Impressive work (even if that did not turn as expected)! I'm not the best when it comes to the interpreter internals, so I cannot really help here. I quickly tested if the |
Work in Progress
Will add a new feature to PyFilesystem, where a filesystem may be patched over the Python builtins. Here's an example of how it will work:
Here
os.listdir
andopen
will use the s3 filesystem. So PyFilesystem can work with any code not explicitly written with the PyFIlesystem API.@althonos early days on this one. Feedback welcome.