From c0c0dcf6982d524ae28cb00b8f3b2a8ad888beef Mon Sep 17 00:00:00 2001 From: Asher Foa <1268088+asherf@users.noreply.github.com> Date: Mon, 8 Aug 2022 15:47:09 -0400 Subject: [PATCH] Allow backend packages to also register remote auth plugins Follow up for https://github.com/pantsbuild/pants/pull/16212 This is useful when the remote auth plugin is a first party (in repo plugin). also add some debug logging. --- src/python/pants/init/extension_loader.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/python/pants/init/extension_loader.py b/src/python/pants/init/extension_loader.py index 0365eeecb3c..2fecae4ba86 100644 --- a/src/python/pants/init/extension_loader.py +++ b/src/python/pants/init/extension_loader.py @@ -2,6 +2,7 @@ # Licensed under the Apache License, Version 2.0 (see LICENSE). import importlib +import logging import traceback from typing import Dict, List, Optional @@ -12,6 +13,8 @@ from pants.goal.builtins import register_builtin_goals from pants.util.ordered_set import FrozenOrderedSet +logger = logging.getLogger(__name__) + class PluginLoadingError(Exception): pass @@ -100,6 +103,9 @@ def load_plugins( build_configuration.register_rules(req.key, rules) if "remote_auth" in entries: remote_auth_func = entries["remote_auth"].load() + logger.debug( + f"register remote auth function {remote_auth_func.__module__}.{remote_auth_func.__name__} from plugin: {plugin}" + ) build_configuration.register_remote_auth_plugin(remote_auth_func) loaded[dist.as_requirement().key] = dist @@ -137,7 +143,7 @@ def load_backend(build_configuration: BuildConfiguration.Builder, backend_packag traceback.print_exc() raise BackendConfigurationError(f"Failed to load the {backend_module} backend: {ex!r}") - def invoke_entrypoint(name): + def invoke_entrypoint(name: str): entrypoint = getattr(module, name, lambda: None) try: return entrypoint() @@ -156,3 +162,9 @@ def invoke_entrypoint(name): rules = invoke_entrypoint("rules") if rules: build_configuration.register_rules(backend_package, rules) + remote_auth_func = getattr(module, "remote_auth", None) + if remote_auth_func: + logger.debug( + f"register remote auth function {remote_auth_func.__module__}.{remote_auth_func.__name__} from backend: {backend_package}" + ) + build_configuration.register_remote_auth_plugin(remote_auth_func)