From 7fd2a9d9271f18bbf0323e69c596be6967c95791 Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Fri, 19 May 2023 10:00:40 -0400 Subject: [PATCH] Issue 5692 Consider --index argument in update and upgrade commands (#5693) * Consider index argument in update and upgrade commands. --- news/5692.bugfix.rst | 1 + pipenv/cli/command.py | 2 ++ pipenv/routines/install.py | 21 +++------------------ pipenv/routines/update.py | 10 ++++++++++ pipenv/utils/requirements.py | 35 ++++++++++++++++++++++------------- pyproject.toml | 2 +- 6 files changed, 39 insertions(+), 32 deletions(-) create mode 100644 news/5692.bugfix.rst diff --git a/news/5692.bugfix.rst b/news/5692.bugfix.rst new file mode 100644 index 00000000..2ec3a11a --- /dev/null +++ b/news/5692.bugfix.rst @@ -0,0 +1 @@ +Consider ``--index`` argument in ``update`` and ``upgrade`` commands. diff --git a/pipenv/cli/command.py b/pipenv/cli/command.py index e532e7d9..c6b384e2 100644 --- a/pipenv/cli/command.py +++ b/pipenv/cli/command.py @@ -282,6 +282,7 @@ def upgrade(state, **kwargs): packages=state.installstate.packages, editable_packages=state.installstate.editables, categories=state.installstate.categories, + index_url=state.index, dev=state.installstate.dev, system=state.system, lock_only=state.installstate.lock_only, @@ -590,6 +591,7 @@ def update(ctx, state, bare=False, dry_run=None, outdated=False, **kwargs): bare=bare, extra_pip_args=state.installstate.extra_pip_args, categories=state.installstate.categories, + index_url=state.index, quiet=state.quiet, dry_run=dry_run, outdated=outdated, diff --git a/pipenv/routines/install.py b/pipenv/routines/install.py index 4b8b2bf8..f33749bc 100644 --- a/pipenv/routines/install.py +++ b/pipenv/routines/install.py @@ -11,7 +11,7 @@ from pipenv.patched.pip._vendor import rich from pipenv.routines.lock import do_lock from pipenv.utils.dependencies import convert_deps_to_pip, is_star from pipenv.utils.indexes import get_source_list -from pipenv.utils.internet import download_file, get_host_and_port, is_valid_url +from pipenv.utils.internet import download_file, is_valid_url from pipenv.utils.pip import ( format_pip_error, format_pip_output, @@ -21,7 +21,7 @@ from pipenv.utils.pip import ( ) from pipenv.utils.pipfile import ensure_pipfile from pipenv.utils.project import ensure_project -from pipenv.utils.requirements import import_requirements +from pipenv.utils.requirements import add_index_to_pipfile, import_requirements from pipenv.utils.virtualenv import cleanup_virtualenv, do_create_virtualenv from pipenv.vendor import click from pipenv.vendor.requirementslib import fileutils @@ -338,22 +338,7 @@ def do_install( ) # Add the package to the Pipfile. if index_url: - trusted_hosts = get_trusted_hosts() - host_and_port = get_host_and_port(index_url) - require_valid_https = not any( - ( - v in trusted_hosts - for v in ( - host_and_port, - host_and_port.partition(":")[ - 0 - ], # also check if hostname without port is in trusted_hosts - ) - ) - ) - index_name = project.add_index_to_pipfile( - index_url, verify_ssl=require_valid_https - ) + index_name = add_index_to_pipfile(project, index_url) pkg_requirement.index = index_name try: if categories: diff --git a/pipenv/routines/update.py b/pipenv/routines/update.py index eddd4de6..60d56e71 100644 --- a/pipenv/routines/update.py +++ b/pipenv/routines/update.py @@ -10,6 +10,7 @@ from pipenv.utils.dependencies import ( pep423_name, ) from pipenv.utils.project import ensure_project +from pipenv.utils.requirements import add_index_to_pipfile from pipenv.utils.resolver import venv_resolve_deps from pipenv.vendor import click from pipenv.vendor.requirementslib.models.requirements import Requirement @@ -26,6 +27,7 @@ def do_update( pypi_mirror=None, dev=False, categories=None, + index_url=None, extra_pip_args=None, quiet=False, bare=False, @@ -81,6 +83,7 @@ def do_update( editable_packages=editable, pypi_mirror=pypi_mirror, categories=categories, + index_url=index_url, dev=dev, lock_only=lock_only, ) @@ -107,6 +110,7 @@ def upgrade( packages=None, editable_packages=None, pypi_mirror=None, + index_url=None, categories=None, dev=False, lock_only=False, @@ -121,12 +125,18 @@ def upgrade( package_args = [p for p in packages] + [f"-e {pkg}" for pkg in editable_packages] + index_name = None + if index_url: + index_name = add_index_to_pipfile(project, index_url) + reqs = {} requested_packages = {} for package in package_args[:]: # section = project.packages if not dev else project.dev_packages section = {} package = Requirement.from_line(package) + if index_name: + package.index = index_name package_name, package_val = package.pipfile_entry package_name = pep423_name(package_name) requested_packages[package_name] = package diff --git a/pipenv/utils/requirements.py b/pipenv/utils/requirements.py index a4ef7466..97f35cb0 100644 --- a/pipenv/utils/requirements.py +++ b/pipenv/utils/requirements.py @@ -9,6 +9,7 @@ from pipenv.patched.pip._internal.req.constructors import ( from pipenv.patched.pip._internal.utils.misc import split_auth_from_netloc from pipenv.utils.indexes import parse_indexes from pipenv.utils.internet import get_host_and_port +from pipenv.utils.pip import get_trusted_hosts def import_requirements(project, r=None, dev=False): @@ -59,21 +60,29 @@ def import_requirements(project, r=None, dev=False): else: project.add_package_to_pipfile(str(package.req), dev=dev) for index in indexes: - # don't require HTTPS for trusted hosts (see: https://pip.pypa.io/en/stable/cli/pip/#cmdoption-trusted-host) - host_and_port = get_host_and_port(index) - require_valid_https = not any( - ( - v in trusted_hosts - for v in ( - host_and_port, - host_and_port.partition(":")[ - 0 - ], # also check if hostname without port is in trusted_hosts - ) + add_index_to_pipfile(project, index, trusted_hosts) + project.recase_pipfile() + + +def add_index_to_pipfile(project, index, trusted_hosts=None): + # don't require HTTPS for trusted hosts (see: https://pip.pypa.io/en/stable/cli/pip/#cmdoption-trusted-host) + if trusted_hosts is None: + trusted_hosts = get_trusted_hosts() + + host_and_port = get_host_and_port(index) + require_valid_https = not any( + ( + v in trusted_hosts + for v in ( + host_and_port, + host_and_port.partition(":")[ + 0 + ], # also check if hostname without port is in trusted_hosts ) ) - project.add_index_to_pipfile(index, verify_ssl=require_valid_https) - project.recase_pipfile() + ) + index_name = project.add_index_to_pipfile(index, verify_ssl=require_valid_https) + return index_name BAD_PACKAGES = ( diff --git a/pyproject.toml b/pyproject.toml index 44a5ea14..4fdcd732 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -124,7 +124,7 @@ target-version = "py37" max-complexity = 32 [tool.ruff.pylint] -max-args = 18 +max-args = 20 max-branches = 38 max-returns = 9 max-statements = 155