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

[ENH] add readme to default data locations #4037

Merged
merged 4 commits into from
Oct 13, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions nilearn/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ def _get_dataset_dir(
if not os.path.exists(path):
try:
os.makedirs(path)
_add_readme_to_default_data_locations(verbose=verbose)
if verbose > 0:
print(f"\nDataset created in {path}\n")
return path
Expand All @@ -316,6 +317,23 @@ def _get_dataset_dir(
)


def _add_readme_to_default_data_locations(verbose):
for d in get_data_dirs():
file = Path(d) / "README.md"
if file.parent.exists() and not file.exists():
with open(file, "w") as f:
f.write(
"""# Nilearn data folder

This directory is used by Nilearn to store datasets
and atlases downloaded from the internet.
It can be safely deleted.
If you delete it, previously downloaded data will be downloaded again."""
)
if verbose > 0:
print(f"\nAdded README.md to {d}\n")


# The functions _is_within_directory and _safe_extract were implemented in
# https://github.com/nilearn/nilearn/pull/3391 to address a directory
# traversal vulnerability https://github.com/advisories/GHSA-gw9q-c7gh-j9vm
Expand Down