@@ -35,16 +35,41 @@ function python_location {
35
35
}
36
36
37
37
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
+
40
62
41
63
" ${VENV_TOOL} " \
42
64
--location " ${VIRTUAL_ENV} " \
43
65
--python " $( python_location) " \
44
- --pth-file " $( rlocation {{ARG_PTH_FILE}}) " \
66
+ --pth-file " ${PTH_FILE} " \
67
+ --pth-entry-prefix " ${PTH_ENTRY_PREFIX} " \
45
68
--collision-strategy " {{ARG_COLLISION_STRATEGY}}" \
46
69
--venv-name " {{ARG_VENV_NAME}}"
47
70
71
+ export VIRTUAL_ENV=" ${RUNFILES_VIRTUAL_ENV} "
72
+
48
73
PATH=" ${VIRTUAL_ENV} /bin:${PATH} "
49
74
export PATH
50
75
0 commit comments