-
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
Refactor cache folder creation to its own function #149
Conversation
Move the code from `pooch.create` to `pooch.utils.make_local_storage`. The function joins the path, adds the version string, checks the environment variable, expands the user path, checks if the path is writable (now printing different messages if we can't create the folder vs can't create a file), and converts the string path to `pathlib.Path`. This will make it easier to reuse this part of the code is needed.
message += "Use environment variable '%s' to specify another directory." | ||
args += [env] | ||
|
||
get_logger().warning(message, *args) |
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.
I realize that I'm the one who made this a warning when we switched over to using the logging API, but do you think it should become an error? If the cache directory isn't writable, the user will just hit another error right after when they try to download something. But the real cause is here and passing through with only a warning could just obscure that.
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.
I was thinking the same thing. If this is the case, the warning will pop up on import
(usually when a package creates the Pooch
instance) and an exception is only raised on Pooch.fetch
. So if running on Jupyter/IPython there will be time to act and set the environment variable. But if running on a script then the error comes right after the warning and people might not see it.
In that case, it might be better to added the message to the error and re-raise it. What do you think?
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.
I was only thinking about the case of running it in a script and hadn't thought about jupyter. In any case I think that changing it from warning to error and re-raising the exception is the way to go.
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.
Agreed. I opened #150 to track this for a future PR instead of implementing it here to avoid changing 2 things at once. Thanks for the feedback @danshapero 👍
Move the code from
pooch.create
topooch.utils.make_local_storage
.The function joins the path, adds the version string, checks the
environment variable, expands the user path, checks if the path is
writable (now printing different messages if we can't create the folder
vs can't create a file), and converts the string path to
pathlib.Path
.This will make it easier to reuse this part of the code is needed.
This will pave the way for #147
Reminders:
make format
andmake check
to make sure the code follows the style guide.doc/api/index.rst
and the base__init__.py
file for the package.AUTHORS.md
file (if you haven't already) in case you'd like to be listed as an author on the Zenodo archive of the next release.