From 4fe023d993a049ebf56b0ec039f80689cb4fb25b Mon Sep 17 00:00:00 2001
From: Padraig Gleeson 
Date: Mon, 18 Oct 2021 17:52:53 +0100
Subject: [PATCH] To v0.5.18
Add check on import into neuroml file of non nml file (e.g. importing a
lems file was failing at include_neuroml2_file)
---
 pyneuroml/__init__.py      |  2 +-
 pyneuroml/lems/__init__.py | 39 ++++++++++++++++++++------------------
 2 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/pyneuroml/__init__.py b/pyneuroml/__init__.py
index 356eeef8..4a04b544 100644
--- a/pyneuroml/__init__.py
+++ b/pyneuroml/__init__.py
@@ -1,6 +1,6 @@
 import logging
 
-__version__ = "0.5.13"
+__version__ = "0.5.18"
 
 JNEUROML_VERSION = "0.11.0"
 
diff --git a/pyneuroml/lems/__init__.py b/pyneuroml/lems/__init__.py
index 87694b6b..7e1b3417 100644
--- a/pyneuroml/lems/__init__.py
+++ b/pyneuroml/lems/__init__.py
@@ -148,26 +148,29 @@ def generate_lems_file_for_neuroml(
                 shutil.copy(incl_curr, target_dir)
 
             ls.include_neuroml2_file(include.href, include_included=False)
-            sub_doc = read_neuroml2_file(incl_curr)
-            sub_dir = (
-                os.path.dirname(incl_curr)
-                if len(os.path.dirname(incl_curr)) > 0
-                else "."
-            )
-
-            if sub_doc.__class__ == neuroml.nml.nml.NeuroMLDocument:
-                for include in sub_doc.includes:
-                    incl_curr = "%s/%s" % (sub_dir, include.href)
-                    logger.info(
-                        " -- Including %s located at %s" % (include.href, incl_curr)
-                    )
+            try:
+                sub_doc = read_neuroml2_file(incl_curr)
+                sub_dir = (
+                    os.path.dirname(incl_curr)
+                    if len(os.path.dirname(incl_curr)) > 0
+                    else "."
+                )
+
+                if sub_doc.__class__ == neuroml.nml.nml.NeuroMLDocument:
+                    for include in sub_doc.includes:
+                        incl_curr = "%s/%s" % (sub_dir, include.href)
+                        logger.info(
+                            " -- Including %s located at %s" % (include.href, incl_curr)
+                        )
 
-                    if not os.path.isfile(
-                        "%s/%s" % (target_dir, os.path.basename(incl_curr))
-                    ) and not os.path.isfile("%s/%s" % (target_dir, incl_curr)):
+                        if not os.path.isfile(
+                            "%s/%s" % (target_dir, os.path.basename(incl_curr))
+                        ) and not os.path.isfile("%s/%s" % (target_dir, incl_curr)):
 
-                        shutil.copy(incl_curr, target_dir)
-                        ls.include_neuroml2_file(include.href, include_included=False)
+                            shutil.copy(incl_curr, target_dir)
+                            ls.include_neuroml2_file(include.href, include_included=False)
+            except TypeError:
+                logging.info("File: %s is not a NeuroML file, but it may be LEMS, ignoring..." % incl_curr)
 
     if (
         gen_plots_for_all_v