You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/03/19 08:45:48 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #7758: [AIRFLOW-7084] Lazy initialize plugins for each entrypoint

mik-laj commented on a change in pull request #7758: [AIRFLOW-7084] Lazy initialize plugins for each entrypoint
URL: https://github.com/apache/airflow/pull/7758#discussion_r394867899
 
 

 ##########
 File path: airflow/plugins_manager.py
 ##########
 @@ -278,38 +304,90 @@ def initialize_plugins():
 
 def integrate_executor_plugins() -> None:
     """Integrate executor plugins to the context."""
+    # pylint: disable=global-statement
+    global plugins
+    global executors_modules
+    # pylint: enable=global-statement
+
+    if executors_modules is not None:
+        return
+
     ensure_plugins_loaded()
 
+    if plugins is None:
+        raise AirflowPluginException("Can't load plugins.")
+
     log.debug("Integrate executor plugins")
 
-    for executors_module in executors_modules:
-        sys.modules[executors_module.__name__] = executors_module
+    executors_modules = []
+    for plugin in plugins:
+        if plugin.name is None:
+            raise AirflowPluginException("Invalid plugin name")
+        plugin_name: str = plugin.name
+
+        executors_module = make_module('airflow.executors.' + plugin_name, plugin.executors)
+        executors_modules.append(executors_module)
+
+        sys.modules[executors_module.__name__] = executors_module  # pylint: disable=no-member
         # noinspection PyProtectedMember
         globals()[executors_module._name] = executors_module  # pylint: disable=protected-access
 
 
 def integrate_dag_plugins() -> None:
     """Integrates operator, sensor, hook, macro plugins."""
+    # pylint: disable=global-statement
+    global plugins
+    global operators_modules
+    global sensors_modules
+    global hooks_modules
+    global macros_modules
+    # pylint: enable=global-statement
+
+    if operators_modules is not None and \
+            sensors_modules is not None and \
+            hooks_modules is not None and \
+            macros_modules is not None:
+        return
+
     ensure_plugins_loaded()
 
-    log.debug("Integrate DAG plugins.")
+    if plugins is None:
+        raise AirflowPluginException("Can't load plugins.")
+
+    log.debug("Integrate DAG plugins")
+
+    operators_modules = []
+    sensors_modules = []
+    hooks_modules = []
+    macros_modules = []
+
+    for plugin in plugins:
+        if plugin.name is None:
+            raise AirflowPluginException("Invalid plugin name")
+        plugin_name: str = plugin.name
+
+        operators_module = make_module('airflow.operators.' + plugin_name, plugin.operators + plugin.sensors)
 
 Review comment:
   We do not have a text formatting convention in the project. Attempts are being made only in this PR:
   https://github.com/apache/airflow/pull/7573

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services