Skip to content
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

pip index versions should ignore --require-venv #10657

Closed
1 task done
justin-f-perez opened this issue Nov 13, 2021 · 2 comments · Fixed by #11671
Closed
1 task done

pip index versions should ignore --require-venv #10657

justin-f-perez opened this issue Nov 13, 2021 · 2 comments · Fixed by #11671
Labels
type: enhancement Improvements to functionality

Comments

@justin-f-perez
Copy link

justin-f-perez commented Nov 13, 2021

Description

There doesn't seem to be any way to silence pip's warning about experimental commands being removed without prior warning (ironic, haha) and it produces an unexpected error when PIP_REQUIRE_VIRTUALENV is set.

pip index versions <module> outputs an "experimental command" warning when called directly, when called as a python3 module (via -m), when PYTHONWARNINGS=ignore is given, or -Wignore (or both!)

There doesn't seem to be any special flags related to ignoring this particular warning, this feature is not listed among the 3 valid values given by --use-feature error output.

Expected behavior

I expect pip index versions to:

  • respect both the python3 -W option and PYTHONWARNINGS environment variable by:
    • silencing output when given the value 'ignore'
    • raising an error when given the value 'error'
  • not raise an error when PIP_REQUIRE_VIRTUALENV is set (I understand this variable to prevent unintended installation, not all pip commands. This command raising one while pip list does not is unexpected)

pip version

21.3.1

Python version

3.9.7

OS

macOS 11.6.1 20G224

How to Reproduce

  1. install pip- it doesn't seem to matter how you do (I tested against pip in a conda env, via homebrew, and via python3-venv)
  2. set your PYTHONWARNINGS environment variable to ignore warnings
  3. (optional) invoke pip as a python3 module, passing python3 the -Wignore option
  4. invoke pip index versions pip (or any other module)
  5. be warned

Output

$ PYTHONWARNINGS=ignore python3 -Wignore -m pip index versions 'pip'
WARNING: pip index is currently an experimental command. It may be removed/changed in a future release without prior warning.
pip (21.3.1)
Available versions: 21.3.1, 21.3, 21.2.4, 21.2.3, 21.2.2, 21.2.1, 21.1.3, 21.1.2, 21.1.1, 21.1, 21.0.1, 21.0, 20.3.4, 20.3.3, 20.3.1, 20.3, 20.2.4, 20.2.3, 20.2.2, 20.2.1, 20.2, 20.1.1, 20.1, 20.0.2, 20.0.1, 19.3.1, 19.3, 19.2.3, 19.2.2, 19.2.1, 19.2, 19.1.1, 19.1, 19.0.3, 19.0.2, 19.0.1, 19.0, 18.1, 18.0, 10.0.1, 10.0.0, 9.0.3, 9.0.2, 9.0.1, 9.0.0, 8.1.2, 8.1.1, 8.1.0, 8.0.3, 8.0.2, 8.0.1, 8.0.0, 7.1.2, 7.1.1, 7.1.0, 7.0.3, 7.0.2, 7.0.1, 7.0.0, 6.1.1, 6.1.0, 6.0.8, 6.0.7, 6.0.6, 6.0.5, 6.0.4, 6.0.3, 6.0.2, 6.0.1, 6.0, 1.5.6, 1.5.5, 1.5.4, 1.5.3, 1.5.2, 1.5.1, 1.5, 1.4.1, 1.4, 1.3.1, 1.3, 1.2.1, 1.2, 1.1, 1.0.2, 1.0.1, 1.0, 0.8.3, 0.8.2, 0.8.1, 0.8, 0.7.2, 0.7.1, 0.7, 0.6.3, 0.6.2, 0.6.1, 0.6, 0.5.1, 0.5, 0.4, 0.3.1, 0.3, 0.2.1, 0.2
  INSTALLED: 21.3.1
  LATEST:    21.3.1

######
# pip index versions throws a virtualenv error, but pip list does not
######
$ export PIP_REQUIRE_VIRTUALENV=true
$ pip index versions pip
ERROR: Could not find an activated virtualenv (required).

$ pip list
Package    Version
---------- -------
...

#####
# proving these options normally ignore warnings:
#####
$ PYTHONWARNINGS=ignore python3 -c 'import warnings; warnings.warn("cant see me")'

$ python3 -c 'import warnings; warnings.warn("see me")'
<string>:1: UserWarning: see me

#####
# verification of version numbers:
####
$ pip --version
pip 21.3.1 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)
$ python3 -m pip --version
pip 21.3.1 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)
$ pip3 --version
pip 21.3.1 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)

$ python3 --version
Python 3.9.7

$ zsh --version
zsh 5.8 (x86_64-apple-darwin20.0)

$ sw_vers
ProductName:	macOS
ProductVersion:	11.6.1
BuildVersion:	20G224

Code of Conduct

@justin-f-perez justin-f-perez added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels Nov 13, 2021
@justin-f-perez justin-f-perez changed the title pip index versions doesn't ignore respect -W, PYTHONWARNINGS, or PIP_REQUIRE_VIRTUALENV semantics pip index versions doesn't respect -W, PYTHONWARNINGS, or PIP_REQUIRE_VIRTUALENV semantics Nov 13, 2021
@pradyunsg
Copy link
Member

Printing the warning on stderr unconditionally is intentional.

The pip index command as a whole is considered experimental, and is exempt from backwards compatibility promises -- which is what the message states clearly.

As for PIP_REQUIRE_VIRTUALENV, a PR would be welcome setting the appropriate flag on the index command:

ignore_require_venv = True

@pradyunsg pradyunsg added type: enhancement Improvements to functionality and removed type: bug A confirmed bug or unintended behavior S: needs triage Issues/PRs that need to be triaged labels Nov 14, 2021
@pradyunsg pradyunsg changed the title pip index versions doesn't respect -W, PYTHONWARNINGS, or PIP_REQUIRE_VIRTUALENV semantics pip index versions should ignore --require-venv Nov 14, 2021
@justin-f-perez
Copy link
Author

justin-f-perez commented Nov 14, 2021

related (similar) to #8602

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: enhancement Improvements to functionality
Projects
None yet
2 participants