This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-liminal.git

commit 2ef72ec83223f4a8e292d73fd7cd0782b17b968d
Author: aviemzur <[email protected]>
AuthorDate: Wed Mar 18 09:52:34 2020 +0200

    Performance improvement for class_util
---
 rainbow/core/util/class_util.py | 37 +++++++++++++++++--------------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/rainbow/core/util/class_util.py b/rainbow/core/util/class_util.py
index 31e1806..e083477 100644
--- a/rainbow/core/util/class_util.py
+++ b/rainbow/core/util/class_util.py
@@ -31,26 +31,23 @@ def find_subclasses_in_packages(packages, parent_class):
 
     for py_path in [a for a in sys.path]:
         for root, directories, files in os.walk(py_path):
-            for file in files:
-                file_path = os.path.join(root, file)
-                if any(p in file_path for p in packages) \
-                        and file.endswith('.py') \
-                        and '__pycache__' not in file_path:
-
-                    spec = importlib.util.spec_from_file_location(file[:-3], 
file_path)
-                    mod = importlib.util.module_from_spec(spec)
-                    spec.loader.exec_module(mod)
-                    for name, obj in inspect.getmembers(mod):
-                        if inspect.isclass(obj) and not 
obj.__name__.endswith('Mixin'):
-                            module_name = mod.__name__
-                            class_name = obj.__name__
-                            parent_module = root[len(py_path) + 
1:].replace('/', '.')
-                            module = parent_module.replace('airflow.dags.', 
'') + \
-                                     '.' + module_name
-                            clazz = __get_class(module, class_name)
-                            if issubclass(clazz, parent_class):
-                                classes.update({module_name: clazz})
-
+            if any(package in root for package in packages):
+                for file in files:
+                    file_path = os.path.join(root, file)
+                    if file.endswith('.py') and '__pycache__' not in file_path:
+                        spec = 
importlib.util.spec_from_file_location(file[:-3], file_path)
+                        mod = importlib.util.module_from_spec(spec)
+                        spec.loader.exec_module(mod)
+                        for name, obj in inspect.getmembers(mod):
+                            if inspect.isclass(obj) and not 
obj.__name__.endswith('Mixin'):
+                                module_name = mod.__name__
+                                class_name = obj.__name__
+                                parent_module = root[len(py_path) + 
1:].replace('/', '.')
+                                module = 
parent_module.replace('airflow.dags.', '') + \
+                                         '.' + module_name
+                                clazz = __get_class(module, class_name)
+                                if issubclass(clazz, parent_class):
+                                    classes.update({module_name: clazz})
     return classes
 
 

Reply via email to