From 7c3da34a6e9c47efcbbac3c1ebd3722d34d41780 Mon Sep 17 00:00:00 2001 From: donishadsmith Date: Thu, 16 Apr 2026 01:18:14 -0400 Subject: [PATCH] Support ``NEUROCAPS_DATA`` env var for data directory override --- CHANGELOG.md | 4 +++ README.md | 2 +- docker/Dockerfile | 39 ++++++++++++++---------------- docker/scripts/entrypoint.sh | 6 +---- docs/introduction.rst | 2 +- neurocaps/__init__.py | 2 +- neurocaps/utils/datasets/_fetch.py | 9 ++++--- neurocaps/utils/parcellations.py | 4 +++ 8 files changed, 36 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb67a9af..0446dea2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ noted in the changelog (e.g., new functions or parameters, changes in parameter improvements/enhancements. All fixes and modifications are backwards compatible. - *.postN* : Consists of documentation changes or metadata-related updates, such as modifications to type hints. +## [0.37.3] - 2026-04-16 +### ♻ Changed +- Added support for the ``NEUROCAPS_DATA`` environment variable to override the default data directory location used by fetch_preset_parcel_approach. Defaults to "~/neurocaps_data" when unset. + ## [0.37.2] - 2026-02-19 ### 💻 Metadata - Update metadata on Pypi diff --git a/README.md b/README.md index b8904a00..6c064312 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Latest Version](https://img.shields.io/pypi/v/neurocaps.svg)](https://pypi.python.org/pypi/neurocaps/) [![Python Versions](https://img.shields.io/pypi/pyversions/neurocaps.svg)](https://pypi.python.org/pypi/neurocaps/) -[![DOI](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.11642615-teal)](https://doi.org/10.5281/zenodo.18529846) +[![DOI](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.11642615-teal)](https://doi.org/10.5281/zenodo.19602764) [![Test Status](https://github.com/donishadsmith/neurocaps/actions/workflows/testing.yaml/badge.svg)](https://github.com/donishadsmith/neurocaps/actions/workflows/testing.yaml) [![Documentation Status](https://readthedocs.org/projects/neurocaps/badge/?version=stable)](http://neurocaps.readthedocs.io/en/stable/?badge=stable) [![codecov](https://codecov.io/github/donishadsmith/neurocaps/branch/main/graph/badge.svg?token=WS2V7I16WF)](https://codecov.io/github/donishadsmith/neurocaps) diff --git a/docker/Dockerfile b/docker/Dockerfile index b37534b1..2cbd2db3 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -35,29 +35,26 @@ RUN apt-get update && apt-get install -y \ ln -sf /usr/bin/python3.12 /usr/bin/python3 && \ curl https://bootstrap.pypa.io/get-pip.py | python3.12 -# Create user and home directory; -# recursively change ownership of home directory to user; -# add user to sudo group -# Append no password requirement for sudo users to sudoers -RUN useradd -md /home/user user && \ - chown -R user /home/user && \ - adduser user sudo && \ - echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +ENV NILEARN_SHARED_DATA=/opt/neurocaps/data/nilearn_data \ + NEUROMAPS_DATA=/opt/neurocaps/data/neuromaps-data \ + NEUROCAPS_DATA=/opt/neurocaps/data/neurocaps_data -WORKDIR /home/user -ENV HOME="/home/user" +RUN mkdir -p /opt/neurocaps/src \ + /opt/neurocaps/demos \ + $NILEARN_SHARED_DATA \ + $NEUROMAPS_DATA \ + $NEUROCAPS_DATA + +WORKDIR /opt/neurocaps COPY neurocaps/ src/neurocaps/ -COPY demos/* demos/ -COPY docker/scripts/entrypoint.sh /usr/local/bin COPY pyproject.toml src/ -COPY tests/data/nilearn_data /home/user/nilearn_data -COPY tests/data/neuromaps-data /home/user/neuromaps-data +COPY demos/* demos/ +COPY tests/data/nilearn_data $NILEARN_SHARED_DATA +COPY tests/data/neuromaps-data $NEUROMAPS_DATA +COPY docker/scripts/entrypoint.sh /usr/local/bin/ -RUN chown -R user:user /home/user/ && \ - chmod -R 775 /home/user/ && \ - chown user /usr/local/bin/entrypoint.sh && \ - sed -i "s/\r$//" /usr/local/bin/entrypoint.sh && \ +RUN sed -i "s/\r$//" /usr/local/bin/entrypoint.sh && \ chmod +x /usr/local/bin/entrypoint.sh RUN pip install --upgrade pip setuptools && \ @@ -66,12 +63,12 @@ RUN pip install --upgrade pip setuptools && \ RUN yes | plotly_get_chrome -EXPOSE 9999 -LABEL maintainer="Donisha Smith " +RUN chmod -R a+rwX /opt/neurocaps RUN mkdir -p /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix -USER user +EXPOSE 9999 +LABEL maintainer="Donisha Smith " ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] diff --git a/docker/scripts/entrypoint.sh b/docker/scripts/entrypoint.sh index b21a861b..1c387013 100644 --- a/docker/scripts/entrypoint.sh +++ b/docker/scripts/entrypoint.sh @@ -2,11 +2,7 @@ Xvfb :0 -screen 0 1600x1200x24 & export DISPLAY=:0 -while !xset q &> /dev/null; do - sleep 0.1 -done - -if [ "$1" = "notebook" ]; then +if [[ "$1" == "notebook" || "$1" == "jupyter" || "$1" == "jupyter-notebook" ]]; then exec jupyter notebook --allow-root --no-browser --ip=0.0.0.0 --port=9999 else exec "$@" diff --git a/docs/introduction.rst b/docs/introduction.rst index 5dea451b..2a09424a 100644 --- a/docs/introduction.rst +++ b/docs/introduction.rst @@ -9,7 +9,7 @@ :alt: Python Versions .. image:: https://img.shields.io/badge/DOI-10.5281%2Fzenodo.11642615-teal - :target: https://doi.org/10.5281/zenodo.18529846 + :target: https://doi.org/10.5281/zenodo.19602764 :alt: DOI .. image:: https://img.shields.io/badge/Source%20Code-neurocaps-purple diff --git a/neurocaps/__init__.py b/neurocaps/__init__.py index 00bee7fd..a580249d 100644 --- a/neurocaps/__init__.py +++ b/neurocaps/__init__.py @@ -22,4 +22,4 @@ __all__ = ["analysis", "extraction", "exceptions", "utils"] # Version in single place -__version__ = "0.37.2" +__version__ = "0.37.3" diff --git a/neurocaps/utils/datasets/_fetch.py b/neurocaps/utils/datasets/_fetch.py index bbc3fd69..52de954b 100644 --- a/neurocaps/utils/datasets/_fetch.py +++ b/neurocaps/utils/datasets/_fetch.py @@ -38,10 +38,13 @@ def is_valid_preset(name: str) -> None: def get_data_dir() -> str: """ - Gets the full path for 'neurocaps_data' in the users home directory. If it does not - exist, then the directory and the subfolders are created. + Gets the full path for 'neurocaps_data' in the users home directory or path set by + environmental variable. If it does not exist, then the directory and the subfolders + are created. """ - data_dir = os.path.expanduser(os.path.join("~", "neurocaps_data")) + if not (data_dir := os.environ.get("NEUROCAPS_DATA")): + data_dir = os.path.expanduser(os.path.join("~", "neurocaps_data")) + # Create manually instead of using `fetch_files` to notify user that a directory was created io_utils.makedir(data_dir) diff --git a/neurocaps/utils/parcellations.py b/neurocaps/utils/parcellations.py index 6e158d26..5803dbd4 100644 --- a/neurocaps/utils/parcellations.py +++ b/neurocaps/utils/parcellations.py @@ -24,6 +24,10 @@ def fetch_preset_parcel_approach( Open Science Framework (OSF) if the corresponding files are not present in the directory. + .. versionchanged:: 0.37.3 + The data directory location can now be overridden via the ``NEUROCAPS_DATA`` + environment variable. If unset, the default ``~/neurocaps_data`` location is used. + Parameters ---------- name : :obj:`str`