Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use an EnvironmentTarget helper instead of direct isinstance checks #21586

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/python/pants/core/util_rules/adhoc_binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from textwrap import dedent # noqa: PNT20

from pants.core.subsystems.python_bootstrap import PythonBootstrapSubsystem
from pants.core.util_rules.environments import EnvironmentTarget, LocalEnvironmentTarget
from pants.core.util_rules.environments import EnvironmentTarget
from pants.core.util_rules.system_binaries import BashBinary, SystemBinariesSubsystem, TarBinary
from pants.engine.fs import DownloadFile
from pants.engine.internals.native_engine import Digest, FileDigest
Expand Down Expand Up @@ -49,7 +49,7 @@ class _DownloadPythonBuildStandaloneBinaryRequest:

@rule
async def get_python_for_scripts(env_tgt: EnvironmentTarget) -> PythonBuildStandaloneBinary:
if env_tgt.val is None or isinstance(env_tgt.val, LocalEnvironmentTarget):
if env_tgt.can_access_local_system_paths:
return PythonBuildStandaloneBinary(sys.executable)

result = await Get(_PythonBuildStandaloneBinary, _DownloadPythonBuildStandaloneBinaryRequest())
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/core/util_rules/asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from pants.base.build_environment import get_buildroot
from pants.base.build_root import BuildRoot
from pants.core.util_rules.environments import EnvironmentTarget, LocalEnvironmentTarget
from pants.core.util_rules.environments import EnvironmentTarget
from pants.engine.env_vars import EnvironmentVars, EnvironmentVarsRequest
from pants.engine.internals.selectors import Get
from pants.engine.rules import _uncacheable_rule, collect_rules
Expand Down Expand Up @@ -97,7 +97,7 @@ async def _resolve_asdf_tool_paths(
env: EnvironmentVars,
local: bool,
) -> tuple[str, ...]:
if not (isinstance(env_tgt.val, LocalEnvironmentTarget) or env_tgt.val is None):
if not env_tgt.can_access_local_system_paths:
return ()

asdf_dir = get_asdf_data_dir(env)
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/core/util_rules/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ async def _warn_on_non_local_environments(specified_targets: Iterable[Target], s
error_cases = [
(env_name, tgts, env_tgt.val)
for ((env_name, tgts), env_tgt) in zip(env_names_and_targets, env_tgts)
if env_tgt.val is not None and not isinstance(env_tgt.val, LocalEnvironmentTarget)
if env_tgt.val is not None and not env_tgt.can_access_local_system_paths
]

for env_name, tgts, env_tgt in error_cases:
Expand Down Expand Up @@ -592,7 +592,7 @@ def use_working_directory_as_base_for_output_captures(self) -> bool:
return True

@property
def can_use_system_path_metadata_requests(self) -> bool:
def can_access_local_system_paths(self) -> bool:
tgt = self.val
if not tgt:
return True
Expand Down
7 changes: 4 additions & 3 deletions src/python/pants/core/util_rules/search_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Any, ClassVar, Iterable

from pants.base.build_environment import get_buildroot
from pants.core.util_rules.environments import EnvironmentTarget, LocalEnvironmentTarget
from pants.core.util_rules.environments import EnvironmentTarget
from pants.engine.collection import DeduplicatedCollection
from pants.engine.env_vars import EnvironmentVars
from pants.engine.rules import Rule, _uncacheable_rule, collect_rules, rule
Expand Down Expand Up @@ -51,7 +51,7 @@ async def get_un_cachable_version_manager_paths(
request: VersionManagerSearchPathsRequest,
) -> VersionManagerSearchPaths:
"""Inspects the directory of a version manager tool like pyenv or nvm to find installations."""
if not (request.env_tgt.val is None or isinstance(request.env_tgt.val, LocalEnvironmentTarget)):
if not request.env_tgt.can_access_local_system_paths:
return VersionManagerSearchPaths()

manager_root_dir = request.root_dir
Expand Down Expand Up @@ -121,8 +121,9 @@ async def validate_search_paths(request: ValidateSearchPathsRequest) -> Validate
env = request.env_tgt.val
search_paths = request.search_paths

if env is None or isinstance(env, LocalEnvironmentTarget):
if request.env_tgt.can_access_local_system_paths:
return ValidatedSearchPaths(search_paths)
assert env is not None, "Expected request.env_tgt to be defined"

if request.is_default:
# Strip out the not-allowed special strings from search_paths.
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/core/util_rules/system_binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ async def find_binary(
env_target: EnvironmentTarget,
) -> BinaryPaths:
found_paths: tuple[str, ...]
if env_target.can_use_system_path_metadata_requests:
if env_target.can_access_local_system_paths:
found_paths = await _find_candidate_paths_via_path_metadata_lookups(request)
else:
found_paths = await _find_candidate_paths_via_subprocess_helper(request, env_target)
Expand Down
Loading