mrsiprep-docker 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: mrsiprep-docker
3
+ Version: 1.0.0
4
+ Summary: A wrapper for generating Docker commands to run MRSIPrep using regular BIDS App syntax
5
+ Author-email: Federico Lucchetti <federico.lucchetti@unil.ch>
6
+ License: CHUV academic non-commercial research license
7
+ Project-URL: Homepage, https://github.com/MRSI-Psychosis-UP/MRSIPrep
8
+ Project-URL: Documentation, https://mrsiprep.readthedocs.io/
9
+ Project-URL: Docker Images, https://hub.docker.com/r/mrsiup/mrsiprep/tags/
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: License :: Other/Proprietary License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+
17
+ # The *MRSIPrep* on Docker wrapper
18
+
19
+ MRSIPrep is distributed as a Docker image; there is no supported host
20
+ installation of the pipeline itself. This is a lightweight, dependency-free
21
+ Python wrapper (mirroring the `fmriprep-docker` wrapper) that builds and runs
22
+ the appropriate `docker run` command using the normal MRSIPrep BIDS App
23
+ syntax. Docker must be installed and running (check with `docker info`).
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ pip install mrsiprep-docker
29
+ ```
30
+
31
+ ## Use
32
+
33
+ ```bash
34
+ mrsiprep-docker /path/to/bids /path/to/derivatives participant \
35
+ --participant-label S001 --session-label V1 \
36
+ --mode mni-norm --nthreads 8 \
37
+ --fs-license-file /path/to/freesurfer/license.txt
38
+ ```
39
+
40
+ This generates and runs the equivalent of:
41
+
42
+ ```bash
43
+ docker run --rm -it -u "$(id -u):$(id -g)" \
44
+ -e TZ="$(cat /etc/timezone)" \
45
+ -v /path/to/freesurfer/license.txt:/opt/freesurfer/license.txt:ro \
46
+ -e FS_LICENSE=/opt/freesurfer/license.txt \
47
+ -v /path/to/bids:/data:ro \
48
+ -v /path/to/derivatives:/out \
49
+ mrsiup/mrsiprep:cpu \
50
+ /data /out participant \
51
+ --participant-label S001 --session-label V1 \
52
+ --mode mni-norm --nthreads 8
53
+ ```
54
+
55
+ All ordinary `mrsiprep` arguments (`--mode`, `--participant-label`,
56
+ `--tissue-backend`, `--parcellation-mode`, `--nproc`, `--verbose`, ...) are
57
+ passed straight through to the container unchanged. The wrapper only
58
+ special-cases the few options that need a bind mount or an environment
59
+ variable: `--fs-license-file`, `--fs-subjects-dir`, `--work-dir`, and
60
+ `--participants`.
61
+
62
+ `-u "$(id -u):$(id -g)"` (the default; override with `-u`/`--user`) plus the
63
+ container's own permission-fixing entrypoint means output files are owned by
64
+ the invoking user, not root. `-e TZ=...` (skip with `--no-tz`) keeps console
65
+ and logbook timestamps in sync with the host clock.
66
+
67
+ See the main repository's documentation for the full MRSIPrep CLI reference:
68
+ https://mrsiprep.readthedocs.io/
@@ -0,0 +1,52 @@
1
+ # The *MRSIPrep* on Docker wrapper
2
+
3
+ MRSIPrep is distributed as a Docker image; there is no supported host
4
+ installation of the pipeline itself. This is a lightweight, dependency-free
5
+ Python wrapper (mirroring the `fmriprep-docker` wrapper) that builds and runs
6
+ the appropriate `docker run` command using the normal MRSIPrep BIDS App
7
+ syntax. Docker must be installed and running (check with `docker info`).
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install mrsiprep-docker
13
+ ```
14
+
15
+ ## Use
16
+
17
+ ```bash
18
+ mrsiprep-docker /path/to/bids /path/to/derivatives participant \
19
+ --participant-label S001 --session-label V1 \
20
+ --mode mni-norm --nthreads 8 \
21
+ --fs-license-file /path/to/freesurfer/license.txt
22
+ ```
23
+
24
+ This generates and runs the equivalent of:
25
+
26
+ ```bash
27
+ docker run --rm -it -u "$(id -u):$(id -g)" \
28
+ -e TZ="$(cat /etc/timezone)" \
29
+ -v /path/to/freesurfer/license.txt:/opt/freesurfer/license.txt:ro \
30
+ -e FS_LICENSE=/opt/freesurfer/license.txt \
31
+ -v /path/to/bids:/data:ro \
32
+ -v /path/to/derivatives:/out \
33
+ mrsiup/mrsiprep:cpu \
34
+ /data /out participant \
35
+ --participant-label S001 --session-label V1 \
36
+ --mode mni-norm --nthreads 8
37
+ ```
38
+
39
+ All ordinary `mrsiprep` arguments (`--mode`, `--participant-label`,
40
+ `--tissue-backend`, `--parcellation-mode`, `--nproc`, `--verbose`, ...) are
41
+ passed straight through to the container unchanged. The wrapper only
42
+ special-cases the few options that need a bind mount or an environment
43
+ variable: `--fs-license-file`, `--fs-subjects-dir`, `--work-dir`, and
44
+ `--participants`.
45
+
46
+ `-u "$(id -u):$(id -g)"` (the default; override with `-u`/`--user`) plus the
47
+ container's own permission-fixing entrypoint means output files are owned by
48
+ the invoking user, not root. `-e TZ=...` (skip with `--no-tz`) keeps console
49
+ and logbook timestamps in sync with the host clock.
50
+
51
+ See the main repository's documentation for the full MRSIPrep CLI reference:
52
+ https://mrsiprep.readthedocs.io/
@@ -0,0 +1,32 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "mrsiprep-docker"
7
+ version = "1.0.0"
8
+ description = "A wrapper for generating Docker commands to run MRSIPrep using regular BIDS App syntax"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = { text = "CHUV academic non-commercial research license" }
12
+ authors = [
13
+ { name = "Federico Lucchetti", email = "federico.lucchetti@unil.ch" }
14
+ ]
15
+ dependencies = []
16
+ classifiers = [
17
+ "Development Status :: 5 - Production/Stable",
18
+ "Intended Audience :: Science/Research",
19
+ "License :: Other/Proprietary License",
20
+ "Programming Language :: Python :: 3",
21
+ ]
22
+
23
+ [project.urls]
24
+ Homepage = "https://github.com/MRSI-Psychosis-UP/MRSIPrep"
25
+ Documentation = "https://mrsiprep.readthedocs.io/"
26
+ "Docker Images" = "https://hub.docker.com/r/mrsiup/mrsiprep/tags/"
27
+
28
+ [project.scripts]
29
+ mrsiprep-docker = "mrsiprep_docker.__main__:main"
30
+
31
+ [tool.setuptools.packages.find]
32
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,15 @@
1
+ """The MRSIPrep on Docker wrapper."""
2
+
3
+ from __future__ import annotations
4
+
5
+ try:
6
+ from ._version import __version__
7
+ except ImportError:
8
+ try:
9
+ from importlib.metadata import version
10
+
11
+ __version__ = version("mrsiprep-docker")
12
+ except Exception:
13
+ __version__ = "0+unknown"
14
+
15
+ __all__ = ["__version__"]
@@ -0,0 +1,197 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ The *MRSIPrep* on Docker wrapper
4
+
5
+ A lightweight, dependency-free Python wrapper that builds and runs the
6
+ ``docker run ...`` command for MRSIPrep, mirroring the fMRIPrep-on-Docker
7
+ wrapper's design. Docker must be installed and running (check with
8
+ ``docker info``). Native ``mrsiprep`` arguments are passed straight through;
9
+ this wrapper only adds a handful of Docker-specific conveniences:
10
+
11
+ - translates ``bids_dir``/``output_dir``/``--fs-subjects-dir``/``--work-dir``
12
+ into bind mounts,
13
+ - mounts ``--fs-license-file`` and sets ``FS_LICENSE``,
14
+ - passes the host timezone through (``-e TZ=...``) so container timestamps
15
+ match the host clock,
16
+ - offers to pull the image if it isn't present locally,
17
+ - forwards HOST_UID/HOST_GID so output files land owned by the invoking user
18
+ (see docker/entrypoint.sh in the main repository).
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ import argparse
24
+ import os
25
+ import subprocess
26
+ import sys
27
+ from pathlib import Path
28
+
29
+ from . import __version__
30
+
31
+ __bugreports__ = "https://github.com/MRSI-Psychosis-UP/MRSIPrep/issues"
32
+
33
+ MISSING = """
34
+ Image '{}' is missing
35
+ Would you like to download? [Y/n] """
36
+
37
+
38
+ def check_docker() -> int:
39
+ """-1 docker not found, 0 found but daemon unreachable, 1 OK."""
40
+ try:
41
+ ret = subprocess.run(["docker", "version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
42
+ except OSError as exc:
43
+ from errno import ENOENT
44
+
45
+ if exc.errno == ENOENT:
46
+ return -1
47
+ raise
48
+ if ret.stderr.startswith(b"Cannot connect to the Docker daemon."):
49
+ return 0
50
+ return 1
51
+
52
+
53
+ def check_image(image: str) -> bool:
54
+ ret = subprocess.run(["docker", "images", "-q", image], stdout=subprocess.PIPE)
55
+ return bool(ret.stdout)
56
+
57
+
58
+ def get_parser() -> argparse.ArgumentParser:
59
+ parser = argparse.ArgumentParser(
60
+ description="MRSIPrep Docker wrapper: runs mrsiprep:cpu with the usual BIDS App syntax.",
61
+ formatter_class=argparse.RawTextHelpFormatter,
62
+ add_help=False,
63
+ )
64
+ parser.add_argument("-h", "--help", action="store_true", help="show this help message")
65
+ parser.add_argument("--version", action="store_true", help="show wrapper and image version")
66
+ parser.add_argument("bids_dir", nargs="?", default="", help="the root folder of a BIDS dataset")
67
+ parser.add_argument("output_dir", nargs="?", default="", help="the output derivatives directory")
68
+ parser.add_argument("analysis_level", nargs="?", default="participant", choices=["participant"])
69
+
70
+ g_wrap = parser.add_argument_group("Wrapper (Docker-only) options")
71
+ g_wrap.add_argument("--image", default="mrsiup/mrsiprep:cpu", help="Docker image to use")
72
+ g_wrap.add_argument("--fs-license-file", metavar="PATH", type=os.path.abspath, help="path to a FreeSurfer license.txt, mounted and exported as FS_LICENSE")
73
+ g_wrap.add_argument("--fs-subjects-dir", metavar="PATH", type=os.path.abspath, help="existing FreeSurfer SUBJECTS_DIR to mount and reuse")
74
+ g_wrap.add_argument("--work-dir", metavar="PATH", type=os.path.abspath, help="scratch directory, mounted at /scratch")
75
+ g_wrap.add_argument("--participants", metavar="PATH", type=os.path.abspath, help="participants TSV/CSV, mounted read-only")
76
+ g_wrap.add_argument("-u", "--user", help="run container as USER[:GROUP] instead of root (default: root, which self-chowns outputs to your user afterward)")
77
+ g_wrap.add_argument("--no-tz", action="store_true", help="do not forward the host timezone to the container")
78
+ g_wrap.add_argument("--shell", action="store_true", help="open a shell in the image instead of running mrsiprep")
79
+
80
+ return parser
81
+
82
+
83
+ def main() -> int:
84
+ parser = get_parser()
85
+ opts, unknown_args = parser.parse_known_args()
86
+
87
+ if (opts.bids_dir, opts.output_dir, opts.version, opts.help) == ("", "", False, False):
88
+ opts.help = True
89
+
90
+ # mrsiprep's own CLI has no --version flag to query inside the container,
91
+ # so this only ever reports the wrapper's own version and configured
92
+ # image -- no need to touch Docker at all.
93
+ if opts.version:
94
+ print(f"mrsiprep-docker wrapper {__version__}")
95
+ print(f"image: {opts.image}")
96
+ return 0
97
+
98
+ check = check_docker()
99
+ if check < 1:
100
+ if opts.help:
101
+ parser.print_help()
102
+ if check == -1:
103
+ print("mrsiprep-docker: could not find the docker command. Is Docker installed?")
104
+ else:
105
+ print("mrsiprep-docker: make sure you have permission to run 'docker' (is the daemon running?)")
106
+ return 1
107
+
108
+ if not check_image(opts.image):
109
+ resp = "Y"
110
+ if opts.help:
111
+ parser.print_help()
112
+ if opts.help:
113
+ try:
114
+ resp = input(MISSING.format(opts.image))
115
+ except KeyboardInterrupt:
116
+ print()
117
+ return 1
118
+ if resp not in ("y", "Y", ""):
119
+ return 0
120
+ print("Downloading. This may take a while...")
121
+ pull = subprocess.run(["docker", "pull", opts.image])
122
+ if pull.returncode:
123
+ return pull.returncode
124
+
125
+ command = ["docker", "run", "--rm"]
126
+ if sys.stdin.isatty() and sys.stdout.isatty():
127
+ command.append("-it")
128
+
129
+ # The container runs as root by default and chowns the output directory
130
+ # back to its owner afterward (see docker/entrypoint.sh); pass -u only if
131
+ # the caller explicitly asks, matching plain `docker run` behavior.
132
+ if opts.user:
133
+ command.extend(["-u", opts.user])
134
+ else:
135
+ command.extend(["-e", f"HOST_UID={os.getuid()}", "-e", f"HOST_GID={os.getgid()}"])
136
+
137
+ if not opts.no_tz:
138
+ tz_file = Path("/etc/timezone")
139
+ if tz_file.exists():
140
+ command.extend(["-e", f"TZ={tz_file.read_text().strip()}"])
141
+
142
+ if opts.fs_license_file:
143
+ command.extend(["-v", f"{opts.fs_license_file}:/opt/freesurfer/license.txt:ro", "-e", "FS_LICENSE=/opt/freesurfer/license.txt"])
144
+
145
+ main_args: list[str] = []
146
+ if opts.bids_dir:
147
+ command.extend(["-v", f"{os.path.abspath(opts.bids_dir)}:/data:ro"])
148
+ main_args.append("/data")
149
+ if opts.output_dir:
150
+ os.makedirs(opts.output_dir, exist_ok=True)
151
+ command.extend(["-v", f"{os.path.abspath(opts.output_dir)}:/out"])
152
+ main_args.append("/out")
153
+ main_args.append(opts.analysis_level)
154
+
155
+ if opts.fs_subjects_dir:
156
+ command.extend(["-v", f"{opts.fs_subjects_dir}:/opt/subjects"])
157
+ unknown_args.extend(["--fs-subjects-dir", "/opt/subjects"])
158
+
159
+ if opts.work_dir:
160
+ os.makedirs(opts.work_dir, exist_ok=True)
161
+ command.extend(["-v", f"{opts.work_dir}:/scratch"])
162
+ unknown_args.extend(["--work-dir", "/scratch"])
163
+
164
+ if opts.participants:
165
+ command.extend(["-v", f"{opts.participants}:/tmp/participants{Path(opts.participants).suffix}:ro"])
166
+ unknown_args.extend(["--participants", f"/tmp/participants{Path(opts.participants).suffix}"])
167
+
168
+ if opts.shell:
169
+ command.append("--entrypoint=bash")
170
+
171
+ command.append(opts.image)
172
+
173
+ if opts.help:
174
+ command.append("-h")
175
+ target_help = subprocess.check_output(command).decode()
176
+ print(parser.format_help())
177
+ print("\n--- mrsiprep (inside the container) ---\n")
178
+ print(target_help)
179
+ return 0
180
+
181
+ if not opts.shell:
182
+ command.extend(main_args)
183
+ command.extend(unknown_args)
184
+
185
+ print("RUNNING: " + " ".join(command))
186
+ ret = subprocess.run(command)
187
+ if ret.returncode:
188
+ print(f"MRSIPrep: please report errors to {__bugreports__}")
189
+ return ret.returncode
190
+
191
+
192
+ if __name__ == "__main__":
193
+ if "__main__.py" in sys.argv[0]:
194
+ from . import __name__ as module
195
+
196
+ sys.argv[0] = f"{sys.executable} -m {module}"
197
+ sys.exit(main())
@@ -0,0 +1,68 @@
1
+ Metadata-Version: 2.4
2
+ Name: mrsiprep-docker
3
+ Version: 1.0.0
4
+ Summary: A wrapper for generating Docker commands to run MRSIPrep using regular BIDS App syntax
5
+ Author-email: Federico Lucchetti <federico.lucchetti@unil.ch>
6
+ License: CHUV academic non-commercial research license
7
+ Project-URL: Homepage, https://github.com/MRSI-Psychosis-UP/MRSIPrep
8
+ Project-URL: Documentation, https://mrsiprep.readthedocs.io/
9
+ Project-URL: Docker Images, https://hub.docker.com/r/mrsiup/mrsiprep/tags/
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: License :: Other/Proprietary License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+
17
+ # The *MRSIPrep* on Docker wrapper
18
+
19
+ MRSIPrep is distributed as a Docker image; there is no supported host
20
+ installation of the pipeline itself. This is a lightweight, dependency-free
21
+ Python wrapper (mirroring the `fmriprep-docker` wrapper) that builds and runs
22
+ the appropriate `docker run` command using the normal MRSIPrep BIDS App
23
+ syntax. Docker must be installed and running (check with `docker info`).
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ pip install mrsiprep-docker
29
+ ```
30
+
31
+ ## Use
32
+
33
+ ```bash
34
+ mrsiprep-docker /path/to/bids /path/to/derivatives participant \
35
+ --participant-label S001 --session-label V1 \
36
+ --mode mni-norm --nthreads 8 \
37
+ --fs-license-file /path/to/freesurfer/license.txt
38
+ ```
39
+
40
+ This generates and runs the equivalent of:
41
+
42
+ ```bash
43
+ docker run --rm -it -u "$(id -u):$(id -g)" \
44
+ -e TZ="$(cat /etc/timezone)" \
45
+ -v /path/to/freesurfer/license.txt:/opt/freesurfer/license.txt:ro \
46
+ -e FS_LICENSE=/opt/freesurfer/license.txt \
47
+ -v /path/to/bids:/data:ro \
48
+ -v /path/to/derivatives:/out \
49
+ mrsiup/mrsiprep:cpu \
50
+ /data /out participant \
51
+ --participant-label S001 --session-label V1 \
52
+ --mode mni-norm --nthreads 8
53
+ ```
54
+
55
+ All ordinary `mrsiprep` arguments (`--mode`, `--participant-label`,
56
+ `--tissue-backend`, `--parcellation-mode`, `--nproc`, `--verbose`, ...) are
57
+ passed straight through to the container unchanged. The wrapper only
58
+ special-cases the few options that need a bind mount or an environment
59
+ variable: `--fs-license-file`, `--fs-subjects-dir`, `--work-dir`, and
60
+ `--participants`.
61
+
62
+ `-u "$(id -u):$(id -g)"` (the default; override with `-u`/`--user`) plus the
63
+ container's own permission-fixing entrypoint means output files are owned by
64
+ the invoking user, not root. `-e TZ=...` (skip with `--no-tz`) keeps console
65
+ and logbook timestamps in sync with the host clock.
66
+
67
+ See the main repository's documentation for the full MRSIPrep CLI reference:
68
+ https://mrsiprep.readthedocs.io/
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/mrsiprep_docker/__init__.py
4
+ src/mrsiprep_docker/__main__.py
5
+ src/mrsiprep_docker.egg-info/PKG-INFO
6
+ src/mrsiprep_docker.egg-info/SOURCES.txt
7
+ src/mrsiprep_docker.egg-info/dependency_links.txt
8
+ src/mrsiprep_docker.egg-info/entry_points.txt
9
+ src/mrsiprep_docker.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ mrsiprep-docker = mrsiprep_docker.__main__:main
@@ -0,0 +1 @@
1
+ mrsiprep_docker