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 280280
281281import pathlib
282282from collections import Counter
283+ import importlib .util
283284
284- # try to import the neuroshare library.
285+ # check if neuroshare library exists
285286# if it is present, use the neuroshareapiio to load neuroshare files
286287# 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/")
295288
296- else :
289+ neuroshare_spec = importlib .util .find_spec ("neuroshare" )
290+ if neuroshare_spec is not None :
297291 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
301294
302295from neo .io .alphaomegaio import AlphaOmegaIO
303296from neo .io .asciiimageio import AsciiImageIO
Original file line number Diff line number Diff line change 1313
1414from __future__ import annotations
1515from 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
2117import logging
2218
2319from neo import logging_handler
Original file line number Diff line number Diff line change 2727from uuid import uuid4
2828import warnings
2929from packaging .version import Version
30+ import importlib .util
31+ import importlib .metadata
3032
3133import quantities as pq
3234import numpy as np
@@ -122,17 +124,15 @@ def dt_from_nix(nixdt, annotype):
122124
123125
124126def 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 (
129130 "Failed to import NIX. "
130131 "The NixIO requires the Python package for NIX "
131132 "(nixio on PyPi). Try `pip install nixio`."
132133 )
133134
134- # nixio version numbers have a 'v' prefix which breaks the comparison
135- nixverstr = nixio .__version__ .lstrip ("v" )
135+ nixverstr = importlib .metadata .version ("nixio" )
136136 try :
137137 nixver = Version (nixverstr )
138138 except ValueError :
Original file line number Diff line number Diff line change 262608 Feb 2014, C. Schmidt-Hieber, University College London
2727"""
2828
29+ import importlib .util
30+
2931import numpy as np
3032import quantities as pq
3133
@@ -92,7 +94,9 @@ def __init__(self, filename=None):
9294 """
9395 # We need this module, so try importing now so that it fails on
9496 # 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" )
96100
97101 BaseIO .__init__ (self )
98102
You can’t perform that action at this time.
0 commit comments