-
-
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
Allow fs to be extended with subpackages #47
Conversation
Interesting! I didn't know you could enumerate modules like that. First impressions are this is a good idea, but give me a little time to digest... :-) You might want to add your sshfs to the docs, in |
Is |
@willmcgugan : indeed, I used paramiko as well, but maybe it is not a customizable as the fs1 version (but I'm testing it against a docker |
Sorry for the delay. I've been a little reluctant to merge, but on reflection I can't find any fault with it. Thanks for the contribution. 👍 |
You're welcome, this way it makes it easier to develop extensions ;) I'll work on integrating fs.sshfs properly and then I'll make a PR to be included in the documentation later on. |
Hi ! This is my last PR, sorry to harass you lately.
I've been developping fs.sshfs, a Pyfilesystem2 extension that implements the SFTP protocol. So I packaged everything, and that worked fine. However, it was a bummer that I had to import
fs.sshfs
for thefs.opener.registry
to know about thessh
protocol !fs/opener.py
-->fs/opener/*
I made the
fs.opener
module a package, containing the following files:fs/opener/_base
, with the baseOpener
classfs/opener/errors
, with the errors specific toopen_fs
,manage_fs
orparse
fs/opener/_registry
, with theRegistry
classThen I added some
pkgutil+importlib
black magic to automatically load files in thefs/opener
directory. To support this, eachOpener
defined in the mainfs
package was moved to a specific file:osfs.py
,ftpfs.py
,memoryfs.py
,tarfs.py
,tempfs.py
,zipfs.py
. Then, when thefs
package is first imported, every known protocol will be loaded in theregistry
.tidying
fs.opener.Registry
manage_fs
was made aRegistry
instance method,ParseResult
and_RE_FS_URL
attributes of theRegistry
class, andparse
aRegistry
class method.namespace packages
fs
andfs.opener
were made namespace packages, so that files provided by extensions would be installed in the same directory as the Pyfilesystem2 library itself.extension framework
Creating an extension for Pyfilesystem2 is made easier, the user doesn't have to know which extensions are installed, and
fs.open_fs
will work out-of-the-box, if the extension if well structured. To support this, I added a HOW-TO to the documentation (pardon the eventual quirks, English is not my mother tongue).tl;dr
If you create a python package with the following structure:
it will be loaded directly by Pyfilesystem, and
fs.open_fs("awesome://")
will work as intended without having to importfs.awesomefs
first.You can have a glance of a working extension (I tested it thoroughly) at the feat-namespace branch of althonos/fs.sshfs.