Skip to content

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

@justin-f-perez

Description

@justin-f-perez

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions