Skip to content

Commit

Permalink
wip: venv temp
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayyn committed Oct 30, 2024
1 parent ca62068 commit 74c2e3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 18 additions & 3 deletions py/private/run.tmpl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,31 @@ 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}}")"

TMP_VENV=$(mktemp -d -t venv.XXXXXX)
VIRTUAL_ENV="$TMP_VENV/{{ARG_VENV_NAME}}"
mkdir -p "${VIRTUAL_ENV}"

# Remove preexisting runfiles virtualenv symlink if it exists
rm "${RUNFILES_VIRTUAL_ENV}" || 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 "$(rlocation {{ARG_PTH_FILE}})")"
PTH="${PTH//..\/..\/..\/../.}"

"${VENV_TOOL}" \
--location "${VIRTUAL_ENV}" \
--python "$(python_location)" \
--pth-file "$(rlocation {{ARG_PTH_FILE}})" \
--pth-file <(echo "$PTH") \
--pth-entry-prefix "${RUNFILES_DIR}" \
--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

0 comments on commit 74c2e3a

Please sign in to comment.