tags:

views:

58

answers:

1

My project has the ability to run python functions remotely. Doing so requires transmitting modules a given function utilizes. Determining what to send is conducted via a modified modulefinder.

As I modify the modulefinder to support arbitrary path_hooks, I've started to get the impression that path_hooks are not all that popular. Quick google codesearching seems to only show the ZipImporter using them. I've noticed a minor project using it (and even then, its loader doesn't support the PEP 302 extension of get_code, which is needed by the modified modulefinder).

Has anyone come across or created projects that use custom path_hooks to access source code?

+2  A: 

Yes, I've coded some path hooks (for one of the obvious purposes: access modules living in other forms of storage besides the filesystem and zipfiles), but never on an open-source project (and actually never needed to support modulefinder in them). What difficulties are you encountering? While I can't share my original code I think I can share the know-how developed with it (though offhand I can't recall any special difficulties -- it has been a while). As for "popular", I guess they will be in direct proportion to the need to site modules "elsewhere" (e.g. in some form of DB), though of course general "usermode file systems" built e.g. using fuse , macfuse and dokan may also allow this (and offer other advantages in terms of generality -- not sure how performance compares).

Alex Martelli
The main issue with supporting arbitrary path_hooks is being able to A) read the source code of a module without importing it and B) tracking changes.A is solved if the get_code extension is implemented by the PEP 302 loader. I suspect custom path hooks don't do this.For B, I currently do timestamps (as python). ZipImporter possesses the archive property. To support arbitrary code, checksums would need to be taken of the code; and, if custom hooks are rarely ever used, the tracking system is not worth developing.
UsAaR33
And thanks for the answer. Your response and the lack of any others (or votes) conforms my hunch that they are very rare.
UsAaR33