feluelle commented on a change in pull request #6696: [AIRFLOW-6128] Simplify
plugins_manager and webserver plugin code
URL: https://github.com/apache/airflow/pull/6696#discussion_r363355164
##########
File path: airflow/plugins_manager.py
##########
@@ -159,161 +143,195 @@ def is_valid_plugin(plugin_obj, existing_plugins):
return False
-plugins = [] # type: List[AirflowPlugin]
+plugins: List[AirflowPlugin] = []
+stat_name_handlers: List[Callable[[str], str]] = []
+
+
+def load_entrypoint_plugins(entry_points: Generator[EntryPoint, None, None])
-> None:
+ """
+ Load AirflowPlugin subclasses from the entrypoints
+ provided. The entry_point group should be 'airflow.plugins'.
+
+ :param entry_points: A collection of entrypoints to search for plugins
+ :type entry_points: Generator[setuptools.EntryPoint, None, None]
+ """
+ for entry_point in entry_points:
+ log.debug('Importing entry_point plugin %s', entry_point.name)
+ plugin_obj = entry_point.load()
+ if is_valid_plugin(plugin_obj, plugins):
+ if callable(getattr(plugin_obj, 'on_load', None)):
+ plugin_obj.on_load()
+ plugins.append(plugin_obj)
+
-norm_pattern = re.compile(r'[/|.]')
+load_entrypoint_plugins(pkg_resources.iter_entry_points('airflow.plugins'))
-assert settings.PLUGINS_FOLDER, "Plugins folder is not set"
-# Crawl through the plugins folder to find AirflowPlugin derivatives
-for root, dirs, files in os.walk(settings.PLUGINS_FOLDER, followlinks=True):
- for f in files:
- filepath = os.path.join(root, f)
- try:
- if not os.path.isfile(filepath):
- continue
- mod_name, file_ext = os.path.splitext(
- os.path.split(filepath)[-1])
- if file_ext != '.py':
- continue
+def import_plugin(filepath: str, mod_name: str, root: str) -> None:
+ """Imports plugin module."""
Review comment:
Don't you think a full documentation is needed here?
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services