Skip to content

Commit a5def19

Browse files
authored
Make zenodo_get an optional dependency (#2146)
* Import zenodo_get only when it's used. Remove as required dependency * Update tests
1 parent 0fbefaa commit a5def19

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
- Dependencies
2828
- matplotlib-base is an optional dependency, instead of required (#2093)
2929
- `unittest-parametrize has been added as a dependency for tests (#1990)
30+
- zenodo_get is an optional dependency, instead of required (#2146)
3031

3132

3233
* 24.3.0

Wrappers/Python/cil/utilities/dataexample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from zipfile import ZipFile
2828
from scipy.io import loadmat
2929
from cil.io import NEXUSDataReader, NikonDataReader, ZEISSDataReader
30-
from zenodo_get import zenodo_get
3130

3231
class DATA(object):
3332
@classmethod
@@ -71,6 +70,7 @@ def download_data(cls, data_dir, prompt=True):
7170
print('Download cancelled')
7271
return False
7372

73+
from zenodo_get import zenodo_get
7474
zenodo_get([cls.ZENODO_RECORD, '-g', cls.ZIP_FILE, '-o', data_dir])
7575
with ZipFile(os.path.join(data_dir, cls.ZIP_FILE), 'r') as zip_ref:
7676
zip_ref.extractall(os.path.join(data_dir, cls.FOLDER))

Wrappers/Python/test/test_dataexample.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,18 @@
1717
# CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt
1818

1919
import unittest
20-
from utils import initialise_tests
20+
from utils import initialise_tests, has_zenodo_get
2121
from cil.framework import ImageGeometry, AcquisitionGeometry
2222
from cil.utilities import dataexample
2323
from cil.utilities import noise
2424
import os, sys, shutil
2525
from testclass import CCPiTestClass
2626
import platform
2727
import numpy as np
28-
from unittest.mock import patch
28+
from unittest.mock import patch
2929
from zipfile import ZipFile
3030
from io import StringIO
3131
import uuid
32-
from zenodo_get import zenodo_get
3332

3433
initialise_tests()
3534

@@ -168,7 +167,8 @@ def mock_zenodo_get(*args):
168167

169168

170169
@patch('cil.utilities.dataexample.input', return_value='y')
171-
@patch('cil.utilities.dataexample.zenodo_get', side_effect=mock_zenodo_get)
170+
@patch('zenodo_get.zenodo_get', side_effect=mock_zenodo_get)
171+
@unittest.skipUnless(has_zenodo_get, "zenodo_get not installed")
172172
def test_download_data_input_y(self, mock_zenodo_get, input):
173173
'''
174174
Test the download_data function, when the user input is 'y' to 'are you sure you want to download data'
@@ -196,7 +196,7 @@ def test_download_data_input_y(self, mock_zenodo_get, input):
196196

197197

198198
@patch('cil.utilities.dataexample.input', return_value='n')
199-
@patch('cil.utilities.dataexample.zenodo_get', side_effect=mock_zenodo_get)
199+
@patch('zenodo_get.zenodo_get', side_effect=mock_zenodo_get)
200200
def test_download_data_input_n(self, mock_zenodo_get, input):
201201
'''
202202
Test the download_data function, when the user input is 'n' to 'are you sure you want to download data'
@@ -239,7 +239,4 @@ def test_download_data_empty(self, input):
239239

240240
with self.assertRaises(ValueError):
241241
remote_data.download_data('.')
242-
243-
def test_a(self):
244-
from cil.utilities.dataexample import WALNUT
245242

Wrappers/Python/test/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ def initialise_tests():
134134
has_matplotlib = True
135135
system_state['has_matplotlib'] = has_matplotlib
136136

137+
#has_zenodo_get
138+
module_info = importlib.util.find_spec("zenodo_get")
139+
if module_info is None:
140+
has_zenodo_get = False
141+
else:
142+
has_zenodo_get = True
143+
system_state['has_zenodo_get'] = has_zenodo_get
137144

138145
# to disable prints from 3rd part libraries and tests
139146
def disable_print():

recipe/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ test:
2525
- ccpi-regulariser=24.0.1 # [not osx]
2626
- astra-toolbox=2.1=cuda* # [not osx]
2727
- matplotlib-base >=3.3.0
28+
- zenodo_get >=1.6
2829

2930
source_files:
3031
- ./Wrappers/Python/test
@@ -71,7 +72,6 @@ requirements:
7172
- {{ pin_compatible('ipp', min_pin='x.x', max_pin='x.x') }}
7273
- tqdm
7374
- numba
74-
- zenodo_get >=1.6
7575

7676
#optional packages with version dependancies
7777
run_constrained:

0 commit comments

Comments
 (0)