From 24a0d40fe9e1c9bd2b25dd37489dda4d497cdeaa Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Mon, 12 Dec 2022 10:40:12 +0100 Subject: [PATCH 1/2] Clean up all symlinks in venv --- py/private/venv/venv.tmpl.sh | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/py/private/venv/venv.tmpl.sh b/py/private/venv/venv.tmpl.sh index 3fd98a31..04548209 100644 --- a/py/private/venv/venv.tmpl.sh +++ b/py/private/venv/venv.tmpl.sh @@ -9,19 +9,8 @@ fi set -o errexit -o nounset -o pipefail -PWD=$(pwd) - export BAZEL_WORKSPACE_NAME="{{BAZEL_WORKSPACE_NAME}}" -function alocation { - local P=$1 - if [[ "${P:0:1}" == "/" ]]; then - echo "${P}" - else - echo "${PWD}/${P}" - fi -} - function maybe_rlocation() { local P=$1 if [ "$USE_MANIFEST_PATH" = false ]; then @@ -73,21 +62,14 @@ export VIRTUAL_ENV_DISABLE_PROMPT=1 . "${VBIN_LOCATION}/activate" unset VIRTUAL_ENV_DISABLE_PROMPT -# Need to keep track of symlinks created inside the venv that are from outside and remove them after. -# Bazel will fail to validate the tree artifact created otherwise. -VENV_BIN_SYMLINKS=$(find "${VBIN_LOCATION}" -type l) -SYMLINKS=(${VENV_BIN_SYMLINKS}) - # Now symlink in pip from the toolchain # Python venv will also link `pip3.x`, but this seems unnecessary for this use ln -snf "${PIP_LOCATION}" "${VPIP_LOCATION}" -SYMLINKS+=("${VPIP_LOCATION}") # Need to symlink in the pip site-packages folder not just the binary. # Ask Python where the site-packages folder is and symlink the pip package in from the toolchain VENV_SITE_PACKAGES=$(${VPYTHON} -c 'import site; print(site.getsitepackages()[0])') ln -snf "${PYTHON_SITE_PACKAGES}/pip" "${VENV_SITE_PACKAGES}/pip" -SYMLINKS+=("${VENV_SITE_PACKAGES}/pip") # If the incoming requirements file has setuptools the skip creating a symlink to our own as they will cause # error when installing. @@ -98,10 +80,8 @@ set -o errexit if [ ${HAS_SETUPTOOLS} -gt 0 ]; then ln -snf "${PYTHON_SITE_PACKAGES}/_distutils_hack" "${VENV_SITE_PACKAGES}/_distutils_hack" - SYMLINKS+=( "${VENV_SITE_PACKAGES}/_distutils_hack") ln -snf "${PYTHON_SITE_PACKAGES}/setuptools" "${VENV_SITE_PACKAGES}/setuptools" - SYMLINKS+=( "${VENV_SITE_PACKAGES}/setuptools") fi INSTALL_WHEELS={{INSTALL_WHEELS}} @@ -144,9 +124,10 @@ PYVENV_CFG="${VENV_LOCATION}/pyvenv.cfg" rm "${PYVENV_CFG}" if [ "$USE_MANIFEST_PATH" = false ]; then - # Tear down the symlinks created above as these won't be able to be resolved by bazel when validating the TreeArtifact - for symlink in "${SYMLINKS[@]}"; do - rm "${symlink}" + # Tear down the symlinks created above as these won't be able to be resolved by bazel when validating the TreeArtifact. + VENV_SYMLINKS=($(find "${VENV_LOCATION}" -type l)) + for symlink in "${VENV_SYMLINKS[@]}"; do + rm "${symlink}" done fi @@ -168,4 +149,4 @@ if [ "$USE_MANIFEST_PATH" = true ]; then chmod +x "${VBIN_LOCATION}/activate" chmod +x "${VBIN_LOCATION}/activate.csh" chmod +x "${VBIN_LOCATION}/activate.fish" -fi \ No newline at end of file +fi From b244a12457a4df85088cc39e70088e256c1be1fe Mon Sep 17 00:00:00 2001 From: Milan Vukov Date: Mon, 12 Dec 2022 11:08:58 +0100 Subject: [PATCH 2/2] Simplify symlink cleanup --- py/private/venv/venv.tmpl.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/py/private/venv/venv.tmpl.sh b/py/private/venv/venv.tmpl.sh index 04548209..88b2727d 100644 --- a/py/private/venv/venv.tmpl.sh +++ b/py/private/venv/venv.tmpl.sh @@ -125,10 +125,7 @@ rm "${PYVENV_CFG}" if [ "$USE_MANIFEST_PATH" = false ]; then # Tear down the symlinks created above as these won't be able to be resolved by bazel when validating the TreeArtifact. - VENV_SYMLINKS=($(find "${VENV_LOCATION}" -type l)) - for symlink in "${VENV_SYMLINKS[@]}"; do - rm "${symlink}" - done + find "${VENV_LOCATION}" -type l -exec rm {} + fi if [ "$USE_MANIFEST_PATH" = true ]; then