From commits-return-87010-archive-asf-public=cust-asf.ponee.io@airflow.apache.org Mon Jan 6 16:06:58 2020 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 69F5618067E for ; Mon, 6 Jan 2020 17:06:58 +0100 (CET) Received: (qmail 27146 invoked by uid 500); 6 Jan 2020 16:06:56 -0000 Mailing-List: contact commits-help@airflow.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airflow.apache.org Delivered-To: mailing list commits@airflow.apache.org Received: (qmail 27030 invoked by uid 99); 6 Jan 2020 16:06:55 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Jan 2020 16:06:55 +0000 From: GitBox To: commits@airflow.apache.org Subject: [GitHub] [airflow] feluelle commented on a change in pull request #6696: [AIRFLOW-6128] Simplify plugins_manager and webserver plugin code Message-ID: <157832681570.22896.14988223426485339554.gitbox@gitbox.apache.org> References: In-Reply-To: Date: Mon, 06 Jan 2020 16:06:55 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit feluelle commented on a change in pull request #6696: [AIRFLOW-6128] Simplify plugins_manager and webserver plugin code URL: https://github.com/apache/airflow/pull/6696#discussion_r363355164 ########## File path: airflow/plugins_manager.py ########## @@ -159,161 +143,195 @@ def is_valid_plugin(plugin_obj, existing_plugins): return False -plugins = [] # type: List[AirflowPlugin] +plugins: List[AirflowPlugin] = [] +stat_name_handlers: List[Callable[[str], str]] = [] + + +def load_entrypoint_plugins(entry_points: Generator[EntryPoint, None, None]) -> None: + """ + Load AirflowPlugin subclasses from the entrypoints + provided. The entry_point group should be 'airflow.plugins'. + + :param entry_points: A collection of entrypoints to search for plugins + :type entry_points: Generator[setuptools.EntryPoint, None, None] + """ + for entry_point in entry_points: + log.debug('Importing entry_point plugin %s', entry_point.name) + plugin_obj = entry_point.load() + if is_valid_plugin(plugin_obj, plugins): + if callable(getattr(plugin_obj, 'on_load', None)): + plugin_obj.on_load() + plugins.append(plugin_obj) + -norm_pattern = re.compile(r'[/|.]') +load_entrypoint_plugins(pkg_resources.iter_entry_points('airflow.plugins')) -assert settings.PLUGINS_FOLDER, "Plugins folder is not set" -# Crawl through the plugins folder to find AirflowPlugin derivatives -for root, dirs, files in os.walk(settings.PLUGINS_FOLDER, followlinks=True): - for f in files: - filepath = os.path.join(root, f) - try: - if not os.path.isfile(filepath): - continue - mod_name, file_ext = os.path.splitext( - os.path.split(filepath)[-1]) - if file_ext != '.py': - continue +def import_plugin(filepath: str, mod_name: str, root: str) -> None: + """Imports plugin module.""" Review comment: Don't you think a full documentation is needed here? ---------------------------------------------------------------- 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 With regards, Apache Git Services