ashb commented on a change in pull request #12472:
URL: https://github.com/apache/airflow/pull/12472#discussion_r533731217



##########
File path: airflow/providers_manager.py
##########
@@ -224,6 +226,43 @@ def _add_hook(self, hook_class_name, provider_package) -> 
None:
 
         self._hooks_dict[conn_type] = (hook_class_name, 
connection_id_attribute_name)
 
+    def _discover_extra_links(self) -> None:
+        """Retrieves all extra links defined in the providers"""
+        for provider_package, (_, provider) in self._provider_dict.items():
+            if provider.get("extra-links"):
+                for extra_link in provider["extra-links"]:
+                    self.__add_extra_link(extra_link, provider_package)
+
+    def __add_extra_link(self, extra_link_class_name, provider_package) -> 
None:
+        """
+        Adds extra link class name to the list of classes
+        :param extra_link_class_name: name of the class to add
+        :param provider_package: provider package adding the link
+        :return:
+        """
+        if provider_package.startswith("apache-airflow"):
+            provider_path = provider_package[len("apache-") :].replace("-", 
".")
+            if not extra_link_class_name.startswith(provider_path):
+                log.warning(
+                    "Sanity check failed when importing '%s' from '%s' 
package. It should start with '%s'",
+                    extra_link_class_name,
+                    provider_package,
+                    provider_path,
+                )
+                return
+        try:
+            module, class_name = extra_link_class_name.rsplit('.', maxsplit=1)
+            getattr(importlib.import_module(module), class_name)

Review comment:
       Do we need actually to import all the classes here? That's potentially a 
lot of extra code that is imported in to the scheduler as a result, that is 
otherwise un-needed (if I'm reading where this is used/called from right)




----------------------------------------------------------------
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]


Reply via email to