Skip to content

Commit

Permalink
feat(pynml): do not import plotters if mpl is not already imported
Browse files Browse the repository at this point in the history
Note: remove these functions from pynml in the future

See also: suny-downstate-medical-center/netpyne#787
  • Loading branch information
sanjayankur31 committed Nov 2, 2023
1 parent 9e1adce commit 8cad443
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions pyneuroml/pynml.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,31 @@
import neuroml.loaders as loaders
import neuroml.writers as writers

# to maintain API compatibility:
# so that existing scripts that use: from pynml import generate_plot
# continue to work
from pyneuroml.plot import generate_plot, generate_interactive_plot # noqa
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

matplotlib_imported = False
for k in sys.modules.keys():
if "matplotlib" in k:
matplotlib_imported = True
break
if matplotlib_imported is True:
# to maintain API compatibility:
# so that existing scripts that use: from pynml import generate_plot
# continue to work
from pyneuroml.plot import generate_plot, generate_interactive_plot # noqa
else:
logger.warning("Matplotlib has not been imported, not importing plotting functions")
logger.warning("Please import these explicitly from pyneuroml.plot")
warnings.warn(
"""
Please note that these plotting methods will be removed from the pynml
module in the future. Please import plotting methods expliclitly from
the pyneuroml.plot sub module.
""",
FutureWarning,
stacklevel=2,
)

DEFAULTS = {
"v": False,
Expand All @@ -58,9 +79,6 @@

lems_model_with_units = None

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)

version_string = "pyNeuroML v{} (libNeuroML v{}, jNeuroML v{})".format(
__version__, neuroml.__version__, JNEUROML_VERSION
)
Expand Down

0 comments on commit 8cad443

Please sign in to comment.