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

wip: venv temp #427

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 28 additions & 3 deletions py/private/run.tmpl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,41 @@ function python_location {
}

VENV_TOOL="$(rlocation {{VENV_TOOL}})"
VIRTUAL_ENV="$(alocation "${RUNFILES_DIR}/{{ARG_VENV_NAME}}")"
export VIRTUAL_ENV

RUNFILES_VIRTUAL_ENV="$(alocation "${RUNFILES_DIR}/{{ARG_VENV_NAME}}")"
VIRTUAL_ENV="${RUNFILES_VIRTUAL_ENV}"

PTH_ENTRY_PREFIX=""
PTH_FILE="$(rlocation {{ARG_PTH_FILE}})"

if [[ -n "${VENV_PATH:-}" ]]; then
VIRTUAL_ENV="${VENV_PATH}"
# Remove preexisting runfiles virtualenv symlink if it exists
rm -rf "${RUNFILES_VIRTUAL_ENV}" > /dev/null || true
# Create a symlink to the virtualenv in the runfiles dir
ln -s "${VIRTUAL_ENV}" "${RUNFILES_VIRTUAL_ENV}"

# We need to rewrite the pth file to be relative to the runfiles dir
PTH="$(cat "${PTH_FILE}")"
PTH="${PTH//"${VENV_PTH_STRIP}"/.}"
PTH_FILE="$(mktemp)"
echo "${PTH}" > "${PTH_FILE}"

# And set the pth entry prefix to the runfiles dir
PTH_ENTRY_PREFIX="${RUNFILES_DIR}"
fi


"${VENV_TOOL}" \
--location "${VIRTUAL_ENV}" \
--python "$(python_location)" \
--pth-file "$(rlocation {{ARG_PTH_FILE}})" \
--pth-file "${PTH_FILE}"\
--pth-entry-prefix "${PTH_ENTRY_PREFIX}" \
--collision-strategy "{{ARG_COLLISION_STRATEGY}}" \
--venv-name "{{ARG_VENV_NAME}}"

export VIRTUAL_ENV="${RUNFILES_VIRTUAL_ENV}"

PATH="${VIRTUAL_ENV}/bin:${PATH}"
export PATH

Expand Down
2 changes: 2 additions & 0 deletions py/tools/py/src/pth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ impl PthFile {
line.clear();

match entry.file_name() {

Some(name) if name == "site-packages" => {
println!("{:#?}", dest.join(entry.clone()));
let src_dir = dest
.join(entry)
.canonicalize()
Expand Down
Loading