From e53e1b1dab159ef342e21d9a4e2f48ea935d371f Mon Sep 17 00:00:00 2001
From: Robert Rosca <robert.rosca@xfel.eu>
Date: Thu, 4 Mar 2021 22:05:01 +0100
Subject: [PATCH] Use importlib to check if XFELDetAna is installed

---
 setup.py | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/setup.py b/setup.py
index 86c3a44f1..e6f030abe 100644
--- a/setup.py
+++ b/setup.py
@@ -1,3 +1,4 @@
+import importlib
 import sys
 from distutils.command.build import build
 from distutils.extension import Extension
@@ -28,20 +29,15 @@ class PostInstallCommand(install):
         python_path = sys.executable
         if "karabo" in python_path:
             print("Karabo installation detected, checking for PyDetLib installation")
-            try:
-                import XFELDetAna
-
-                print("...found!")
-                return
-            except ImportError:
-                "No PyDetLib installation found, attempting to install"
+            if importlib.util.find_spec("XFELDetAna") is None:
+                print("No PyDetLib installation found, attempting to install")
                 check_call(
                     "karabo -g https://in.xfel.eu/gitlab install pyDetLib master".split()
                 )
         else:
             print(
-                "Python environment seems to not be a Karabo environment. "
-                + "Please install PyDetLib manually."
+                "Python environment seems to not be a Karabo environment. Please"
+                "install PyDetLib manually."
             )
 
 
@@ -92,7 +88,8 @@ setup(
             "bin/*.sh",
             "titlepage.tmpl",
             "xfel.pdf",
-        ] + data_files
+        ]
+        + data_files
     },
     entry_points={
         "console_scripts": [
@@ -164,7 +161,7 @@ setup(
         "dev": [
             "nbqa[toolchain]",
             "pre-commit",
-        ]
+        ],
     },
     python_requires=">=3.6",
     classifiers=[
-- 
GitLab