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



##########
File path: airflow/providers_manager.py
##########
@@ -178,7 +181,49 @@ def _add_provider_info_from_local_source_file(self, path, 
package_name) -> None:
         except Exception as e:  # noqa pylint: disable=broad-except
             log.warning("Error when loading '%s': %s", path, e)
 
+    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)
+        except Exception as e:  # noqa pylint: disable=broad-except
+            log.warning(
+                "The '%s' extra-link from '%s' could not be imported: %s",
+                extra_link_class_name,
+                provider_package,
+                e,
+            )
+            return
+        self.__extra_link_class_name_set.add(extra_link_class_name)
+
     @property
     def providers(self):
         """Returns information about available providers."""
         return self._provider_dict
+
+    @property
+    def extra_links_class_names(self):
+        """Returns set of extra link class names."""
+        return sorted(list(self.__extra_link_class_name_set))

Review comment:
       ```suggestion
           return sorted(self.__extra_link_class_name_set)
   ```
   
   sorted would return a list anyway:
   
   ```python
   In [1]: a = {'d', 'a', 'c'}
   
   In [2]: sorted(a)
   Out[2]: ['a', 'c', 'd']
   ```




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