-
Notifications
You must be signed in to change notification settings - Fork 128
Suppress pip root user warning by conditionally skipping ensurepip in installer scripts #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR addresses pip root user warnings by introducing conditional logic to skip ensurepip when pip is already present. The solution checks for a pip directory in site-packages before attempting to install pip.
Key changes:
- Added pip presence detection logic using Python's
site.getsitepackages()method - Conditional execution of
ensurepiponly when pip directory is not found - Maintained existing
PIP_ROOT_USER_ACTION=ignoreenvironment variable
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ./python -m pip install --upgrade --force-reinstall pip --disable-pip-version-check --no-warn-script-location | ||
|
|
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After conditionally skipping ensurepip, the script still runs pip install --upgrade --force-reinstall pip. This creates a logical inconsistency: if pip already exists (ensurepip skipped), the force-reinstall makes the skip pointless. If pip doesn't exist (ensurepip runs), the upgrade is redundant since ensurepip just installed pip. Additionally, if ensurepip was skipped because pip was detected but pip is broken or incomplete, this line may fail.
Consider verifying pip is functional after the conditional ensurepip step, or reconsider the logic flow to ensure pip is properly available before attempting to upgrade it.
| ./python -m pip install --upgrade --force-reinstall pip --disable-pip-version-check --no-warn-script-location | |
| # Verify pip is functional before attempting to upgrade | |
| if ./python -m pip --version >/dev/null 2>&1; then | |
| ./python -m pip install --upgrade --force-reinstall pip --disable-pip-version-check --no-warn-script-location | |
| else | |
| echo "Error: pip is not functional after ensurepip. Aborting pip upgrade." | |
| exit 1 | |
| fi |
| export PIP_ROOT_USER_ACTION=ignore | ||
| ./python -m ensurepip | ||
|
|
||
| if [ -d "$(./python -c 'import site; print(site.getsitepackages()[0])')/pip" ]; then |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pip directory check uses command substitution without proper error handling. If the Python command fails (e.g., site module not available, or getsitepackages() returns an empty list), the script will continue with potentially incorrect behavior due to set -e being active. The command should be wrapped with error handling or the result should be validated.
Consider using a safer approach:
SITE_PACKAGES=$(./python -c 'import site; print(site.getsitepackages()[0])' 2>/dev/null) || SITE_PACKAGES=""
if [ -n "$SITE_PACKAGES" ] && [ -d "$SITE_PACKAGES/pip" ]; then
echo "pip directory found in site-packages, skipping ensurepip."
else
echo "pip directory not found, running ensurepip..."
./python -m ensurepip
fi| if [ -d "$(./python -c 'import site; print(site.getsitepackages()[0])')/pip" ]; then | |
| SITE_PACKAGES=$(./python -c 'import site; s=site.getsitepackages(); print(s[0] if s else "")' 2>/dev/null) || SITE_PACKAGES="" | |
| if [ -n "$SITE_PACKAGES" ] && [ -d "$SITE_PACKAGES/pip" ]; then |
Description
Resolution for the pip root user warnings.