Skip to content

Commit

Permalink
Merge pull request #9779 from pfmoore/workaround_9540
Browse files Browse the repository at this point in the history
Make pip work with warnings converted to errors
  • Loading branch information
pfmoore authored Apr 6, 2021
2 parents 3679947 + 8d6870a commit a64ab1a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions news/9779.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix pip to work with warnings converted to errors.
11 changes: 9 additions & 2 deletions src/pip/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import warnings

# Remove '' and current working directory from the first entry
# of sys.path, if present to avoid using current directory
Expand All @@ -18,7 +19,13 @@
path = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, path)

from pip._internal.cli.main import main as _main

if __name__ == "__main__":
# Work around the error reported in #9540, pending a proper fix.
# Note: It is essential the warning filter is set *before* importing
# pip, as the deprecation happens at import time, not runtime.
warnings.filterwarnings(
"ignore", category=DeprecationWarning, module=".*packaging\\.version"
)
from pip._internal.cli.main import main as _main

sys.exit(_main())
5 changes: 5 additions & 0 deletions tests/functional/test_warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,8 @@ def test_version_warning_is_not_shown_if_python_version_is_not_2(script):

def test_flag_does_nothing_if_python_version_is_not_2(script):
script.pip("list", "--no-python-version-warning")


def test_pip_works_with_warnings_as_errors(script):
script.environ['PYTHONWARNINGS'] = 'error'
script.pip("--version")

0 comments on commit a64ab1a

Please sign in to comment.