[Distutils] Accessing package data files in wheels

Vinay Sajip vinay_sajip at yahoo.co.uk
Mon Jun 29 10:00:52 CEST 2015


From: Paul Sokolovsky <pmiscml at gmail.com>

> Which makes everyone in the audience wonder: how it happens that it's
> 2015, Python is at 3.5, but pkgutil.get_data() is in stdlib, while> pkg_resources.resource_stream() isn't? An implementation of
> pkgutil.get_data() would be based on pkg_resources.resource_stream(),
> or would contain just the same code as the latter, so it could easily
>be exposed, and yet it isn't.
Perhaps because it's not always that way around - pkg_resources.get_stream_resource, in relevant cases, returns a BytesIO which wraps a byte string. If you want a stream, you could just as easily do this yourself by calling io.BytesIO(pkg_util.get_data('foo.pkg', 'foo_resource')).
In the case of file resources only, pkg_resources.get_stream_resource can open the file and return the stream directly. But this is an optimisation and is not always necessarily available for all different loader implementations - which is perhaps why a `pkgutil.get_data_stream` is not provided.
Regards,
Vinay Sajip

   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20150629/87ff411d/attachment.html>


More information about the Distutils-SIG mailing list