Issue 5692 Consider --index argument in update and upgrade commands (#5693)

* Consider index argument in update and upgrade commands.
This commit is contained in:
Matt Davis
2023-05-19 10:00:40 -04:00
committed by GitHub
parent a101d1e7f5
commit 7fd2a9d927
6 changed files with 39 additions and 32 deletions
+1
View File
@@ -0,0 +1 @@
Consider ``--index`` argument in ``update`` and ``upgrade`` commands.
+2
View File
@@ -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,
+3 -18
View File
@@ -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:
+10
View File
@@ -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
+22 -13
View File
@@ -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 = (
+1 -1
View File
@@ -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