Skip to content

Commit

Permalink
Allow backend packages to also register remote auth plugins (pantsbui…
Browse files Browse the repository at this point in the history
…ld#16444)

Follow up for pantsbuild#16212

This is useful when the remote auth plugin is a first party (in repo plugin).
also add some debug logging.

[ci skip-rust]
  • Loading branch information
asherf authored Aug 8, 2022
1 parent add0956 commit b5a0611
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/python/pants/init/extension_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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)

0 comments on commit b5a0611

Please sign in to comment.