Skip to content
Open
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
18 changes: 8 additions & 10 deletions bootstrap-salt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2731,23 +2731,21 @@ __install_salt_from_repo() {
echodebug "__install_salt_from_repo py_exe=$_py_exe"

_py_version=$(${_py_exe} -c "import sys; print('{0}.{1}'.format(*sys.version_info))")
_pip_cmd="pip${_py_version}"
if ! __check_command_exists "${_pip_cmd}"; then
echodebug "The pip binary '${_pip_cmd}' was not found in PATH"
_pip_cmd="pip$(echo "${_py_version}" | cut -c -1)"
_pip_cmd="${_py_exe} -m pip"
_pip_version="$(${_pip_cmd} --version)"

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.

If pip is not installed, running ${_pip_cmd} --version will dump a No module named pip traceback or command error to stderr. We should silence stderr here so the terminal output stays clean for the user during the check.

_pip_version="$( ${_pip_cmd} --version 2>/dev/null )"

if [ -z "${_pip_version}" ]; then

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.

Relying on string length of the output can occasionally be brittle depending on the shell environment or if python outputs unexpected warnings to stdout. A more robust and idiomatic way to check if the module works is to evaluate the exit code of the command directly.

if ! ${_pip_cmd} --version >/dev/null 2>&1; then

echodebug "Pip is not installed for Python '${_py_exe}' (version ${_py_version})"
_pip_cmd="pip${_py_version}"
if ! __check_command_exists "${_pip_cmd}"; then

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.

Blocker:
This is where the logic breaks completely. If the code falls through to this check (or if the previous block set _pip_cmd="pip${_py_version}"), passing ${_pip_cmd} to __check_command_exists will fail if it contains spaces (like "/usr/bin/python3 -m pip").

__check_command_exists utilizes utilities like which or command -v, which expect a standalone binary executable, not a command string with flags. Passing -m pip will make the function look for a literal binary with spaces/arguments in its name and fail every time.

Since we've already successfully verified the command works if it hits the fallback logic, we should bypass __check_command_exists entirely when using the -m pip syntax, or handle the check explicitly.

Suggested Change:
Instead of trying to mix the two syntax styles in a single variable and routing them through __check_command_exists, refactor the block to separate the python module execution path from the legacy binary fallback path:

    _pip_cmd="${_py_exe} -m pip"
    if ${_pip_cmd} --version >/dev/null 2>&1; then
        _pip_version="$( ${_pip_cmd} --version 2>/dev/null )"
    else
        echodebug "Pip is not installed for Python '${_py_exe}' (version ${_py_version})"
        # Fallback to looking for standard standalone binaries
        _pip_cmd="pip${_py_version}"
        if ! __check_command_exists "${_pip_cmd}"; then
            echodebug "The pip binary '${_pip_cmd}' was not found in PATH"
            echoerror "Unable to find a pip binary"
            return 1
        fi
        _pip_version="$( ${_pip_cmd} --version 2>/dev/null )"
    fi

echodebug "The pip binary '${_pip_cmd}' was not found in PATH"
_pip_cmd="pip"
if ! __check_command_exists "${_pip_cmd}"; then
echoerror "Unable to find a pip binary"
return 1
fi
echoerror "Unable to find a pip binary"
return 1
fi
fi

__check_pip_allowed

echodebug "Installed pip version: $(${_pip_cmd} --version)"
echodebug "Installed pip version: $_pip_version"

_setuptools_dep="setuptools>=${_MINIMUM_SETUPTOOLS_VERSION},<${_MAXIMUM_SETUPTOOLS_VERSION}"
if [ "$_PY_MAJOR_VERSION" -ne 3 ]; then
Expand Down
Loading