diff --git a/news/6705.feature b/news/6705.feature new file mode 100644 index 00000000000..126c9713d7a --- /dev/null +++ b/news/6705.feature @@ -0,0 +1 @@ +Show deprecation warning against ``--trusted-host`` with port part. diff --git a/src/pip/_internal/cli/cmdoptions.py b/src/pip/_internal/cli/cmdoptions.py index ac41bd99bd4..c748c796544 100644 --- a/src/pip/_internal/cli/cmdoptions.py +++ b/src/pip/_internal/cli/cmdoptions.py @@ -17,12 +17,15 @@ from optparse import SUPPRESS_HELP, Option, OptionGroup from textwrap import dedent +from pip._vendor.six.moves.urllib import parse as urllib_parse + from pip._internal.exceptions import CommandError from pip._internal.locations import USER_CACHE_DIR, src_prefix from pip._internal.models.format_control import FormatControl from pip._internal.models.index import PyPI from pip._internal.models.search_scope import SearchScope from pip._internal.models.target_python import TargetPython +from pip._internal.utils.deprecation import deprecated from pip._internal.utils.hashes import STRONG_HASHES from pip._internal.utils.misc import redact_password_from_url from pip._internal.utils.typing import MYPY_CHECK_RUNNING @@ -378,13 +381,27 @@ def make_search_scope(options, suppress_no_index=False): return search_scope +def _handle_trusted_host(option, opt_str, value, parser): + # type: (Option, str, str, OptionParser) -> None + if urllib_parse.urlparse("//{}/".format(value)).port: + deprecated( + "--trusted-host no longer needs port part with it.", + replacement=None, + gone_in=None, + issue=6705 + ) + parser.values.trusted_hosts.append(value) + + def trusted_host(): # type: () -> Option return Option( "--trusted-host", dest="trusted_hosts", - action="append", metavar="HOSTNAME", + type="string", + action="callback", + callback=_handle_trusted_host, default=[], help="Mark this host as trusted, even though it does not have valid " "or any HTTPS.",