At 11:09 PM 10/1/2010 +0200, Ronny Pfannschmidt wrote:
hi,

I'm implementing a custom pep302 importer in order to ship sets of
python packages within a generated python script,

I'd like to support egg-info entry-points, so I can ship extensions as
well as choose the script entry-point based on the executable name.

However I couldn't find simple docs on doing that.

You need to register some adapters for your importer type, using the functions described here:

http://peak.telecommunity.com/DevCenter/PkgResources#supporting-custom-importers

Essentially, you will need to define two functions and a class:

def my_finder(path_item, importer, only):
    # yield Distribution objects for path

def my_namespace_fixer(importer, path_item, modulename, module):
    # return a __path__ entry to add to module

class MyProvider(EggProvider):

    def _has(self, path):
        # os.path.exists(path)

    def _isdir(self,path):
        # os.path.isdir(path)

    def _listdir(self,path):
        # os.listdir(path)

    def _get(self, path):
        # open(path,'rb').read()

and then register them like so:

    register_finder(MyImporter, my_finder)
    register_namespace_handler(MyImporter, my_namespace_fixer)
    register_loader_type(MyLoaderType, MyProvider)

Without knowing how your PEP 302 importer works, it's hard to get more specific than this; it all depends on how your sys.path entry strings are formatted. Are you using a virtual OS path the way .zip paths work, or something else? (If you're using pseudo-OS paths, you can reuse pkg_resources.file_ns_handler in place of writing your own my_namespace_fixer.)

Note, by the way, that if your system doesn't physically place individual files on disk, you probably actually want something that emulates .egg rather than .egg-info, as then you can support resource_filename() operations. (In which case, you'll probably also subclass ZipProvider rather than EggProvider.)

So, yeah, there are no simple docs.  ;-)

It would probably be good if pkg_resources had better support for rolling your own stuff over a virtual file system; it already has some, but the "finder" part could be a lot simpler if there was a way to reuse the built-in ones with a VFS, and the "provider" class would be easier if the parts of ZipProvider that aren't truly zipfile-specific were moved to EggProvider or NullProvider.

_______________________________________________
Distutils-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/distutils-sig

Reply via email to