templateflow 24.2.1__tar.gz → 24.2.2__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.
Files changed (51) hide show
  1. {templateflow-24.2.1 → templateflow-24.2.2}/.circleci/config.yml +131 -109
  2. {templateflow-24.2.1 → templateflow-24.2.2}/.maint/update_requirements.py +3 -3
  3. {templateflow-24.2.1 → templateflow-24.2.2}/CHANGES.rst +6 -1
  4. {templateflow-24.2.1 → templateflow-24.2.2}/PKG-INFO +15 -9
  5. {templateflow-24.2.1 → templateflow-24.2.2}/pyproject.toml +7 -5
  6. {templateflow-24.2.1 → templateflow-24.2.2}/templateflow/__init__.py +2 -0
  7. {templateflow-24.2.1 → templateflow-24.2.2}/templateflow/_loader.py +1 -0
  8. {templateflow-24.2.1 → templateflow-24.2.2}/templateflow/_version.py +2 -2
  9. {templateflow-24.2.1 → templateflow-24.2.2}/templateflow/api.py +12 -16
  10. {templateflow-24.2.1 → templateflow-24.2.2}/templateflow/cli.py +14 -21
  11. {templateflow-24.2.1 → templateflow-24.2.2}/templateflow/conf/__init__.py +20 -22
  12. {templateflow-24.2.1 → templateflow-24.2.2}/templateflow/conf/_s3.py +6 -5
  13. {templateflow-24.2.1 → templateflow-24.2.2}/templateflow/conf/bids.py +2 -3
  14. {templateflow-24.2.1 → templateflow-24.2.2}/templateflow/tests/test_api.py +3 -7
  15. {templateflow-24.2.1/templateflow/conf → templateflow-24.2.2/templateflow}/tests/test_conf.py +23 -8
  16. templateflow-24.2.2/templateflow/tests/test_s3.py +89 -0
  17. {templateflow-24.2.1 → templateflow-24.2.2}/templateflow/tests/test_version.py +1 -0
  18. templateflow-24.2.1/templateflow/conf/tests/test_s3.py +0 -74
  19. templateflow-24.2.1/templateflow/tests/__init__.py +0 -0
  20. templateflow-24.2.1/templateflow/tests/test_conf.py +0 -52
  21. {templateflow-24.2.1 → templateflow-24.2.2}/.gitattributes +0 -0
  22. {templateflow-24.2.1 → templateflow-24.2.2}/.github/workflows/codespell.yml +0 -0
  23. {templateflow-24.2.1 → templateflow-24.2.2}/.github/workflows/pythonpackage.yml +0 -0
  24. {templateflow-24.2.1 → templateflow-24.2.2}/.gitignore +0 -0
  25. {templateflow-24.2.1 → templateflow-24.2.2}/.gitmodules +0 -0
  26. {templateflow-24.2.1 → templateflow-24.2.2}/.maint/update_changes.sh +0 -0
  27. {templateflow-24.2.1 → templateflow-24.2.2}/.neurodebian/neurodebian.gpg +0 -0
  28. {templateflow-24.2.1 → templateflow-24.2.2}/.zenodo.json +0 -0
  29. {templateflow-24.2.1 → templateflow-24.2.2}/LICENSE +0 -0
  30. {templateflow-24.2.1 → templateflow-24.2.2}/README.rst +0 -0
  31. {templateflow-24.2.1 → templateflow-24.2.2}/codecov.yml +0 -0
  32. {templateflow-24.2.1 → templateflow-24.2.2}/docs/Makefile +0 -0
  33. {templateflow-24.2.1 → templateflow-24.2.2}/docs/_static/RTD-advanced-conf.png +0 -0
  34. {templateflow-24.2.1 → templateflow-24.2.2}/docs/_static/git.png +0 -0
  35. {templateflow-24.2.1 → templateflow-24.2.2}/docs/_templates/versions.html +0 -0
  36. {templateflow-24.2.1 → templateflow-24.2.2}/docs/api.rst +0 -0
  37. {templateflow-24.2.1 → templateflow-24.2.2}/docs/changes.rst +0 -0
  38. {templateflow-24.2.1 → templateflow-24.2.2}/docs/cli.rst +0 -0
  39. {templateflow-24.2.1 → templateflow-24.2.2}/docs/conf.py +0 -0
  40. {templateflow-24.2.1 → templateflow-24.2.2}/docs/datalad.rst +0 -0
  41. {templateflow-24.2.1 → templateflow-24.2.2}/docs/environment.yml +0 -0
  42. {templateflow-24.2.1 → templateflow-24.2.2}/docs/examples.rst +0 -0
  43. {templateflow-24.2.1 → templateflow-24.2.2}/docs/index.rst +0 -0
  44. {templateflow-24.2.1 → templateflow-24.2.2}/docs/installation.rst +0 -0
  45. {templateflow-24.2.1 → templateflow-24.2.2}/docs/links.rst +0 -0
  46. {templateflow-24.2.1 → templateflow-24.2.2}/docs/reference/.gitignore +0 -0
  47. {templateflow-24.2.1 → templateflow-24.2.2}/templateflow/conf/config.json +0 -0
  48. {templateflow-24.2.1 → templateflow-24.2.2}/templateflow/conf/templateflow-skel.md5 +0 -0
  49. {templateflow-24.2.1 → templateflow-24.2.2}/templateflow/conf/templateflow-skel.zip +0 -0
  50. {templateflow-24.2.1/templateflow/conf → templateflow-24.2.2/templateflow}/tests/__init__.py +0 -0
  51. {templateflow-24.2.1 → templateflow-24.2.2}/templateflow/tests/test_multiproc.py +0 -0
@@ -1,44 +1,85 @@
1
- version: 2
1
+ version: 2.1
2
+ orbs:
3
+ docker: circleci/docker@2.7.0
4
+ codecov: codecov/codecov@4.1.0
5
+ python: circleci/python@2.1.1
6
+
2
7
  jobs:
3
- tests:
4
- docker:
5
- - image: cimg/python:3.11
6
- auth:
7
- username: $DOCKER_USER
8
- password: $DOCKER_PAT
9
- working_directory: /tmp/tests
10
- environment:
11
- - OSF_MIRROR_PATH: /tmp/data/templateflow
12
- steps:
13
- - checkout:
14
- path: /tmp/src/templateflow
8
+ build:
9
+ executor:
10
+ name: python/default
11
+ tag: '3.12'
12
+
13
+ # docker:
14
+ # - auth:
15
+ # username: $DOCKER_USERNAME
16
+ # password: $DOCKER_PASSWORD
15
17
 
18
+ steps:
19
+ - checkout
16
20
  - run:
17
- name: Generate requirements.txt
18
21
  command: |
19
- python /tmp/src/templateflow/.maint/update_requirements.py
20
-
21
- - restore_cache:
22
- keys:
23
- - deps-v11-{{ checksum "/tmp/src/templateflow/dev-requirements.txt"}}-{{ epoch }}
24
- - deps-v11-{{ checksum "/tmp/src/templateflow/dev-requirements.txt"}}-
25
- - deps-v11-
22
+ echo 'build' > requirements.txt
23
+ echo 'wheel' >> requirements.txt
24
+ echo 'twine' >> requirements.txt
25
+ - python/install-packages:
26
+ pkg-manager: pip
27
+ cache-version: build-v1
26
28
  - run:
27
- name: Prepare environment
28
29
  command: |
29
- python -m venv /tmp/venv
30
- source /tmp/venv/bin/activate
31
- python -m pip install -U pip
32
- python -m pip install -r /tmp/src/templateflow/dev-requirements.txt
33
- python -m pip install -U "datalad ~= 0.19.0"
34
- python -m pip install -U build hatch twine pkginfo codecov
30
+ python -m build
31
+ python -m twine check dist/*
32
+ name: Test packaging
33
+ - persist_to_workspace:
34
+ root: ~/project
35
+ paths:
36
+ - .
37
+
38
+ deploy_pypi:
39
+ executor:
40
+ name: python/default
41
+ tag: '3.12'
42
+
43
+ # docker:
44
+ # - auth:
45
+ # username: $DOCKER_USERNAME
46
+ # password: $DOCKER_PASSWORD
47
+
48
+ steps:
49
+ - attach_workspace:
50
+ at: ~/project
51
+
52
+ - python/install-packages:
53
+ args: twine
54
+ pkg-manager: pip
35
55
 
56
+ - run:
57
+ command: python -m twine upload dist/*
58
+ name: Upload to Pypi
59
+
60
+ tests:
61
+ executor:
62
+ name: python/default
63
+ tag: '3.12'
64
+
65
+ # docker:
66
+ # - auth:
67
+ # username: $DOCKER_USERNAME
68
+ # password: $DOCKER_PASSWORD
69
+
70
+ environment:
71
+ - OSF_MIRROR_PATH: /tmp/data/templateflow
72
+ steps:
73
+ - restore_cache:
74
+ keys:
75
+ - annex-v1-{{ epoch }}
76
+ - annex-v1-
36
77
  - run:
37
78
  name: Install git and git-annex
38
79
  command: |
39
80
  if [[ ! -e "/tmp/cache/git-annex-standalone.tar.gz" ]]; then
40
81
  wget -O- http://neuro.debian.net/lists/focal.us-ca.full | sudo tee /etc/apt/sources.list.d/neurodebian.sources.list
41
- sudo apt-key add /tmp/src/templateflow/.neurodebian/neurodebian.gpg
82
+ sudo apt-key add .neurodebian/neurodebian.gpg
42
83
  sudo apt-key adv --recv-keys --keyserver hkps://keys.openpgp.org 0xA5D32F012649A5A9 || true
43
84
  sudo apt update && sudo apt-get install -y --no-install-recommends git-annex-standalone
44
85
  mkdir -p /tmp/cache
@@ -50,83 +91,80 @@ jobs:
50
91
  git config --global user.email "email@domain.com"
51
92
 
52
93
  - save_cache:
53
- key: deps-v11-{{ checksum "/tmp/src/templateflow/dev-requirements.txt"}}-{{ epoch }}
94
+ key: annex-v1-{{ epoch }}
54
95
  paths:
55
96
  - "/tmp/cache"
56
- - "/tmp/venv"
97
+
98
+ - attach_workspace:
99
+ at: ~/project
57
100
 
58
101
  - run:
59
- name: Test packaging
60
102
  command: |
61
- source /tmp/venv/bin/activate
62
- cd /tmp/src/templateflow
63
- python -m build
64
- python -m twine check dist/*
103
+ python .maint/update_requirements.py
104
+ name: Generate requirements.txt
105
+
106
+ - python/install-packages:
107
+ pip-dependency-file: dev-requirements.txt
108
+ pkg-manager: pip
109
+ cache-version: v1
65
110
 
66
111
  - run:
67
- name: Run tests (w/ DataLad)
112
+ name: Run tests (config and others)
68
113
  command: |
69
- source /tmp/venv/bin/activate
70
- export TEMPLATEFLOW_USE_DATALAD=on
71
- pytest --junit-xml=/tmp/tests/datalad.xml --cov templateflow --cov-report xml:/tmp/cov_api_dl.xml \
72
- --doctest-modules /tmp/src/templateflow/templateflow
114
+ python -m pytest \
115
+ --junit-xml=~/tests/conftests.xml --cov templateflow --cov-report xml:~/coverage/cov_config.xml \
116
+ templateflow/tests/
117
+
118
+ - codecov/upload:
119
+ file: ~/coverage/cov_config.xml
120
+ flags: config
121
+ upload_name: General
73
122
 
74
123
  - run:
75
- name: Submit api test coverage
124
+ name: Run tests (w/ DataLad)
76
125
  command: |
77
- source /tmp/venv/bin/activate
78
- codecov --file /tmp/cov_api_dl.xml --root /tmp/src/templateflow \
79
- --flags api,datalad -e CIRCLE_JOB
126
+ mkdir -p ~/tests/ ~/coverage/
127
+ export TEMPLATEFLOW_USE_DATALAD=on
128
+ python -m pytest \
129
+ --junit-xml=~/tests/datalad.xml --cov templateflow --cov-report xml:~/coverage/cov_api_dl.xml \
130
+ --doctest-modules templateflow/api.py
131
+
132
+ - codecov/upload:
133
+ file: ~/coverage/cov_api_dl.xml
134
+ flags: api,datalad
135
+ upload_name: Datalad tests
80
136
 
81
137
  - run:
82
138
  name: Run tests (pulling from S3)
83
139
  command: |
84
- source /tmp/venv/bin/activate
85
140
  export TEMPLATEFLOW_USE_DATALAD=off
86
141
  export TEMPLATEFLOW_HOME=$HOME/templateflow-s3
87
- pytest --junit-xml=/tmp/tests/s3.xml --cov templateflow --cov-report xml:/tmp/cov_api_s3.xml \
88
- --doctest-modules /tmp/src/templateflow/templateflow/api.py
142
+ python -m pytest \
143
+ --junit-xml=~/tests/s3.xml --cov templateflow --cov-report xml:~/coverage/cov_api_s3.xml \
144
+ --doctest-modules templateflow/api.py
89
145
 
90
- - run:
91
- name: Submit api test coverage
92
- command: |
93
- source /tmp/venv/bin/activate
94
- codecov --file /tmp/cov_api_s3.xml --root /tmp/src/templateflow \
95
- --flags api,s3 -e CIRCLE_JOB
146
+ - codecov/upload:
147
+ file: ~/coverage/cov_api_s3.xml
148
+ flags: api,s3
149
+ upload_name: S3 tests
96
150
 
97
151
  - run:
98
152
  name: Run tests (w/ DataLad, bypassed via S3)
99
153
  command: |
100
- source /tmp/venv/bin/activate
101
154
  export TEMPLATEFLOW_USE_DATALAD=off
102
155
  export TEMPLATEFLOW_HOME=$HOME/templateflow-clean
103
156
  datalad install -r -s https://github.com/templateflow/templateflow $TEMPLATEFLOW_HOME
104
- pytest --junit-xml=/tmp/tests/dl+s3.xml --cov templateflow --cov-report xml:/tmp/cov_api_dl_s3.xml \
105
- --doctest-modules /tmp/src/templateflow/templateflow/api.py
157
+ python -m pytest \
158
+ --junit-xml=~/tests/dl+s3.xml --cov templateflow --cov-report xml:~/coverage/cov_api_dl_s3.xml \
159
+ --doctest-modules templateflow/api.py
106
160
 
107
- - run:
108
- name: Submit api test coverage
109
- command: |
110
- source /tmp/venv/bin/activate
111
- codecov --file /tmp/cov_api_dl_s3.xml --root /tmp/src/templateflow \
112
- --flags api,dls3 -e CIRCLE_JOB
113
-
114
- - run:
115
- name: Run tests (config, parameterized TEMPLATEFLOW_USE_DATALAD)
116
- command: |
117
- source /tmp/venv/bin/activate
118
- pytest --junit-xml=/tmp/tests/conftests.xml --cov templateflow --cov-report xml:/tmp/cov_config.xml \
119
- /tmp/src/templateflow/templateflow/conf/tests/test_conf.py
120
-
121
- - run:
122
- name: Submit config test coverage
123
- command: |
124
- source /tmp/venv/bin/activate
125
- codecov --file /tmp/cov_config.xml --root /tmp/src/templateflow \
126
- --flags config -e CIRCLE_JOB
161
+ - codecov/upload:
162
+ file: ~/coverage/cov_api_dl_s3.xml
163
+ flags: api,dls3
164
+ upload_name: Datalad-S3-bypass
127
165
 
128
166
  - store_test_results:
129
- path: /tmp/tests
167
+ path: ~/tests
130
168
 
131
169
  build_docs:
132
170
  machine:
@@ -179,54 +217,38 @@ jobs:
179
217
  - store_artifacts:
180
218
  path: ~/html
181
219
 
182
- deploy_pypi:
183
- docker:
184
- - image: cimg/python:3.9
185
- working_directory: /tmp/src/templateflow
186
- steps:
187
- - attach_workspace:
188
- at: /tmp
189
-
190
- - checkout:
191
- path: /tmp/src/templateflow
192
-
193
- - run:
194
- name: Generate requirements.txt
195
- command: |
196
- python /tmp/src/templateflow/.maint/update_requirements.py
197
-
198
- - restore_cache:
199
- keys:
200
- - deps-v11-{{ checksum "/tmp/src/templateflow/dev-requirements.txt"}}-{{ epoch }}
201
- - deps-v11-{{ checksum "/tmp/src/templateflow/dev-requirements.txt"}}-
202
- - deps-v11-
203
-
204
- - run:
205
- name: Deploy to PyPi
206
- command: |
207
- source /tmp/venv/bin/activate
208
- python -m pip install build -U twine pkginfo
209
- python -m build
210
- python -m twine check dist/*
211
- python -m twine upload dist/*
212
-
213
220
  workflows:
214
221
  version: 2
215
222
  build_test_deploy:
216
223
  jobs:
224
+ - build:
225
+ context:
226
+ - nipreps-common
227
+ filters:
228
+ branches:
229
+ ignore:
230
+ - /docs?\/.*/
231
+ tags:
232
+ only: /.*/
233
+
217
234
  - tests:
218
235
  context:
219
236
  - nipreps-common
237
+ requires:
238
+ - build
220
239
  filters:
221
240
  branches:
222
241
  ignore:
223
242
  - /docs?\/.*/
224
243
  tags:
225
244
  only: /.*/
245
+
226
246
  - deploy_pypi:
227
247
  context:
228
248
  - nipreps-common
229
249
  requires:
250
+ - build
251
+ - tests
230
252
  - build_docs
231
253
  filters:
232
254
  branches:
@@ -16,13 +16,13 @@ min_reqs = repo_root / 'min-requirements.txt'
16
16
  reqs_dev = repo_root / 'dev-requirements.txt'
17
17
 
18
18
  requirements = [
19
- Requirement(req)
20
- for req in loads(pyproject.read_text())['project']['dependencies']
19
+ Requirement(req) for req in loads(pyproject.read_text())['project']['dependencies']
21
20
  ]
22
21
 
23
22
  requirements_dev = [
24
23
  Requirement(req)
25
- for req in loads(pyproject.read_text())['project']['optional-dependencies']['test']
24
+ for group in ('test', 'datalad')
25
+ for req in loads(pyproject.read_text())['project']['optional-dependencies'][group]
26
26
  ]
27
27
 
28
28
  script_name = Path(__file__).relative_to(repo_root)
@@ -1,8 +1,13 @@
1
- 24.2.1 (September 13, 2024)
1
+ 24.2.2 (September 14, 2024)
2
2
  ===========================
3
3
  Patch release containing one bugfix and updating the default skeleton.
4
4
 
5
5
  * FIX: Avoid directory clobber during zip extraction (#131)
6
+ * MAINT: Overdue updates and revision of CircleCI (#136)
7
+
8
+ 24.2.1 (September 13, 2024; RECALLED)
9
+ =====================================
10
+ Release recalled because it was uploaded in a stale status of the client.
6
11
 
7
12
  24.2.0 (March 18, 2024)
8
13
  =======================
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: templateflow
3
- Version: 24.2.1
3
+ Version: 24.2.2
4
4
  Summary: TemplateFlow Python Client - TemplateFlow is the Zone of neuroimaging templates.
5
5
  Project-URL: Archive, https://github.com/templateflow/templateflow
6
6
  Project-URL: Bug Tracker, https://github.com/templateflow/python-client/issues
@@ -225,22 +225,24 @@ Requires-Dist: pybids>=0.15.2
225
225
  Requires-Dist: requests
226
226
  Requires-Dist: tqdm
227
227
  Provides-Extra: all
228
- Requires-Dist: coverage; extra == 'all'
229
- Requires-Dist: datalad~=0.19.0; extra == 'all'
228
+ Requires-Dist: coverage~=5.0.0; extra == 'all'
229
+ Requires-Dist: datalad~=1.0.0; extra == 'all'
230
230
  Requires-Dist: nbsphinx; extra == 'all'
231
231
  Requires-Dist: packaging; extra == 'all'
232
232
  Requires-Dist: pydot>=1.2.3; extra == 'all'
233
233
  Requires-Dist: pydotplus; extra == 'all'
234
234
  Requires-Dist: pytest; extra == 'all'
235
- Requires-Dist: pytest-cov==2.5.1; extra == 'all'
235
+ Requires-Dist: pytest-cov; extra == 'all'
236
+ Requires-Dist: pytest-env; extra == 'all'
236
237
  Requires-Dist: pytest-xdist; extra == 'all'
237
238
  Requires-Dist: sphinx-click; extra == 'all'
238
239
  Requires-Dist: sphinx-multiversion; extra == 'all'
239
240
  Requires-Dist: sphinx-rtd-theme>=0.4.3; extra == 'all'
240
241
  Requires-Dist: sphinxcontrib-apidoc; extra == 'all'
241
242
  Requires-Dist: sphinx~=4.0; extra == 'all'
243
+ Requires-Dist: toml; extra == 'all'
242
244
  Provides-Extra: datalad
243
- Requires-Dist: datalad~=0.19.0; extra == 'datalad'
245
+ Requires-Dist: datalad~=1.0.0; extra == 'datalad'
244
246
  Provides-Extra: doc
245
247
  Requires-Dist: nbsphinx; extra == 'doc'
246
248
  Requires-Dist: packaging; extra == 'doc'
@@ -262,15 +264,19 @@ Requires-Dist: sphinx-rtd-theme>=0.4.3; extra == 'docs'
262
264
  Requires-Dist: sphinxcontrib-apidoc; extra == 'docs'
263
265
  Requires-Dist: sphinx~=4.0; extra == 'docs'
264
266
  Provides-Extra: test
265
- Requires-Dist: coverage; extra == 'test'
267
+ Requires-Dist: coverage~=5.0.0; extra == 'test'
266
268
  Requires-Dist: pytest; extra == 'test'
267
- Requires-Dist: pytest-cov==2.5.1; extra == 'test'
269
+ Requires-Dist: pytest-cov; extra == 'test'
270
+ Requires-Dist: pytest-env; extra == 'test'
268
271
  Requires-Dist: pytest-xdist; extra == 'test'
272
+ Requires-Dist: toml; extra == 'test'
269
273
  Provides-Extra: tests
270
- Requires-Dist: coverage; extra == 'tests'
274
+ Requires-Dist: coverage~=5.0.0; extra == 'tests'
271
275
  Requires-Dist: pytest; extra == 'tests'
272
- Requires-Dist: pytest-cov==2.5.1; extra == 'tests'
276
+ Requires-Dist: pytest-cov; extra == 'tests'
277
+ Requires-Dist: pytest-env; extra == 'tests'
273
278
  Requires-Dist: pytest-xdist; extra == 'tests'
279
+ Requires-Dist: toml; extra == 'tests'
274
280
  Description-Content-Type: text/x-rst
275
281
 
276
282
  A Python client to query TemplateFlow
@@ -37,13 +37,15 @@ Documentation = "https://www.templateflow.org/python-client/"
37
37
 
38
38
  [project.optional-dependencies]
39
39
  test = [
40
+ "coverage ~= 5.0.0",
40
41
  "pytest",
42
+ "pytest-cov",
43
+ "pytest-env",
41
44
  "pytest-xdist",
42
- "pytest-cov == 2.5.1",
43
- "coverage",
45
+ "toml",
44
46
  ]
45
47
  datalad = [
46
- "datalad ~= 0.19.0"
48
+ "datalad ~= 1.0.0"
47
49
  ]
48
50
  doc = [
49
51
  "nbsphinx",
@@ -113,7 +115,7 @@ per-file-ignores = [
113
115
 
114
116
  [tool.pytest.ini_options]
115
117
  norecursedirs = [".git"]
116
- addopts = "-svx --doctest-modules"
118
+ addopts = "-svx"
117
119
  doctest_optionflags = "ALLOW_UNICODE NORMALIZE_WHITESPACE ELLIPSIS"
118
120
  env = "PYTHONHASHSEED=0"
119
121
  filterwarnings = ["ignore::DeprecationWarning"]
@@ -121,7 +123,7 @@ junit_family = "xunit2"
121
123
 
122
124
  [tool.coverage.run]
123
125
  branch = true
124
- concurrency = 'multiprocessing'
126
+ concurrency = ['multiprocessing']
125
127
  omit = [
126
128
  '*/tests/*',
127
129
  '*/conftest.py',
@@ -21,6 +21,7 @@
21
21
  # https://www.nipreps.org/community/licensing/
22
22
  #
23
23
  """TemplateFlow is the Zone of Templates."""
24
+
24
25
  from datetime import datetime as _dt
25
26
  from datetime import timezone as _tz
26
27
 
@@ -30,6 +31,7 @@ try:
30
31
  from ._version import __version__
31
32
  except ModuleNotFoundError:
32
33
  from importlib.metadata import PackageNotFoundError, version
34
+
33
35
  try:
34
36
  __version__ = version(__packagename__)
35
37
  except PackageNotFoundError:
@@ -24,6 +24,7 @@
24
24
 
25
25
  .. autoclass:: Loader
26
26
  """
27
+
27
28
  from __future__ import annotations
28
29
 
29
30
  import atexit
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '24.2.1'
16
- __version_tuple__ = version_tuple = (24, 2, 1)
15
+ __version__ = version = '24.2.2'
16
+ __version_tuple__ = version_tuple = (24, 2, 2)
@@ -21,6 +21,7 @@
21
21
  # https://www.nipreps.org/community/licensing/
22
22
  #
23
23
  """TemplateFlow's Python Client."""
24
+
24
25
  import sys
25
26
  from json import loads
26
27
  from pathlib import Path
@@ -35,9 +36,7 @@ from templateflow.conf import (
35
36
  requires_layout,
36
37
  )
37
38
 
38
- _layout_dir = tuple(
39
- item for item in dir(TF_LAYOUT) if item.startswith('get_')
40
- )
39
+ _layout_dir = tuple(item for item in dir(TF_LAYOUT) if item.startswith('get_'))
41
40
 
42
41
 
43
42
  @requires_layout
@@ -92,10 +91,9 @@ def ls(template, **kwargs):
92
91
  kwargs['extension'] = _normalize_ext(kwargs['extension'])
93
92
 
94
93
  return [
95
- Path(p) for p in TF_LAYOUT.get(
96
- template=Query.ANY if template is None else template,
97
- return_type='file',
98
- **kwargs
94
+ Path(p)
95
+ for p in TF_LAYOUT.get(
96
+ template=Query.ANY if template is None else template, return_type='file', **kwargs
99
97
  )
100
98
  ]
101
99
 
@@ -176,25 +174,23 @@ def get(template, raise_empty=False, **kwargs):
176
174
  not_fetched = [str(p) for p in out_file if not p.is_file() or p.stat().st_size == 0]
177
175
 
178
176
  if not_fetched:
179
- msg = 'Could not fetch template files: %s.' % ', '.join(not_fetched)
177
+ msg = 'Could not fetch template files: {}.'.format(', '.join(not_fetched))
180
178
  if dl_missing and not TF_USE_DATALAD:
181
179
  msg += (
182
- """\
183
- The $TEMPLATEFLOW_HOME folder %s seems to contain an initiated DataLad \
180
+ f"""\
181
+ The $TEMPLATEFLOW_HOME folder {TF_LAYOUT.root} seems to contain an initiated DataLad \
184
182
  dataset, but the environment variable $TEMPLATEFLOW_USE_DATALAD is not \
185
183
  set or set to one of (false, off, 0). Please set $TEMPLATEFLOW_USE_DATALAD \
186
184
  on (possible values: true, on, 1)."""
187
- % TF_LAYOUT.root
188
185
  )
189
186
 
190
187
  if s3_missing and TF_USE_DATALAD:
191
188
  msg += (
192
- """\
193
- The $TEMPLATEFLOW_HOME folder %s seems to contain an plain \
189
+ f"""\
190
+ The $TEMPLATEFLOW_HOME folder {TF_LAYOUT.root} seems to contain an plain \
194
191
  dataset, but the environment variable $TEMPLATEFLOW_USE_DATALAD is \
195
192
  set to one of (true, on, 1). Please set $TEMPLATEFLOW_USE_DATALAD \
196
193
  off (possible values: false, off, 0)."""
197
- % TF_LAYOUT.root
198
194
  )
199
195
 
200
196
  raise RuntimeError(msg)
@@ -251,7 +247,7 @@ def get_metadata(template):
251
247
 
252
248
  """
253
249
  tf_home = Path(TF_LAYOUT.root)
254
- filepath = tf_home / ('tpl-%s' % template) / 'template_description.json'
250
+ filepath = tf_home / (f'tpl-{template}') / 'template_description.json'
255
251
 
256
252
  # Ensure that template is installed and file is available
257
253
  if not filepath.is_file():
@@ -324,7 +320,7 @@ def _s3_get(filepath):
324
320
  path = filepath.relative_to(TF_LAYOUT.root).as_posix()
325
321
  url = f'{TF_S3_ROOT}/{path}'
326
322
 
327
- print('Downloading %s' % url, file=stderr)
323
+ print(f'Downloading {url}', file=stderr)
328
324
  # Streaming, so we can iterate over the response.
329
325
  r = requests.get(url, stream=True, timeout=TF_GET_TIMEOUT)
330
326
 
@@ -21,6 +21,7 @@
21
21
  # https://www.nipreps.org/community/licensing/
22
22
  #
23
23
  """The TemplateFlow Python Client command-line interface (CLI)."""
24
+
24
25
  from __future__ import annotations
25
26
 
26
27
  import json
@@ -31,20 +32,20 @@ from click.decorators import FC, Option, _param_memo
31
32
 
32
33
  from templateflow import __package__, api
33
34
  from templateflow._loader import Loader as _Loader
34
- from templateflow.conf import TF_HOME, TF_USE_DATALAD, TF_AUTOUPDATE
35
+ from templateflow.conf import TF_AUTOUPDATE, TF_HOME, TF_USE_DATALAD
35
36
 
36
37
  load_data = _Loader(__package__)
37
38
 
38
39
  ENTITY_SHORTHANDS = {
39
40
  # 'template': ('--tpl', '-t'),
40
- 'resolution': ('--res', ),
41
- 'density': ('--den', ),
42
- 'atlas': ('-a', ),
43
- 'suffix': ('-s', ),
41
+ 'resolution': ('--res',),
42
+ 'density': ('--den',),
43
+ 'atlas': ('-a',),
44
+ 'suffix': ('-s',),
44
45
  'desc': ('-d', '--description'),
45
46
  'extension': ('--ext', '-x'),
46
- 'label': ('-l', ),
47
- 'segmentation': ('--seg', ),
47
+ 'label': ('-l',),
48
+ 'segmentation': ('--seg',),
48
49
  }
49
50
  ENTITY_EXCLUDE = {'template', 'description'}
50
51
  TEMPLATE_LIST = api.get_templates()
@@ -57,16 +58,12 @@ def _nulls(s):
57
58
  def entity_opts():
58
59
  """Attaches all entities as options to the command."""
59
60
 
60
- entities = json.loads(
61
- Path(load_data('conf/config.json')).read_text()
62
- )['entities']
61
+ entities = json.loads(Path(load_data('conf/config.json')).read_text())['entities']
63
62
 
64
63
  args = [
65
- (
66
- f"--{e['name']}",
67
- *ENTITY_SHORTHANDS.get(e['name'], ())
68
- )
69
- for e in entities if e['name'] not in ENTITY_EXCLUDE
64
+ (f"--{e['name']}", *ENTITY_SHORTHANDS.get(e['name'], ()))
65
+ for e in entities
66
+ if e['name'] not in ENTITY_EXCLUDE
70
67
  ]
71
68
 
72
69
  def decorator(f: FC) -> FC:
@@ -135,9 +132,7 @@ def update(local, overwrite):
135
132
  def ls(template, **kwargs):
136
133
  """List the assets corresponding to template and optional filters."""
137
134
  entities = {k: _nulls(v) for k, v in kwargs.items() if v != ''}
138
- click.echo(
139
- '\n'.join(f'{match}' for match in api.ls(template, **entities))
140
- )
135
+ click.echo('\n'.join(f'{match}' for match in api.ls(template, **entities)))
141
136
 
142
137
 
143
138
  @main.command()
@@ -146,9 +141,7 @@ def ls(template, **kwargs):
146
141
  def get(template, **kwargs):
147
142
  """Fetch the assets corresponding to template and optional filters."""
148
143
  entities = {k: _nulls(v) for k, v in kwargs.items() if v != ''}
149
- click.echo(
150
- '\n'.join(f'{match}' for match in api.get(template, **entities))
151
- )
144
+ click.echo('\n'.join(f'{match}' for match in api.get(template, **entities)))
152
145
 
153
146
 
154
147
  if __name__ == '__main__':
@@ -1,4 +1,5 @@
1
1
  """Configuration and settings."""
2
+
2
3
  import re
3
4
  from contextlib import suppress
4
5
  from functools import wraps
@@ -35,7 +36,7 @@ def _env_to_bool(envvar: str, default: bool) -> bool:
35
36
 
36
37
 
37
38
  TF_DEFAULT_HOME = Path.home() / '.cache' / 'templateflow'
38
- TF_HOME = Path(getenv('TEMPLATEFLOW_HOME', str(TF_DEFAULT_HOME)))
39
+ TF_HOME = Path(getenv('TEMPLATEFLOW_HOME', str(TF_DEFAULT_HOME))).absolute()
39
40
  TF_GITHUB_SOURCE = 'https://github.com/templateflow/templateflow.git'
40
41
  TF_S3_ROOT = 'https://templateflow.s3.amazonaws.com'
41
42
  TF_USE_DATALAD = _env_to_bool('TEMPLATEFLOW_USE_DATALAD', False)
@@ -43,9 +44,19 @@ TF_AUTOUPDATE = _env_to_bool('TEMPLATEFLOW_AUTOUPDATE', True)
43
44
  TF_CACHED = True
44
45
  TF_GET_TIMEOUT = 10
45
46
 
47
+ if TF_USE_DATALAD:
48
+ try:
49
+ from datalad.api import install
50
+ except ImportError:
51
+ warn('DataLad is not installed ➔ disabled.', stacklevel=2)
52
+ TF_USE_DATALAD = False
53
+
54
+ if not TF_USE_DATALAD:
55
+ from templateflow.conf._s3 import update as _update_s3
56
+
46
57
 
47
58
  def _init_cache():
48
- global TF_HOME, TF_CACHED, TF_USE_DATALAD
59
+ global TF_CACHED
49
60
 
50
61
  if not TF_HOME.exists() or not list(TF_HOME.iterdir()):
51
62
  TF_CACHED = False
@@ -58,17 +69,9 @@ please set the TEMPLATEFLOW_HOME environment variable.""",
58
69
  stacklevel=2,
59
70
  )
60
71
  if TF_USE_DATALAD:
61
- try:
62
- from datalad.api import install
63
- except ImportError:
64
- TF_USE_DATALAD = False
65
- else:
66
- TF_HOME.parent.mkdir(exist_ok=True, parents=True)
67
- install(path=str(TF_HOME), source=TF_GITHUB_SOURCE, recursive=True)
68
-
69
- if not TF_USE_DATALAD:
70
- from ._s3 import update as _update_s3
71
-
72
+ TF_HOME.parent.mkdir(exist_ok=True, parents=True)
73
+ install(path=str(TF_HOME), source=TF_GITHUB_SOURCE, recursive=True)
74
+ else:
72
75
  _update_s3(TF_HOME, local=True, overwrite=TF_AUTOUPDATE, silent=True)
73
76
 
74
77
 
@@ -85,9 +88,7 @@ def requires_layout(func):
85
88
  if TF_LAYOUT is None:
86
89
  from bids import __version__
87
90
 
88
- raise RuntimeError(
89
- f'A layout with PyBIDS <{__version__}> could not be initiated'
90
- )
91
+ raise RuntimeError(f'A layout with PyBIDS <{__version__}> could not be initiated')
91
92
  return func(*args, **kwargs)
92
93
 
93
94
  return wrapper
@@ -95,8 +96,8 @@ def requires_layout(func):
95
96
 
96
97
  def update(local=False, overwrite=True, silent=False):
97
98
  """Update an existing DataLad or S3 home."""
98
- if TF_USE_DATALAD and _update_datalad():
99
- success = True
99
+ if TF_USE_DATALAD:
100
+ success = _update_datalad()
100
101
  else:
101
102
  from ._s3 import update as _update_s3
102
103
 
@@ -116,7 +117,6 @@ def update(local=False, overwrite=True, silent=False):
116
117
 
117
118
  def wipe():
118
119
  """Clear the cache if functioning in S3 mode."""
119
- global TF_USE_DATALAD, TF_HOME
120
120
 
121
121
  if TF_USE_DATALAD:
122
122
  print('TemplateFlow is configured in DataLad mode, wipe() has no effect')
@@ -131,9 +131,7 @@ def wipe():
131
131
  from pathlib import Path
132
132
 
133
133
  if Path(path).exists():
134
- print(
135
- f'Warning: could not delete <{path}>, please clear the cache manually.'
136
- )
134
+ print(f'Warning: could not delete <{path}>, please clear the cache manually.')
137
135
 
138
136
  rmtree(TF_HOME, onerror=_onerror)
139
137
  _init_cache()
@@ -21,6 +21,7 @@
21
21
  # https://www.nipreps.org/community/licensing/
22
22
  #
23
23
  """Tooling to handle S3 downloads."""
24
+
24
25
  from pathlib import Path
25
26
  from tempfile import mkstemp
26
27
 
@@ -86,18 +87,18 @@ def _update_skeleton(skel_file, dest, overwrite=True, silent=False):
86
87
  newfiles = allfiles
87
88
  else:
88
89
  current_files = [s.relative_to(dest) for s in dest.glob('**/*')]
89
- existing = sorted({'%s/' % s.parent for s in current_files}) + [
90
+ existing = sorted({f'{s.parent}/' for s in current_files}) + [
90
91
  str(s) for s in current_files
91
92
  ]
92
93
  newfiles = sorted(set(allfiles) - set(existing))
93
94
 
94
95
  if newfiles:
95
96
  if not silent:
96
- print(
97
- 'Updating TEMPLATEFLOW_HOME using S3. Adding:\n%s'
98
- % '\n'.join(newfiles)
99
- )
97
+ print('Updating TEMPLATEFLOW_HOME using S3. Adding:')
98
+
100
99
  for fl in newfiles:
100
+ if not silent:
101
+ print(fl)
101
102
  localpath = dest / fl
102
103
  if localpath.exists():
103
104
  continue
@@ -21,6 +21,7 @@
21
21
  # https://www.nipreps.org/community/licensing/
22
22
  #
23
23
  """Extending pyBIDS for querying TemplateFlow."""
24
+
24
25
  from bids.layout import BIDSLayout, add_config_paths
25
26
 
26
27
  from templateflow.conf import load_data
@@ -34,7 +35,5 @@ class Layout(BIDSLayout):
34
35
  s = """\
35
36
  TemplateFlow Layout
36
37
  - Home: {}
37
- - Templates: {}.""".format(
38
- self.root, ', '.join(sorted(self.get_templates()))
39
- )
38
+ - Templates: {}.""".format(self.root, ', '.join(sorted(self.get_templates())))
40
39
  return s
@@ -24,7 +24,7 @@
24
24
 
25
25
  import pytest
26
26
 
27
- from .. import api
27
+ from templateflow import api
28
28
 
29
29
 
30
30
  class Bibtex:
@@ -154,9 +154,7 @@ Surface-Based Atlases},
154
154
  journal={Cerebral Cortex}
155
155
  }"""
156
156
 
157
- fslr_lbib = (
158
- 'https://github.com/Washington-University/HCPpipelines/tree/master/global/templates'
159
- )
157
+ fslr_lbib = 'https://github.com/Washington-University/HCPpipelines/tree/master/global/templates'
160
158
 
161
159
  fsaverage_fbib = """\
162
160
  @article{Fischl_1999,
@@ -181,9 +179,7 @@ journal={Human Brain Mapping}
181
179
  ('fsLR', fslr_urls, fslr_fbib, fslr_lbib),
182
180
  (
183
181
  'fsaverage',
184
- [
185
- 'https://doi.org/10.1002/(sici)1097-0193(1999)8:4%3C272::aid-hbm10%3E3.0.co;2-4'
186
- ],
182
+ ['https://doi.org/10.1002/(sici)1097-0193(1999)8:4%3C272::aid-hbm10%3E3.0.co;2-4'],
187
183
  fsaverage_fbib,
188
184
  None,
189
185
  ),
@@ -20,6 +20,8 @@
20
20
  #
21
21
  # https://www.nipreps.org/community/licensing/
22
22
  #
23
+ """Tests the config module."""
24
+
23
25
  from importlib import reload
24
26
  from shutil import rmtree
25
27
 
@@ -39,9 +41,9 @@ def _find_message(lines, msg, reverse=True):
39
41
 
40
42
 
41
43
  @pytest.mark.parametrize('use_datalad', ['off', 'on'])
42
- def test_conf_init(monkeypatch, tmp_path, capsys, use_datalad):
44
+ def test_conf_init(monkeypatch, tmp_path, use_datalad):
43
45
  """Check the correct functioning of config set-up."""
44
- home = (tmp_path / '-'.join(('tf', 'dl', use_datalad))).resolve()
46
+ home = (tmp_path / f'conf-init-{use_datalad}').resolve()
45
47
  monkeypatch.setenv('TEMPLATEFLOW_USE_DATALAD', use_datalad)
46
48
  monkeypatch.setenv('TEMPLATEFLOW_HOME', str(home))
47
49
 
@@ -55,21 +57,34 @@ def test_conf_init(monkeypatch, tmp_path, capsys, use_datalad):
55
57
  assert str(tfc.TF_HOME) == str(home)
56
58
 
57
59
 
58
- @pytest.mark.parametrize('use_datalad', ['off', 'on'])
60
+ @pytest.mark.parametrize('use_datalad', ['on', 'off'])
59
61
  def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad):
60
62
  """Check the correct functioning of the installation hook."""
61
- home = (tmp_path / '-'.join(('tf', 'dl', use_datalad))).resolve()
63
+
64
+ if use_datalad == 'on':
65
+ # ImportError if not installed
66
+ pass
67
+
68
+ home = (tmp_path / f'setup-home-{use_datalad}').absolute()
62
69
  monkeypatch.setenv('TEMPLATEFLOW_USE_DATALAD', use_datalad)
63
70
  monkeypatch.setenv('TEMPLATEFLOW_HOME', str(home))
64
71
 
65
- reload(tfc)
72
+ use_post = tfc._env_to_bool('TEMPLATEFLOW_USE_DATALAD', False)
73
+ assert use_post is (use_datalad == 'on')
74
+
75
+ with capsys.disabled():
76
+ reload(tfc)
77
+
78
+ # Ensure mocks are up-to-date
79
+ assert tfc.TF_USE_DATALAD is (use_datalad == 'on')
80
+ assert str(tfc.TF_HOME) == str(home)
66
81
  # First execution, the S3 stub is created (or datalad install)
67
82
  assert tfc.TF_CACHED is False
68
83
  assert tfc.setup_home() is False
69
84
 
70
85
  out = capsys.readouterr().out
71
86
  assert _find_message(out, 'TemplateFlow was not cached')
72
- assert ('TEMPLATEFLOW_HOME=%s' % home) in out
87
+ assert (f'TEMPLATEFLOW_HOME={home}') in out
73
88
  assert home.exists()
74
89
  assert len(list(home.iterdir())) > 0
75
90
 
@@ -119,9 +134,9 @@ def test_setup_home(monkeypatch, tmp_path, capsys, use_datalad):
119
134
  def test_layout(monkeypatch, tmp_path):
120
135
  monkeypatch.setenv('TEMPLATEFLOW_USE_DATALAD', 'off')
121
136
 
122
- lines = ('%s' % tfc.TF_LAYOUT).splitlines()
137
+ lines = (f'{tfc.TF_LAYOUT}').splitlines()
123
138
  assert lines[0] == 'TemplateFlow Layout'
124
- assert lines[1] == ' - Home: %s' % tfc.TF_HOME
139
+ assert lines[1] == f' - Home: {tfc.TF_HOME}'
125
140
  assert lines[2].startswith(' - Templates:')
126
141
 
127
142
 
@@ -0,0 +1,89 @@
1
+ # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2
+ # vi: set ft=python sts=4 ts=4 sw=4 et:
3
+ #
4
+ # Copyright 2024 The NiPreps Developers <nipreps@gmail.com>
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ # We support and encourage derived works from this project, please read
19
+ # about our expectations at
20
+ #
21
+ # https://www.nipreps.org/community/licensing/
22
+ #
23
+ """Check S3-type repo tooling."""
24
+
25
+ from importlib import reload
26
+ from pathlib import Path
27
+
28
+ import requests
29
+
30
+ from templateflow import conf as tfc
31
+
32
+
33
+ def test_get_skel_file(tmp_path, monkeypatch):
34
+ """Exercise the skeleton file generation."""
35
+
36
+ home = (tmp_path / 's3-skel-file').resolve()
37
+ monkeypatch.setenv('TEMPLATEFLOW_USE_DATALAD', 'off')
38
+ monkeypatch.setenv('TEMPLATEFLOW_HOME', str(home))
39
+
40
+ # First execution, the S3 stub is created (or datalad install)
41
+ reload(tfc)
42
+
43
+ local_md5 = tfc._s3.TF_SKEL_MD5
44
+ monkeypatch.setattr(tfc._s3, 'TF_SKEL_MD5', 'invent')
45
+ new_skel = tfc._s3._get_skeleton_file()
46
+ assert new_skel is not None
47
+ assert Path(new_skel).exists()
48
+ assert Path(new_skel).stat().st_size > 0
49
+
50
+ latest_md5 = (
51
+ requests.get(
52
+ tfc._s3.TF_SKEL_URL(release='master', ext='md5', allow_redirects=True), timeout=10
53
+ )
54
+ .content.decode()
55
+ .split()[0]
56
+ )
57
+ monkeypatch.setattr(tfc._s3, 'TF_SKEL_MD5', latest_md5)
58
+ assert tfc._s3._get_skeleton_file() is None
59
+
60
+ monkeypatch.setattr(tfc._s3, 'TF_SKEL_MD5', local_md5)
61
+ monkeypatch.setattr(tfc._s3, 'TF_SKEL_URL', 'http://weird/{release}/{ext}'.format)
62
+ assert tfc._s3._get_skeleton_file() is None
63
+
64
+ monkeypatch.setattr(
65
+ tfc._s3, 'TF_SKEL_URL', tfc._s3.TF_SKEL_URL(release='{release}', ext='{ext}z').format
66
+ )
67
+ assert tfc._s3._get_skeleton_file() is None
68
+
69
+
70
+ def test_update_s3(tmp_path, monkeypatch):
71
+ """Exercise updating the S3 skeleton."""
72
+
73
+ newhome = (tmp_path / 's3-update').resolve()
74
+ monkeypatch.setenv('TEMPLATEFLOW_USE_DATALAD', 'off')
75
+ monkeypatch.setenv('TEMPLATEFLOW_HOME', str(newhome))
76
+
77
+ assert tfc._s3.update(newhome)
78
+ assert not tfc._s3.update(newhome, overwrite=False)
79
+ for p in (newhome / 'tpl-MNI152NLin6Sym').glob('*.nii.gz'):
80
+ p.unlink()
81
+ assert tfc._s3.update(newhome, overwrite=False)
82
+
83
+ # This should cover the remote zip file fetching
84
+ monkeypatch.setattr(tfc._s3, 'TF_SKEL_MD5', 'invent')
85
+ assert tfc._s3.update(newhome, local=False)
86
+ assert not tfc._s3.update(newhome, local=False, overwrite=False)
87
+ for p in (newhome / 'tpl-MNI152NLin6Sym').glob('*.nii.gz'):
88
+ p.unlink()
89
+ assert tfc._s3.update(newhome, local=False, overwrite=False)
@@ -21,6 +21,7 @@
21
21
  # https://www.nipreps.org/community/licensing/
22
22
  #
23
23
  """Test version retrieval."""
24
+
24
25
  import sys
25
26
  from importlib import reload
26
27
  from importlib.metadata import PackageNotFoundError
@@ -1,74 +0,0 @@
1
- # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2
- # vi: set ft=python sts=4 ts=4 sw=4 et:
3
- #
4
- # Copyright 2024 The NiPreps Developers <nipreps@gmail.com>
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
- # We support and encourage derived works from this project, please read
19
- # about our expectations at
20
- #
21
- # https://www.nipreps.org/community/licensing/
22
- #
23
- """Check S3-type repo tooling."""
24
- # import pytest
25
- from pathlib import Path
26
-
27
- import requests
28
-
29
- from .. import _s3 as s3
30
-
31
-
32
- def test_get_skel_file(monkeypatch):
33
- """Exercise the skeleton file generation."""
34
- local_md5 = s3.TF_SKEL_MD5
35
- monkeypatch.setattr(s3, 'TF_SKEL_MD5', 'invent')
36
- new_skel = s3._get_skeleton_file()
37
- assert new_skel is not None
38
- assert Path(new_skel).exists()
39
- assert Path(new_skel).stat().st_size > 0
40
-
41
- latest_md5 = (
42
- requests.get(s3.TF_SKEL_URL(release='master', ext='md5', allow_redirects=True), timeout=10)
43
- .content.decode()
44
- .split()[0]
45
- )
46
- monkeypatch.setattr(s3, 'TF_SKEL_MD5', latest_md5)
47
- assert s3._get_skeleton_file() is None
48
-
49
- monkeypatch.setattr(s3, 'TF_SKEL_MD5', local_md5)
50
- monkeypatch.setattr(s3, 'TF_SKEL_URL', 'http://weird/{release}/{ext}'.format)
51
- assert s3._get_skeleton_file() is None
52
-
53
- monkeypatch.setattr(
54
- s3, 'TF_SKEL_URL', s3.TF_SKEL_URL(release='{release}', ext='{ext}z').format
55
- )
56
- assert s3._get_skeleton_file() is None
57
-
58
-
59
- def test_update_s3(tmp_path, monkeypatch):
60
- """Exercise updating the S3 skeleton."""
61
- newhome = tmp_path / 'templateflow'
62
- assert s3.update(newhome)
63
- assert not s3.update(newhome, overwrite=False)
64
- for p in (newhome / 'tpl-MNI152NLin6Sym').glob('*.nii.gz'):
65
- p.unlink()
66
- assert s3.update(newhome, overwrite=False)
67
-
68
- # This should cover the remote zip file fetching
69
- monkeypatch.setattr(s3, 'TF_SKEL_MD5', 'invent')
70
- assert s3.update(newhome, local=False)
71
- assert not s3.update(newhome, local=False, overwrite=False)
72
- for p in (newhome / 'tpl-MNI152NLin6Sym').glob('*.nii.gz'):
73
- p.unlink()
74
- assert s3.update(newhome, local=False, overwrite=False)
File without changes
@@ -1,52 +0,0 @@
1
- # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
2
- # vi: set ft=python sts=4 ts=4 sw=4 et:
3
- #
4
- # Copyright 2024 The NiPreps Developers <nipreps@gmail.com>
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
- # We support and encourage derived works from this project, please read
19
- # about our expectations at
20
- #
21
- # https://www.nipreps.org/community/licensing/
22
- #
23
- """Tests the config module."""
24
- from pathlib import Path
25
-
26
- import pytest
27
-
28
- from .. import api, conf
29
-
30
-
31
- @pytest.mark.skipif(conf.TF_USE_DATALAD, reason='S3 only')
32
- def test_update_s3(tmp_path):
33
- conf.TF_HOME = tmp_path / 'templateflow'
34
- conf.TF_HOME.mkdir(exist_ok=True)
35
-
36
- # replace TF_SKEL_URL with the path of a legacy skeleton
37
- _skel_url = conf._s3.TF_SKEL_URL
38
- conf._s3.TF_SKEL_URL = (
39
- 'https://github.com/templateflow/python-client/raw/0.5.0/'
40
- 'templateflow/conf/templateflow-skel.{ext}'.format
41
- )
42
- # initialize templateflow home, making sure to pull the legacy skeleton
43
- conf.update(local=False)
44
- # ensure we can grab a file
45
- assert Path(api.get('MNI152NLin2009cAsym', resolution=2, desc='brain', suffix='mask')).exists()
46
- # and ensure we can't fetch one that doesn't yet exist
47
- assert not api.get('Fischer344', hemi='L', desc='brain', suffix='mask')
48
-
49
- # refresh the skeleton using the most recent skeleton
50
- conf._s3.TF_SKEL_URL = _skel_url
51
- conf.update(local=True, overwrite=True)
52
- assert Path(api.get('Fischer344', hemi='L', desc='brain', suffix='mask')).exists()
File without changes
File without changes
File without changes
File without changes
File without changes