From c1749f6ece7bfba770b132c4504710842d5ab9a0 Mon Sep 17 00:00:00 2001
From: "sascha.herzinger" <sascha.herzinger@uni.lu>
Date: Tue, 17 Oct 2017 10:30:40 +0200
Subject: [PATCH] Making project compatible with python 3.4

---
 fractalis/sync.py  |  5 ++++-
 fractalis/utils.py | 12 +++++-------
 setup.py           | 39 ++++++++++++++++++++-------------------
 3 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/fractalis/sync.py b/fractalis/sync.py
index 93f173a..4c12754 100644
--- a/fractalis/sync.py
+++ b/fractalis/sync.py
@@ -55,7 +55,10 @@ def cleanup_all() -> None:
     for key in redis.keys('data:*'):
         value = redis.get(key)
         data_state = json.loads(value)
-        celery.AsyncResult(data_state['task_id']).get(propagate=False)
+        try:
+            celery.AsyncResult(data_state.get('task_id')).get(propagate=False)
+        except ValueError:
+            pass
         # celery.control.revoke(data_state['task_id'], terminate=True,
         #                       signal='SIGUSR1', wait=True)
     redis.flushall()
diff --git a/fractalis/utils.py b/fractalis/utils.py
index 951376a..fdf8192 100644
--- a/fractalis/utils.py
+++ b/fractalis/utils.py
@@ -1,8 +1,9 @@
 import os
-import glob
 import inspect
 import importlib
+from pathlib import Path
 from typing import List
+from importlib.machinery import SourceFileLoader
 
 
 def import_module_by_abs_path(module_path: str) -> object:
@@ -11,10 +12,7 @@ def import_module_by_abs_path(module_path: str) -> object:
     :return: A reference to the imported module.
     """
     module_name = os.path.splitext(os.path.basename(module_path))[0]
-    spec = importlib.util.spec_from_file_location(module_name, module_path)
-    module = importlib.util.module_from_spec(spec)
-    spec.loader.exec_module(module)
-    return module
+    return SourceFileLoader(module_name, module_path).load_module()
 
 
 def list_classes_with_base_class(
@@ -28,8 +26,8 @@ def list_classes_with_base_class(
     package = importlib.import_module(package)
     abs_path = os.path.dirname(os.path.abspath(package.__file__))
     class_list = []
-    for module_path in glob.iglob('{}/*/**/*.py'.format(abs_path),
-                                  recursive=True):
+    for f in Path(abs_path).glob('*/**/*.py'):
+        module_path = str(f)
         if not os.path.basename(module_path).startswith('_'):
             module = import_module_by_abs_path(module_path)
             classes = inspect.getmembers(module, inspect.isclass)
diff --git a/setup.py b/setup.py
index a3b43dc..e18ec25 100644
--- a/setup.py
+++ b/setup.py
@@ -8,29 +8,30 @@ setup(
     packages=find_packages(),
     include_package_data=True,
     install_requires=[
-        'Flask',
-        'flask-cors',
-        'Flask-Script',
-        'flask-request-id-middleware',
-        'flask-compress',
-        'jsonschema',
-        'celery[redis]',
-        'redis',
-        'pandas',
-        'numpy',
-        'scipy',
-        'sklearn',
-        'requests',
-        'PyYAML',
-        'pycryptodomex',
-        'rpy2'
+        'Flask==0.12.2',
+        'flask-cors==3.0.3',
+        'Flask-Script==2.0.6',
+        'flask-request-id-middleware==1.1',
+        'flask-compress==1.4.0',
+        'typing==3.6.2',
+        'jsonschema==2.6.0',
+        'celery[redis]==4.1.0',
+        'redis==2.10.6',
+        'numpy==1.13.3',
+        'scipy==0.19.1',
+        'pandas==0.20.3',
+        'sklearn==0.0',
+        'requests==2.18.4',
+        'PyYAML==3.12',
+        'pycryptodomex==3.4.7',
+        'rpy2==2.9.0'
     ],
     setup_requires=[
-        'pytest-runner',
+        'pytest-runner==2.12.1',
     ],
     tests_require=[
         'pytest==3.0.3',
-        'pytest-mock',
-        'responses'
+        'pytest-mock==1.6.3',
+        'responses==0.8.1'
     ]
 )
-- 
GitLab