File tree Expand file tree Collapse file tree 4 files changed +18
-25
lines changed Expand file tree Collapse file tree 4 files changed +18
-25
lines changed Original file line number Diff line number Diff line change 280
280
281
281
import pathlib
282
282
from collections import Counter
283
+ import importlib .util
283
284
284
- # try to import the neuroshare library.
285
+ # check if neuroshare library exists
285
286
# if it is present, use the neuroshareapiio to load neuroshare files
286
287
# if it is not present, use the neurosharectypesio to load files
287
- try :
288
- import neuroshare as ns
289
- except ModuleNotFoundError as err :
290
- from neo .io .neurosharectypesio import NeurosharectypesIO as NeuroshareIO
291
-
292
- # print("\n neuroshare library not found, loading data with ctypes" )
293
- # print("\n to use the API be sure to install the library found at:")
294
- # print("\n www.http://pythonhosted.org/neuroshare/")
295
288
296
- else :
289
+ neuroshare_spec = importlib .util .find_spec ("neuroshare" )
290
+ if neuroshare_spec is not None :
297
291
from neo .io .neuroshareapiio import NeuroshareapiIO as NeuroshareIO
298
-
299
- # print("neuroshare library successfully imported")
300
- # print("\n loading with API...")
292
+ else :
293
+ from neo .io .neurosharectypesio import NeurosharectypesIO as NeuroshareIO
301
294
302
295
from neo .io .alphaomegaio import AlphaOmegaIO
303
296
from neo .io .asciiimageio import AsciiImageIO
Original file line number Diff line number Diff line change 13
13
14
14
from __future__ import annotations
15
15
from pathlib import Path
16
-
17
- try :
18
- from collections .abc import Sequence
19
- except ImportError :
20
- from collections import Sequence
16
+ from collections .abc import Sequence
21
17
import logging
22
18
23
19
from neo import logging_handler
Original file line number Diff line number Diff line change 27
27
from uuid import uuid4
28
28
import warnings
29
29
from packaging .version import Version
30
+ import importlib .util
31
+ import importlib .metadata
30
32
31
33
import quantities as pq
32
34
import numpy as np
@@ -122,17 +124,15 @@ def dt_from_nix(nixdt, annotype):
122
124
123
125
124
126
def check_nix_version ():
125
- try :
126
- import nixio
127
- except ImportError :
128
- raise Exception (
127
+ nixio_spec = importlib .util .find_spec ("nixio" )
128
+ if nixio_spec is None :
129
+ raise ImportError (
129
130
"Failed to import NIX. "
130
131
"The NixIO requires the Python package for NIX "
131
132
"(nixio on PyPi). Try `pip install nixio`."
132
133
)
133
134
134
- # nixio version numbers have a 'v' prefix which breaks the comparison
135
- nixverstr = nixio .__version__ .lstrip ("v" )
135
+ nixverstr = importlib .metadata .version ("nixio" )
136
136
try :
137
137
nixver = Version (nixverstr )
138
138
except ValueError :
Original file line number Diff line number Diff line change 26
26
08 Feb 2014, C. Schmidt-Hieber, University College London
27
27
"""
28
28
29
+ import importlib .util
30
+
29
31
import numpy as np
30
32
import quantities as pq
31
33
@@ -92,7 +94,9 @@ def __init__(self, filename=None):
92
94
"""
93
95
# We need this module, so try importing now so that it fails on
94
96
# instantiation rather than read_block
95
- import stfio # noqa
97
+ stfio_spec = importlib .util .find_spec ("stfio" )
98
+ if stfio_spec is None :
99
+ raise ImportError ("stfio must be installed to use StimfitIO" )
96
100
97
101
BaseIO .__init__ (self )
98
102
You can’t perform that action at this time.
0 commit comments