Skip to content
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

Merged
merged 1 commit into from
Mar 12, 2020
Merged

Conversation

leouieda
Copy link
Member

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.

This will pave the way for #147

Reminders:

  • Run make format and make check to make sure the code follows the style guide.
  • Add tests for new features or tests that would have caught the bug that you're fixing.
  • Add new public functions/methods/classes to doc/api/index.rst and the base __init__.py file for the package.
  • Write detailed docstrings for all functions/classes/methods. It often helps to design better code if you write the docstrings first.
  • If adding new functionality, add an example to the docstring, gallery, and/or tutorials.
  • Add your full name, affiliation, and ORCID (optional) to the 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.

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)
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Member Author

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 👍

@leouieda leouieda merged commit aef0aba into master Mar 12, 2020
@leouieda leouieda deleted the cache-creation branch March 12, 2020 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants