예제 #1
0
 def _discover_all_providers_from_packages(self) -> None:
     """
     Discovers all providers by scanning packages installed. The list of providers should be returned
     via the 'apache_airflow_provider' entrypoint as a dictionary conforming to the
     'airflow/provider.yaml.schema.json' schema.
     """
     for entry_point, dist in entry_points_with_dist(
             'apache_airflow_provider'):
         package_name = dist.metadata['name']
         log.debug("Loading %s from package %s", entry_point, package_name)
         version = dist.version
         provider_info = entry_point.load()()
         self._validator.validate(provider_info)
         provider_info_package_name = provider_info['package-name']
         if package_name != provider_info_package_name:
             raise Exception(
                 f"The package '{package_name}' from setuptools and "
                 f"{provider_info_package_name} do not match. Please make sure they are aligned"
             )
         if package_name not in self._provider_dict:
             self._provider_dict[package_name] = (version, provider_info)
         else:
             log.warning(
                 "The provider for package '%s' could not be registered from because providers for that "
                 "package name have already been registered",
                 package_name,
             )
예제 #2
0
 def _discover_all_providers_from_packages(self) -> None:
     """
     Discovers all providers by scanning packages installed. The list of providers should be returned
     via the 'apache_airflow_provider' entrypoint as a dictionary conforming to the
     'airflow/provider_info.schema.json' schema. Note that the schema is different at runtime
     than provider.yaml.schema.json. The development version of provider schema is more strict and changes
     together with the code. The runtime version is more relaxed (allows for additional properties)
     and verifies only the subset of fields that are needed at runtime.
     """
     for entry_point, dist in entry_points_with_dist(
             'apache_airflow_provider'):
         package_name = dist.metadata['name']
         if self._provider_dict.get(package_name) is not None:
             continue
         log.debug("Loading %s from package %s", entry_point, package_name)
         version = dist.version
         provider_info = entry_point.load()()
         self._provider_schema_validator.validate(provider_info)
         provider_info_package_name = provider_info['package-name']
         if package_name != provider_info_package_name:
             raise Exception(
                 f"The package '{package_name}' from setuptools and "
                 f"{provider_info_package_name} do not match. Please make sure they are aligned"
             )
         if package_name not in self._provider_dict:
             self._provider_dict[package_name] = ProviderInfo(
                 version, provider_info, 'package')
         else:
             log.warning(
                 "The provider for package '%s' could not be registered from because providers for that "
                 "package name have already been registered",
                 package_name,
             )
예제 #3
0
def load_entrypoint_plugins():
    """
    Load and register plugins AirflowPlugin subclasses from the entrypoints.
    The entry_point group should be 'airflow.plugins'.
    """
    global import_errors  # pylint: disable=global-statement
    global plugins  # pylint: disable=global-statement

    log.debug("Loading plugins from entrypoints")

    for entry_point, dist in entry_points_with_dist('airflow.plugins'):
        log.debug('Importing entry_point plugin %s', entry_point.name)
        try:
            plugin_class = entry_point.load()
            if not is_valid_plugin(plugin_class):
                continue

            plugin_instance = plugin_class()
            if callable(getattr(plugin_instance, 'on_load', None)):
                plugin_instance.on_load()
                plugin_instance.source = EntryPointSource(entry_point, dist)
                plugins.append(plugin_instance)
        except Exception as e:  # pylint: disable=broad-except
            log.exception("Failed to import plugin %s", entry_point.name)
            import_errors[entry_point.module] = str(e)
예제 #4
0
def load_entrypoint_plugins():
    """
    Load and register plugins AirflowPlugin subclasses from the entrypoints.
    The entry_point group should be 'airflow.plugins'.
    """
    global import_errors

    log.debug("Loading plugins from entrypoints")

    for entry_point, dist in entry_points_with_dist('airflow.plugins'):
        log.debug('Importing entry_point plugin %s', entry_point.name)
        try:
            plugin_class = entry_point.load()
            if not is_valid_plugin(plugin_class):
                continue

            plugin_instance = plugin_class()
            plugin_instance.source = EntryPointSource(entry_point, dist)
            register_plugin(plugin_instance)
        except Exception as e:
            log.exception("Failed to import plugin %s", entry_point.name)
            import_errors[entry_point.module] = str(e)