[Distutils] distlib updated with resources API

Vinay Sajip vinay_sajip at yahoo.co.uk
Thu Sep 27 15:14:21 CEST 2012


Daniel Holth <dholth <at> gmail.com> writes:

> 
> What you can do with pkgutil is call
> pkgutil.iter_importer_modules.register(importer, function) so that
> your new importer works with iter_modules. Unfortunately even though
> it implements most of what you would need to listdir() a zip file,
> using zipimport._zip_directory_cache[], it does not expose the
> functionality.

I haven't defined any new importers. In terms of listing a whole zip's contents,
that's not part of the idea of a resource: you need to know what resource you
want, before you can get it, at least at the top level. Of
course, you can iterate over a resource tree once you have a top-level
resource. Possibly an iterator could be provided for convenience, but I'm not
sure what the use case is. For example, should particular files like __pycache__
and .pyc be excluded when operating on file system resources?

I don't use _zip_directory_cache directly - it's exposed as the zipimport
loader's "_files" attribute, and I use that.

> Make sure you have a test where the package is not in the root of the .zip file
> 
> foo.zip/site-packages/bar.py
>

Thanks for pointing that out, I've raised an issue to remind myself.

> Speaking of old code, does anyone feel like replacing
> 
> # @decorator
> def fn(): ...
> fn = decorator(fn)
> 
> with the probably-ok-to-use-by-now decorator syntax?

Where's the anachronistic code you're referring to?

Regards,

Vinay Sajip



More information about the Distutils-SIG mailing list