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/11/17 11:09:54 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #12383: Adds mechanism for provider package discovery.

mik-laj commented on a change in pull request #12383:
URL: https://github.com/apache/airflow/pull/12383#discussion_r525072040



##########
File path: airflow/providers_manager.py
##########
@@ -0,0 +1,78 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""Manages all providers."""
+import importlib
+import logging
+import pkgutil
+import traceback
+
+import yaml
+
+try:
+    import importlib.resources as importlib_resources
+except ImportError:
+    # Try backported to PY<37 `importlib_resources`.
+    import importlib_resources
+
+
+log = logging.getLogger(__name__)
+
+
+class ProvidersManager:
+    """Manages all provider packages."""
+
+    def __find_all_providers(self, paths: str):
+        def onerror(_):
+            exception_string = traceback.format_exc()
+            log.warning(exception_string)
+
+        for module_info in pkgutil.walk_packages(paths, prefix="airflow.providers.", onerror=onerror):
+            try:
+                imported_module = importlib.import_module(module_info.name)
+            except Exception as e:  # noqa pylint: disable=broad-except
+                log.warning("Error when importing %s:%s", module_info.name, e)
+                continue
+            try:
+                provider_info = yaml.safe_load(
+                    importlib_resources.read_text(imported_module, 'provider.yaml')
+                )
+                # TODO(potiuk): map to a class maybe? Or we might stick to a dictionary

Review comment:
       Can you add JSON schema validation? 
   ![image](https://user-images.githubusercontent.com/12058428/99383072-ab2a1280-28cd-11eb-8d37-708358c87f7c.png)
   




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