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

Fail gracefully if cache directory is read only #430

Merged
merged 5 commits into from
Nov 20, 2024

Conversation

IgorTatarnikov
Copy link
Member

@IgorTatarnikov IgorTatarnikov commented Nov 15, 2024

Before submitting a pull request (PR), please read the contributing guide.

Please fill out as much of this template as you can, but if you have any problems or questions, just leave a comment and we will help out :)

Description

What is this PR

  • Bug fix
  • Addition of a new feature
  • Other

Why is this PR needed?
If a user doesn't have write permission to the .brainglobe directory, instantiating an atlas will cause a crash unless check_latest=False is set.

What does this PR do?
Gracefully handles permission denied errors when caching the latest_versions.conf file. The user will be informed of the error without crashes.

References

brainglobe/brainglobe-heatmap#65
brainglobe/brainrender#395

Please reference any existing issues/PRs that relate to this PR.

How has this PR been tested?

Tested locally by changing the permissions for the last_versions.conf file.

New test added to check error is printed once, and utils.conf_from_url runs even if .brainglobe has read only permissions.

Is this a breaking change?

No.

Does this PR require an update to the documentation?

No.

Checklist:

  • The code has been tested locally
  • Tests have been added to cover all new functionality (unit & integration)
  • The code has been formatted with pre-commit

@IgorTatarnikov IgorTatarnikov marked this pull request as ready for review November 15, 2024 11:51
@IgorTatarnikov IgorTatarnikov requested a review from a team November 15, 2024 11:52
Copy link
Member

@alessandrofelder alessandrofelder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am happy with the changes - made a very minor comment.
To check my understanding: this means that if latest_versions.conf is read-only, users won't be able to update atlases (and will need e.g. a sysadmin to do it for them)?

with open(cache_path, "w") as f_out:
config_obj.write(f_out)
except OSError as e:
print(f"Could not update the latest atlas versions cache: {e}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better if this used logging.warning or logging.info?

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 wasn't sure, the rest of the file uses print statements to inform user of error cases so I didn't want to break from what's currently being used. Does brainglobe-atlasapi keep a log on disk somewhere?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like earlier in the utils.py file it sets the logging level for urllib3 but if print is used elsewhere, maybe let's stick to print here and open an issue to make logging consistent... (atlasgen uses loguru)

@IgorTatarnikov
Copy link
Member Author

I think so, if the .brainglobe directory is read only then the user can't update the atlases anyway (as far as I understand).

  • If the internet is available, the directory is read only, and last_versions.conf file doesn't exists: the user gets the printed warning, atlases are loaded.

  • If the internet is available, the directory is read only, and last_versions.conf exists: the user gets the printed warning, atlases are loaded.

  • If there is no internet, the directory is read only, and last_versions.conf exists: no printed warning, atlases are loaded.

  • If there is no internet, the directory is read only, and last_versions.conf doesn't exist: no printed warning, atlases are loaded.

Thinking more about it, is it worth getting rid of the printed warning?

@adamltyson
Copy link
Member

Thinking more about it, is it worth getting rid of the printed warning?

What are the warnings? Users may not care too much that their directory is read only, but they may if they're not able to get the latest version of an atlas.

@IgorTatarnikov
Copy link
Member Author

Currently, they only get a warning that their directory is read only, nothing to do with being able to get the latest version of an atlas. If they're connected to the internet the atlas version check is done by comparing to the data fetched from GIN not the cached last_versions.conf.

@alessandrofelder
Copy link
Member

Thinking more about it, is it worth getting rid of the printed warning?

If nothing else, it's a useful piece of logs for us, so I suggest keeping.

@IgorTatarnikov IgorTatarnikov merged commit 4eaa6b1 into main Nov 20, 2024
13 checks passed
@IgorTatarnikov IgorTatarnikov deleted the no-cache-read-only branch November 20, 2024 10:08
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