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

Add the ability for Pants to provide Python via a union (with a pyenv impl) #18352

Merged
merged 30 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions src/python/pants/backend/adhoc/adhoc_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ async def run_in_sandbox_request(
)
)

print(extra_sandbox_contents)
merged_extras = await Get(
ExtraSandboxContents, MergeExtraSandboxContents(tuple(extra_sandbox_contents))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ def test_adhoc_tool_is_loaded_by_backend() -> None:
args = [
"--backend-packages=['pants.backend.experimental.adhoc', 'pants.backend.python']",
f"--source-root-patterns=['{tmpdir}/src']",
"--print-stacktrace",
"package",
f"{tmpdir}/src:archive",
]
result = run_pants(args)
print(result.stdout.strip())
assert "[INFO] I'm Fleegan Floop!" in result.stderr.strip()
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ async def parse_python_dependencies(
file,
],
input_digest=input_digest,
append_only_caches=python_interpreter.append_only_caches,
description=f"Determine Python dependencies for {request.source.address}",
env=parser_script.env,
level=LogLevel.DEBUG,
Expand Down
9 changes: 8 additions & 1 deletion src/python/pants/backend/python/goals/run_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from pants.engine.fs import CreateDigest, Digest, FileContent, MergeDigests
from pants.engine.rules import Get, MultiGet
from pants.engine.target import TransitiveTargets, TransitiveTargetsRequest
from pants.util.frozendict import FrozenDict


def _in_chroot(relpath: str) -> str:
Expand Down Expand Up @@ -112,12 +113,18 @@ async def _create_python_source_run_request(
**complete_pex_environment.environment_dict(python_configured=venv_pex.python is not None),
"PEX_EXTRA_SYS_PATH": os.pathsep.join(source_roots),
}
append_only_caches = (
FrozenDict({}) if venv_pex.append_only_caches is None else venv_pex.append_only_caches
)

return RunRequest(
digest=merged_digest,
args=[_in_chroot(venv_pex.pex.argv0)],
extra_env=extra_env,
append_only_caches=complete_pex_environment.append_only_caches,
append_only_caches={
**complete_pex_environment.append_only_caches,
**append_only_caches,
},
)


Expand Down
4 changes: 4 additions & 0 deletions src/python/pants/backend/python/providers/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

python_sources()
Empty file.
12 changes: 12 additions & 0 deletions src/python/pants/backend/python/providers/pyenv/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

python_sources()
python_tests(
name="tests",
overrides={
"rules_integration_test.py": {
"timeout": 600,
}
},
)
Empty file.
14 changes: 14 additions & 0 deletions src/python/pants/backend/python/providers/pyenv/register.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2023 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).


from pants.backend.python.providers.pyenv.rules import rules as pyenv_rules
from pants.backend.python.providers.pyenv.target_types import PyenvInstall


def target_types():
return [PyenvInstall]


def rules():
return pyenv_rules()
Loading