Skip to content

Commit

Permalink
Have go_bootstrap raise an error if using asdf in a lon-local env…
Browse files Browse the repository at this point in the history
…ironment
  • Loading branch information
Christopher Neugebauer committed Sep 29, 2022
1 parent e3325d8 commit 7d52aa6
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/python/pants/backend/go/util_rules/go_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
from pants.backend.go.subsystems.golang import GolangSubsystem
from pants.core.util_rules import asdf
from pants.core.util_rules.asdf import AsdfToolPathsRequest, AsdfToolPathsResult
from pants.core.util_rules.environments import EnvironmentTarget
from pants.core.util_rules.environments import EnvironmentTarget, LocalEnvironmentTarget
from pants.engine.env_vars import EnvironmentVars, EnvironmentVarsRequest
from pants.engine.internals.selectors import Get
from pants.engine.rules import collect_rules, rule, rule_helper
from pants.util.strutil import softwrap

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -77,10 +78,47 @@ async def _environment_paths() -> list[str]:
return []


def _error_if_not_compatible_with_asdf(
env_tgt: EnvironmentTarget,
_search_paths: Iterable[str],
) -> None:
"""Raises an exception if any special search path strings any are invalid for the environment.
If the environment is non-local and there are invalid tokens for those environments, raise
`ValueError`.
"""

env = env_tgt.val

if env is None or isinstance(env, LocalEnvironmentTarget):
return

not_allowed = {"<ASDF>", "<ASDF_LOCAL>"}

any_not_allowed = set(_search_paths) & not_allowed
if any_not_allowed:
env_type = type(env)
raise ValueError(
softwrap(
f"`[python-bootstrap].search_paths` is configured to use local Go discovery "
f"tools, which do not work in {env_type.__name__} runtime environments. To fix "
f"this, set the value of `golang_go_search_paths` in the `{env.alias}` "
f"defined at `{env.address}` to contain only hardcoded paths or the `<PATH>` "
"special string."
)
)

return


@rule
async def resolve_go_bootstrap(
golang_subsystem: GolangSubsystem, golang_env_aware: GolangSubsystem.EnvironmentAware
) -> GoBootstrap:

_error_if_not_compatible_with_asdf(
golang_env_aware.env_tgt, golang_env_aware.raw_go_search_paths
)
paths = await _go_search_paths(
golang_env_aware.env_tgt, golang_subsystem, golang_env_aware.raw_go_search_paths
)
Expand Down

0 comments on commit 7d52aa6

Please sign in to comment.