Skip to content

Commit 760a767

Browse files
committed
feat(utils): prevent error if optional dep is not found
A nice warning tells users they need to install the optional deps.
1 parent 31855a4 commit 760a767

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pyneuroml/utils/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
logger = logging.getLogger(__name__)
3434
logger.setLevel(logging.INFO)
3535

36+
try:
37+
import libsedml
38+
except ModuleNotFoundError:
39+
logger.warning("Please install optional dependencies to use libsedml:")
40+
logger.warning("pip install pyneuroml[combine]")
41+
3642

3743
MAX_COLOUR = (255, 0, 0) # type: typing.Tuple[int, int, int]
3844
MIN_COLOUR = (255, 255, 0) # type: typing.Tuple[int, int, int]
@@ -121,7 +127,6 @@ def extract_position_info(
121127
if verbose:
122128
print(info)
123129

124-
colour = "b"
125130
substitute_radius = None
126131

127132
props = []
@@ -555,7 +560,6 @@ def get_model_file_list(
555560
lems_def_dir = get_model_file_list(inc, filelist, rootdir, lems_def_dir)
556561

557562
elif rootfile.endswith(".sedml"):
558-
import libsedml
559563
if pathlib.Path(rootfile).is_absolute():
560564
rootdoc = libsedml.readSedMLFromFile(rootfile)
561565
else:
@@ -577,7 +581,7 @@ def get_model_file_list(
577581

578582

579583
def extract_lems_definition_files(
580-
path: typing.Union[str, None, tempfile.TemporaryDirectory] = None
584+
path: typing.Union[str, None, tempfile.TemporaryDirectory] = None,
581585
) -> str:
582586
"""Extract the NeuroML2 LEMS definition files to a directory and return its path.
583587

0 commit comments

Comments
 (0)