Skip to content

Commit 1ebb18f

Browse files
committed
wip: venv temp
1 parent ca62068 commit 1ebb18f

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

py/private/run.tmpl.sh

+28-3
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,41 @@ function python_location {
3535
}
3636

3737
VENV_TOOL="$(rlocation {{VENV_TOOL}})"
38-
VIRTUAL_ENV="$(alocation "${RUNFILES_DIR}/{{ARG_VENV_NAME}}")"
39-
export VIRTUAL_ENV
38+
39+
RUNFILES_VIRTUAL_ENV="$(alocation "${RUNFILES_DIR}/{{ARG_VENV_NAME}}")"
40+
VIRTUAL_ENV="${RUNFILES_VIRTUAL_ENV}"
41+
42+
PTH_ENTRY_PREFIX=""
43+
PTH_FILE="$(rlocation {{ARG_PTH_FILE}})"
44+
45+
if [[ -n "${VENV_PATH:-}" ]]; then
46+
VIRTUAL_ENV="${VENV_PATH}"
47+
# Remove preexisting runfiles virtualenv symlink if it exists
48+
rm -rf "${RUNFILES_VIRTUAL_ENV}" > /dev/null || true
49+
# Create a symlink to the virtualenv in the runfiles dir
50+
ln -s "${VIRTUAL_ENV}" "${RUNFILES_VIRTUAL_ENV}"
51+
52+
# We need to rewrite the pth file to be relative to the runfiles dir
53+
PTH="$(cat "${PTH_FILE}")"
54+
PTH="${PTH//"${VENV_PTH_STRIP}"/.}"
55+
PTH_FILE="$(mktemp)"
56+
echo "${PTH}" > "${PTH_FILE}"
57+
58+
# And set the pth entry prefix to the runfiles dir
59+
PTH_ENTRY_PREFIX="${RUNFILES_DIR}"
60+
fi
61+
4062

4163
"${VENV_TOOL}" \
4264
--location "${VIRTUAL_ENV}" \
4365
--python "$(python_location)" \
44-
--pth-file "$(rlocation {{ARG_PTH_FILE}})" \
66+
--pth-file "${PTH_FILE}"\
67+
--pth-entry-prefix "${PTH_ENTRY_PREFIX}" \
4568
--collision-strategy "{{ARG_COLLISION_STRATEGY}}" \
4669
--venv-name "{{ARG_VENV_NAME}}"
4770

71+
export VIRTUAL_ENV="${RUNFILES_VIRTUAL_ENV}"
72+
4873
PATH="${VIRTUAL_ENV}/bin:${PATH}"
4974
export PATH
5075

py/tools/py/src/pth.rs

+2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ impl PthFile {
6666
line.clear();
6767

6868
match entry.file_name() {
69+
6970
Some(name) if name == "site-packages" => {
71+
println!("{:#?}", dest.join(entry.clone()));
7072
let src_dir = dest
7173
.join(entry)
7274
.canonicalize()

0 commit comments

Comments
 (0)