Skip to content
Merged
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
4 changes: 4 additions & 0 deletions packages/gapic-generator/pyenv3wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

HOME_DIR=$(getent passwd "$(whoami)" | cut -d: -f6)
exec "$HOME_DIR/.pyenv/shims/python3" "$@"
Comment on lines +3 to +4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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" "$@"

Loading