chore(generator): add pyenv3wrapper script#17483
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new shell script pyenv3wrapper.sh to execute python3 from the user's pyenv directory. The review feedback points out a portability issue on macOS where the getent command is unavailable, and suggests a fallback mechanism using the $HOME environment variable.
| HOME_DIR=$(getent passwd "$(whoami)" | cut -d: -f6) | ||
| exec "$HOME_DIR/.pyenv/shims/python3" "$@" |
There was a problem hiding this comment.
The getent command is not available on macOS by default. Running this script on macOS will result in a command not found error for getent, causing HOME_DIR to be empty and the script to fail when attempting to execute /.pyenv/shims/python3.
To make this script portable across both Linux and macOS, we should first attempt to use the $HOME environment variable, and fallback to getent or shell tilde expansion if $HOME is not set.
| HOME_DIR=$(getent passwd "$(whoami)" | cut -d: -f6) | |
| exec "$HOME_DIR/.pyenv/shims/python3" "$@" | |
| HOME_DIR="${HOME:-$(getent passwd \"$(whoami)\" 2>/dev/null | cut -d: -f6)}" | |
| HOME_DIR="${HOME_DIR:-$(eval echo \"~$(whoami)\")}" | |
| exec "$HOME_DIR/.pyenv/shims/python3" "$@" | |
This file is needed by the bazel build rules.