[Import-SIG] Proposed design for importlib.resources()
Donald Stufft
donald at stufft.io
Tue Nov 24 15:47:10 EST 2015
> On Nov 24, 2015, at 3:21 PM, Brett Cannon <brett at python.org> wrote:
>
>
> resource_filename(). Doesn't pkg_resources already have a strategy for the
> temporary file that sometimes has to be created?
>
> Yes and I don't like it. :) Basically you either create an instance or implicitly use a global instance of a class that stores the references and registers with atexit a cleanup function to be executed.
In pkg_resources they aren’t actually temporary files but are instead cached files which are stored in a non temporary location per user and will be recreated if need be. It would probably be sane to make this context manager like the ones in tempfile where the creation happens in __init__ and the deletion happens in __exit__ (with also a .delete() function) so people can choose how to use it. If you wanted something more like what pkg_resources does now, you could do:
filename = importlib.resources.get_filename(“mypackage”, “some/path.txt”, dir=“~/.cache/mypackage”)
-----------------
Donald Stufft
PGP: 0x6E3CBCE93372DCFA // 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/import-sig/attachments/20151124/ef0bb524/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.python.org/pipermail/import-sig/attachments/20151124/ef0bb524/attachment.sig>
More information about the Import-SIG
mailing list