amoghrajesh commented on code in PR #59956: URL: https://github.com/apache/airflow/pull/59956#discussion_r2661451657
########## shared/plugins_manager/src/airflow_shared/plugins_manager/plugins_manager.py: ########## @@ -0,0 +1,280 @@ +# +# 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 plugins.""" + +from __future__ import annotations + +import inspect +import logging +import os +import sys +import types +from pathlib import Path +from typing import TYPE_CHECKING, Any + +# TODO: these should be moved into module_loading i think +from airflow.utils.entry_points import entry_points_with_dist +from airflow.utils.file import find_path_from_directory + +if TYPE_CHECKING: + if sys.version_info >= (3, 12): + from importlib import metadata + else: + import importlib_metadata as metadata + from collections.abc import Generator + from types import ModuleType + + from airflow.listeners.listener import ListenerManager + +log = logging.getLogger(__name__) + + +class AirflowPluginSource: + """Class used to define an AirflowPluginSource.""" + + def __str__(self): + raise NotImplementedError + + def __html__(self): + raise NotImplementedError + + +class PluginsDirectorySource(AirflowPluginSource): + """Class used to define Plugins loaded from Plugins Directory.""" + + def __init__(self, path, plugins_folder: str): + self.path = os.path.relpath(path, plugins_folder) + + def __str__(self): + return f"$PLUGINS_FOLDER/{self.path}" + + def __html__(self): + return f"<em>$PLUGINS_FOLDER/</em>{self.path}" + + +class EntryPointSource(AirflowPluginSource): + """Class used to define Plugins loaded from entrypoint.""" + + def __init__(self, entrypoint: metadata.EntryPoint, dist: metadata.Distribution): + self.dist = dist.metadata["Name"] # type: ignore[index] + self.version = dist.version + self.entrypoint = str(entrypoint) + + def __str__(self): + return f"{self.dist}=={self.version}: {self.entrypoint}" + + def __html__(self): + return f"<em>{self.dist}=={self.version}:</em> {self.entrypoint}" + + +class AirflowPluginException(Exception): + """Exception when loading plugin.""" + + +class AirflowPlugin: + """Class used to define AirflowPlugin.""" + + name: str | None = None + source: AirflowPluginSource | None = None + macros: list[Any] = [] + admin_views: list[Any] = [] + flask_blueprints: list[Any] = [] + fastapi_apps: list[Any] = [] + fastapi_root_middlewares: list[Any] = [] + external_views: list[Any] = [] + react_apps: list[Any] = [] + menu_links: list[Any] = [] Review Comment: Umm, I think its a separate discussion, but good call, would you mind creating an issue for it? -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
