Skip to content

Commit

Permalink
refactor(internal): adjust pants_venv venv_dir calculation (#19140)
Browse files Browse the repository at this point in the history
The "uname -mps" output on my machine includes odd chars and is really
long:
```
Linux x86_64 Intel(R) Core(TM) i7-3610QM CPU @ 2.30GHz
```

As of #18916, the entire python version is a fingerprint instead of 2
chars "39". The longer fingerprint plus my excessively long processor
name trips over the shebang max length (127 chars).

Once the python interpreter becomes longer than the shebang max length,
that triggers distlib's long shebang logic (which writes the shebangs
for scripts like `pip` in the `venv/bin` dir), But, that distlib logic
breaks with the special uname chars on my machine because distlib does
not escape the special chars in the path.
https://github.com/pypa/distlib/blob/0.3.6/distlib/scripts.py#L152-L157

So, this bypasses the whole mess by generating one fingerprint for uname
+ python version and then use that fingerprint (which doesn't have any
special chars) in the venv dir name.
  • Loading branch information
cognifloyd authored May 25, 2023
1 parent f6100e1 commit a168b39
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions build-support/pants_venv
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ REQUIREMENTS=(
"${REPO_ROOT}/3rdparty/python/requirements.txt"
)

# NB: We house these outside the working copy to avoid needing to gitignore them, but also to
# dodge https://github.com/hashicorp/vagrant/issues/12057.
platform=$(uname -mps | sed 's/ /./g')
venv_dir_prefix="${HOME}/.cache/pants/pants_dev_deps/${platform}"
platform=$(uname -mps)

function venv_dir() {
# Include the entire version string in order to differentiate e.g. PyPy from CPython.
py_venv_version=$(${PY} --version | fingerprint_data)
echo "${venv_dir_prefix}.py.${py_venv_version}.venv"
# Fingerprinting uname and python output avoids shebang length limits and any odd chars.
venv_fingerprint=$( (
echo "${platform}"
${PY} --version
) | fingerprint_data)

# NB: We house these outside the working copy to avoid needing to gitignore them, but also to
# dodge https://github.com/hashicorp/vagrant/issues/12057.
echo "${HOME}/.cache/pants/pants_dev_deps/${venv_fingerprint}.venv"
}

function activate_venv() {
Expand Down

0 comments on commit a168b39

Please sign in to comment.