-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for file objects to load_registry() #117
Conversation
Alternatively there could be a separate method that does the |
16e31b2
to
fa701d9
Compare
fa701d9
to
61b1608
Compare
(fixed lint issues: |
|
||
""" | ||
with open(fname) as fin: | ||
with contextlib.ExitStack() as stack: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, this is new to me. Bookmarking for later use 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this, Rémi 👍 We can add the pkg_resources
line to the docs but it might be better to include it as an alternative or recommended way. It's not very straight forward for those not familiar with setuptools (I didn't know about resource_stream
) and this is a good chance to introduce it.
Co-Authored-By: Leonardo Uieda <[email protected]>
Are you asking for it to be alternative or recommended? To be honest it is pretty weird to not use |
Sorry, my comment wasn't clear. We should definitely recommend this as the preferred approach since it's the correct thing to do (we should probably do it internally as well :). But we should probably acknowledge that the other approach exists and why it's best to do it this way. This can be done in another PR as it's not directly related to this. Merging this one in since it seems to be complete and all tests pass. Thanks! I always learn some new things from your PRs 🙂 |
Follow up on #117 and document using pkg_resources instead of os.path. It's less error-prone and allows one's package to work from ZIPs (zip-safe).
This makes it possible to pass a file object to
load_registry()
, opened either in binary or text mode.My main reason for this is to support passing
pkg_resources.resource_stream()
to it, which is the preferred way of using data files from the package (it will allow your package to be "zip-safe" though that doesn't matter as much those days).This could be updated:
pooch/doc/usage.rst
Line 461 in 9a1382d
to this:
Reminders
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
.