Skip to content

Commit

Permalink
Issue 5692 Consider --index argument in update and upgrade commands (#…
Browse files Browse the repository at this point in the history
…5693)

* Consider index argument in update and upgrade commands.
  • Loading branch information
matteius authored May 19, 2023
1 parent a101d1e commit 7fd2a9d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 32 deletions.
1 change: 1 addition & 0 deletions news/5692.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Consider ``--index`` argument in ``update`` and ``upgrade`` commands.
2 changes: 2 additions & 0 deletions pipenv/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 3 additions & 18 deletions pipenv/routines/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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,
Expand All @@ -21,7 +21,7 @@
)
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
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions pipenv/routines/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
)
Expand All @@ -107,6 +110,7 @@ def upgrade(
packages=None,
editable_packages=None,
pypi_mirror=None,
index_url=None,
categories=None,
dev=False,
lock_only=False,
Expand All @@ -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
Expand Down
35 changes: 22 additions & 13 deletions pipenv/utils/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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):
Expand Down Expand Up @@ -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 = (
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7fd2a9d

Please sign in to comment.