Re: Proposed design for importlib.resources()
Barry Warsaw <[email protected]> Mon, 23 Nov 2015 15:45:55 -0500
| Newsgroups | gmane.comp.python.import |
|---|---|
| Organization | Damn Crazy Followers of the Horn |
| Message-ID | <[email protected]> |
--===============3895746506239636274== Content-Type: multipart/signed; micalg=pgp-sha256; boundary="Sig_/HnL8rNscg2okMEWH4E5.THO"; protocol="application/pgp-signature" --Sig_/HnL8rNscg2okMEWH4E5.THO Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Nov 20, 2015, at 09:23 PM, Brett Cannon wrote: >I have created a Jupyter Notebook to explain my thinking on what >importlib.resources() should be (at least initially). Just a few thoughts based on a review of two projects' use of pkg_resources. +1 on getting *something* into Python 3.6. Module API vs package API. Doesn't pkg_resources actually support something similar to both, with the module function providing a convenience API? I l= ike that a lot because the convenience API is so darn... convenient! You just give it the Python dotted-path and the resource and it does the rest. Generally I don't care about caching the results of the search; these calls are almost never in performance critical code. resource_filename(). Doesn't pkg_resources already have a strategy for the temporary file that sometimes has to be created? Maybe it doesn't work so well on some platforms (I've never noticed a problem on *nix). A context manager as proposed seems like the most reasonable approach. We definitely need this API though. I see plenty of examples where e.g. test data files have to be shutil.copy()'d, passed to subprocess command line arguments, et= c. read_bytes(). Thank you for the truth in advertising! IIRC in Python 3, pkg_resource.resource_string() actually returns bytes. from-import-as to the rescue. An actual resource_string() would have to accept an encoding argum= ent (as would any resource-based open() method). resource_stream(). IIRC, the pkg_resource's version is not a context manag= er so it has to be closed explicitly (or wrapped in contextlib.closing()). We can do better. I do have one use of resource_listdir() which is used to find importable plugin modules at runtime. It's handy. That's all for now. -Barry --Sig_/HnL8rNscg2okMEWH4E5.THO Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJWU3sDAAoJEBJutWOnSwa/gE4P/jtYOuFx3XFLNd9DHulcf07f Bq8LrLz7KEuW2dPrb1EKojhnz7FLgqCHV5b/lkXSp7YKYSgGmMbATZdLNm+EySCJ i6OtFiHmba5Lw0c1onn0UVHHV3wGq5NLJ/VUr/p2lXV9tqxyeNZXgQunEuYsS4xx 4ZRl/g3oa3oj2qr2mrP3FAgUmsiaNYyHuQrW3a3M3sdEwQ8S4J9L1oaFeuqupTtF d5hykq2isIQXHfXjF+SaPM1ex3387zgic7ie6Ts+RxYIYQ5JmxdIHr33sPtGpUHc oI7GAcxK9XP9hR/DhqEzGJGQOeAJYeVFrE+0FqByzZj4TynmM6Cqp0auEnc27zMr TKrcFWOd5/7ayCGeQ/1wyfWzSEUxCMHnzj5xgCnL2Rgl9EO6oi8TmKKU06xcNnkp RegySNW79Nb1UwnkzIW4hSBO9gzXtfpU2Mnr6pVKZGNiXlVrcBlgzQmuQneVlXAn 7a/wafIVib0wFSXumZU8WKixWvNmcmHppWNoN62yiGprm5yumpPHjjqalVJ35v5H b+d//N1BmwRF9SyqCWKDNqVyFfrvaEs5P/Mfi5h+zpUX/bQ1EZBCUB/roRXUjN0g MpcX0qiW/nmvIr/iaHGpVV+C35QgZJATE6jpAewLXn//3zgI4nqq+47kVK4RIlfP sLBjpcYzZsFTAhRkLQWx =3ocS -----END PGP SIGNATURE----- --Sig_/HnL8rNscg2okMEWH4E5.THO-- --===============3895746506239636274== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Import-SIG mailing list [email protected] https://mail.python.org/mailman/listinfo/import-sig --===============3895746506239636274==--