great-art-3505
06/08/2024, 7:31 PMexport
functionality and I came up with this pair of just recipes to create the venv and the include a pth
file with paths that are source roots within the repo and are considered a dependency even at the transitive level:
pants-find-dep-roots +targets:
#!/usr/bin/env python
import subprocess
import pathlib
roots = subprocess.check_output(["pants", "roots"]).decode().split()
tgt_deps = subprocess.check_output(
["pants", "dependencies", "--transitive"] + "{{ targets }}".split()
).decode().split()
used_roots = set()
for root in roots:
for d in tgt_deps:
if d.startswith(root):
used_roots.add(root)
base_dir = pathlib.Path("{{ justfile_directory() }}")
for r in sorted(used_roots):
print(str(base_dir / r))
pants-export-venv-with-dep-roots $resolver +targets:
#!/usr/bin/env bash
set -eu
venv_path=$(pants export --resolve=$resolver | tail -n 1 | awk '{print($NF)}')
pants_roots_pth="$(echo $venv_path/lib/python*/site-packages)/pants-roots.pth"
just pants-find-dep-roots {{ targets }} >> $pants_roots_pth
echo "========================================================"
echo "Virtualenv ready for resolver: $resolver"
echo "With roots:"
cat $pants_roots_pth
echo "========================================================"
echo "Activate with: . $venv_path/bin/activate"
Question: Is there something like this already available in pants or in the form of a plugin? Any opinion against this approach?broad-processor-92400
06/09/2024, 3:52 AMpants export
could do that automatically to avoid needing to configure PYTHONPATH
env var manually.proud-dentist-22844
06/10/2024, 3:59 PMpython_distribution
targets in the resolve.
Assuming you have a python_distribution for each of your source roots, this should do what you want.
https://www.pantsbuild.org/2.21/reference/goals/export#py_editable_in_resolvegreat-art-3505
06/10/2024, 4:05 PMgreat-art-3505
06/10/2024, 4:10 PM