Skip to content

Add option to silence warnings related to deprecation of Python versions #6739

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

Merged
merged 12 commits into from
Dec 15, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions news/6673.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add option ``--no-python-version-warning`` to silence warnings
related to deprecation of Python versions.
5 changes: 4 additions & 1 deletion src/pip/_internal/cli/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ def _main(self, args):
user_log_file=options.log,
)

if sys.version_info[:2] == (2, 7):
if (
sys.version_info[:2] == (2, 7) and
not options.no_python_version_warning
):
message = (
"A future version of pip will drop support for Python 2.7. "
"More details about Python 2 support in pip, can be found at "
Expand Down
11 changes: 11 additions & 0 deletions src/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,16 @@ def check_list_path_option(options):
)


no_python_version_warning = partial(
Option,
'--no-python-version-warning',
dest='no_python_version_warning',
action='store_true',
default=False,
help='Silence deprecation warnings for upcoming unsupported Pythons.',
) # type: Callable[..., Option]


##########
# groups #
##########
Expand Down Expand Up @@ -895,6 +905,7 @@ def check_list_path_option(options):
no_cache,
disable_pip_version_check,
no_color,
no_python_version_warning,
]
} # type: Dict[str, Any]

Expand Down
6 changes: 2 additions & 4 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from os.path import curdir, join, pardir

import pytest
from pip._vendor.six import PY2

from pip import __version__ as pip_current_version
from pip._internal import pep425tags
Expand All @@ -28,6 +27,8 @@
pyversion,
pyversion_tuple,
requirements_file,
skip_if_not_python2,
skip_if_python2,
)
from tests.lib.filesystem import make_socket_file
from tests.lib.local_repos import local_checkout
Expand All @@ -39,9 +40,6 @@
server_running,
)

skip_if_python2 = pytest.mark.skipif(PY2, reason="Non-Python 2 only")
skip_if_not_python2 = pytest.mark.skipif(not PY2, reason="Python 2 only")


@pytest.mark.parametrize('command', ('install', 'wheel'))
@pytest.mark.parametrize('variant', ('missing_setuptools', 'bad_setuptools'))
Expand Down
39 changes: 39 additions & 0 deletions tests/functional/test_warning.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import platform
import textwrap

import pytest

from tests.lib import skip_if_not_python2, skip_if_python2


@pytest.fixture
def warnings_demo(tmpdir):
Expand All @@ -28,3 +31,39 @@ def test_deprecation_warnings_can_be_silenced(script, warnings_demo):
script.environ['PYTHONWARNINGS'] = 'ignore'
result = script.run('python', warnings_demo)
assert result.stderr == ''


DEPRECATION_TEXT = "drop support for Python 2.7"
CPYTHON_DEPRECATION_TEXT = "January 1st, 2020"


@skip_if_python2
def test_version_warning_is_not_shown_if_python_version_is_not_2(script):
result = script.pip("debug", allow_stderr_warning=True)
assert DEPRECATION_TEXT not in result.stderr, str(result)
assert CPYTHON_DEPRECATION_TEXT not in result.stderr, str(result)


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


@skip_if_not_python2
def test_version_warning_is_shown_if_python_version_is_2(script):
result = script.pip("debug", allow_stderr_warning=True)
assert DEPRECATION_TEXT in result.stderr, str(result)
if platform.python_implementation() == 'CPython':
assert CPYTHON_DEPRECATION_TEXT in result.stderr, str(result)
else:
assert CPYTHON_DEPRECATION_TEXT not in result.stderr, str(result)


@skip_if_not_python2
def test_version_warning_is_not_shown_when_flag_is_passed(script):
result = script.pip(
"debug", "--no-python-version-warning", allow_stderr_warning=True
)
assert DEPRECATION_TEXT not in result.stderr, str(result)
assert CPYTHON_DEPRECATION_TEXT not in result.stderr, str(result)
assert "--no-python-version-warning" not in result.stderr
5 changes: 5 additions & 0 deletions tests/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from textwrap import dedent

import pytest
from pip._vendor.six import PY2
from scripttest import FoundDir, TestFileEnvironment

from pip._internal.index.collector import LinkCollector
Expand Down Expand Up @@ -1047,3 +1048,7 @@ def need_mercurial(fn):
return pytest.mark.mercurial(need_executable(
'Mercurial', ('hg', 'version')
)(fn))


skip_if_python2 = pytest.mark.skipif(PY2, reason="Non-Python 2 only")
skip_if_not_python2 = pytest.mark.skipif(not PY2, reason="Python 2 only")