Skip to content

Commit

Permalink
Drop the --keep-outdated flag and --selective-upgrade flag that have …
Browse files Browse the repository at this point in the history
…been deprecated in favor of update/upgrade commands.
  • Loading branch information
matteius committed Jun 11, 2023
1 parent 9a9ee9c commit 205269c
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 344 deletions.
6 changes: 0 additions & 6 deletions pipenv/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ def install(state, **kwargs):
requirementstxt=state.installstate.requirementstxt,
pre=state.installstate.pre,
deploy=state.installstate.deploy,
keep_outdated=state.installstate.keep_outdated,
selective_upgrade=state.installstate.selective_upgrade,
index_url=state.index,
packages=state.installstate.packages,
editable_packages=state.installstate.editables,
Expand Down Expand Up @@ -321,7 +319,6 @@ def uninstall(ctx, state, all_dev=False, all=False, **kwargs):
lock=not state.installstate.skip_lock,
all_dev=all_dev,
all=all,
keep_outdated=state.installstate.keep_outdated,
pypi_mirror=state.pypi_mirror,
categories=state.installstate.categories,
ctx=ctx,
Expand Down Expand Up @@ -370,7 +367,6 @@ def lock(ctx, state, **kwargs):
state.project,
clear=state.clear,
pre=pre,
keep_outdated=state.installstate.keep_outdated,
pypi_mirror=state.pypi_mirror,
write=not state.quiet,
categories=state.installstate.categories,
Expand Down Expand Up @@ -583,7 +579,6 @@ def update(ctx, state, bare=False, dry_run=None, outdated=False, **kwargs):
clear=state.clear,
pre=state.installstate.pre,
pypi_mirror=state.pypi_mirror,
keep_outdated=state.installstate.keep_outdated,
system=False,
packages=state.installstate.packages,
editable_packages=state.installstate.editables,
Expand Down Expand Up @@ -679,7 +674,6 @@ def sync(ctx, state, bare=False, user=False, unused=False, **kwargs):
dev=state.installstate.dev,
python=state.python,
bare=bare,
dont_upgrade=(not state.installstate.keep_outdated),
user=user,
clear=state.clear,
unused=unused,
Expand Down
58 changes: 0 additions & 58 deletions pipenv/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from pipenv.project import Project
from pipenv.utils.internet import is_valid_url
from pipenv.vendor import click
from pipenv.vendor.click import (
BadArgumentUsage,
BadParameter,
Expand Down Expand Up @@ -77,8 +76,6 @@ class InstallState:
def __init__(self):
self.dev = False
self.pre = False
self.selective_upgrade = False
self.keep_outdated = False
self.skip_lock = False
self.ignore_pipfile = False
self.code = False
Expand Down Expand Up @@ -151,59 +148,6 @@ def callback(ctx, param, value):
)(f)


def keep_outdated_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.installstate.keep_outdated = value
if value:
click.secho(
"The flag --keep-outdated has been deprecated for removal. "
"The flag does not respect package resolver results and leads to inconsistent lock files. "
"Consider using the new `pipenv upgrade` command to selectively upgrade packages.",
fg="yellow",
bold=True,
err=True,
)
return value

return option(
"--keep-outdated",
is_flag=True,
default=False,
expose_value=False,
help="Keep out-dated dependencies from being updated in Pipfile.lock.",
callback=callback,
type=click_types.BOOL,
show_envvar=True,
)(f)


def selective_upgrade_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
state.installstate.selective_upgrade = value
if value:
click.secho(
"The flag --selective-upgrade has been deprecated for removal. "
"The flag is buggy and leads to inconsistent lock files. "
"Consider using the new `pipenv upgrade` command to selectively upgrade packages.",
fg="yellow",
bold=True,
err=True,
)
return value

return option(
"--selective-upgrade",
is_flag=True,
default=False,
type=click_types.BOOL,
help="Update specified packages.",
callback=callback,
expose_value=False,
)(f)


def ignore_pipfile_option(f):
def callback(ctx, param, value):
state = ctx.ensure_object(State)
Expand Down Expand Up @@ -571,7 +515,6 @@ def common_options(f):
def install_base_options(f):
f = common_options(f)
f = pre_option(f)
f = keep_outdated_option(f)
f = extra_pip_args(f)
return f

Expand Down Expand Up @@ -605,7 +548,6 @@ def install_options(f):
f = sync_options(f)
f = index_option(f)
f = requirementstxt_option(f)
f = selective_upgrade_option(f)
f = ignore_pipfile_option(f)
f = editable_option(f)
f = package_arg(f)
Expand Down
74 changes: 4 additions & 70 deletions pipenv/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,8 @@ def marker_to_str(marker):
return marker_str
return None

def get_cleaned_dict(self, keep_outdated=False):
if keep_outdated and self.is_updated:
self.validate_constraints()
self.ensure_least_updates_possible()
elif not keep_outdated:
self.validate_constraints()
def get_cleaned_dict(self):
self.validate_constraints()
if self.entry.extras != self.lockfile_entry.extras:
entry_extras = list(self.entry.extras)
if self.lockfile_entry.extras:
Expand Down Expand Up @@ -626,65 +622,7 @@ def clean_results(results, resolver, project, category):
reverse_deps=reverse_deps,
category=category,
)
entry_dict = translate_markers(entry.get_cleaned_dict(keep_outdated=False))
new_results.append(entry_dict)
return new_results


def clean_outdated(results, resolver, project, category):
from pipenv.utils.dependencies import get_lockfile_section_using_pipfile_category

if not project.lockfile_exists:
return results
lockfile = project.lockfile_content
lockfile_section = get_lockfile_section_using_pipfile_category(category)
reverse_deps = project.environment.reverse_dependencies()
new_results = [r for r in results if r["name"] not in lockfile[lockfile_section]]
for result in results:
name = result.get("name")
entry_dict = result.copy()
entry = Entry(
name,
entry_dict,
project,
resolver,
reverse_deps=reverse_deps,
category=category,
)
# The old entry was editable but this one isnt; prefer the old one
# TODO: Should this be the case for all locking?
if entry.was_editable and not entry.is_editable:
continue
lockfile_entry = lockfile[lockfile_section].get(name, None)
if not lockfile_entry:
if name in lockfile[lockfile_section]:
lockfile_entry = lockfile[lockfile_section][name]
if lockfile_entry and not entry.is_updated:
old_markers = next(
iter(
m
for m in (
entry.lockfile_entry.markers,
lockfile_entry.get("markers", None),
)
if m is not None
),
None,
)
new_markers = entry_dict.get("markers", None)
if old_markers:
old_markers = Entry.marker_to_str(old_markers)
if old_markers and not new_markers:
entry.markers = old_markers
elif new_markers and not old_markers:
del entry.entry_dict["markers"]
entry._entry.req.req.marker = None
entry._entry.markers = None
# if the entry has not changed versions since the previous lock,
# don't introduce new markers since that is more restrictive
# if entry.has_markers and not entry.had_markers and not entry.is_updated:
# do make sure we retain the original markers for entries that are not changed
entry_dict = entry.get_cleaned_dict(keep_outdated=True)
entry_dict = translate_markers(entry.get_cleaned_dict())
new_results.append(entry_dict)
return new_results

Expand Down Expand Up @@ -755,7 +693,6 @@ def resolve(
if pypi_mirror_source
else project.pipfile_sources()
)
keep_outdated = os.environ.get("PIPENV_KEEP_OUTDATED", False)
results, resolver = resolve(
packages,
pre=pre,
Expand All @@ -766,10 +703,7 @@ def resolve(
system=system,
requirements_dir=requirements_dir,
)
if keep_outdated:
results = clean_outdated(results, resolver, project, category)
else:
results = clean_results(results, resolver, project, category)
results = clean_results(results, resolver, project, category)
if write:
with open(write, "w") as fh:
if not results:
Expand Down
8 changes: 3 additions & 5 deletions pipenv/routines/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ def do_clean(
sys.exit(int(failure))


def ensure_lockfile(project, keep_outdated=False, pypi_mirror=None):
def ensure_lockfile(project, pypi_mirror=None):
"""Ensures that the lockfile is up-to-date."""
if not keep_outdated:
keep_outdated = project.settings.get("keep_outdated")
# Write out the lockfile if it doesn't exist, but not if the Pipfile is being ignored
if project.lockfile_exists:
old_hash = project.get_lockfile_hash()
Expand All @@ -80,6 +78,6 @@ def ensure_lockfile(project, keep_outdated=False, pypi_mirror=None):
bold=True,
err=True,
)
do_lock(project, keep_outdated=keep_outdated, pypi_mirror=pypi_mirror)
do_lock(project, pypi_mirror=pypi_mirror)
else:
do_lock(project, keep_outdated=keep_outdated, pypi_mirror=pypi_mirror)
do_lock(project, pypi_mirror=pypi_mirror)
34 changes: 1 addition & 33 deletions pipenv/routines/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from pipenv.patched.pip._internal.exceptions import PipError
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, is_valid_url
from pipenv.utils.pip import (
Expand Down Expand Up @@ -43,8 +42,6 @@ def do_install(
requirementstxt=False,
pre=False,
deploy=False,
keep_outdated=False,
selective_upgrade=False,
site_packages=None,
extra_pip_args=None,
categories=None,
Expand All @@ -53,8 +50,6 @@ def do_install(
suffix="-requirements", prefix="pipenv-"
)
warnings.filterwarnings("default", category=ResourceWarning)
if selective_upgrade:
keep_outdated = True
packages = packages if packages else []
editable_packages = editable_packages if editable_packages else []
package_args = [p for p in packages if p] + [p for p in editable_packages if p]
Expand Down Expand Up @@ -82,8 +77,6 @@ def do_install(
# Load the --pre settings from the Pipfile.
if not pre:
pre = project.settings.get("allow_prereleases")
if not keep_outdated:
keep_outdated = project.settings.get("keep_outdated")
remote = requirementstxt and is_valid_url(requirementstxt)
if "default" in categories:
raise exceptions.PipenvUsageError(
Expand Down Expand Up @@ -166,30 +159,12 @@ def do_install(

# Allow more than one package to be provided.
package_args = [p for p in packages] + [f"-e {pkg}" for pkg in editable_packages]
# Support for --selective-upgrade.
# We should do this part first to make sure that we actually do selectively upgrade
# the items specified
if selective_upgrade:
from pipenv.vendor.requirementslib.models.requirements import Requirement

for i, package in enumerate(package_args[:]):
section = project.packages if not dev else project.dev_packages
package = Requirement.from_line(package)
package__name, package__val = package.pipfile_entry
try:
if not is_star(section[package__name]) and is_star(package__val):
# Support for VCS dependencies.
package_args[i] = convert_deps_to_pip(
{package__name: section[package__name]}, project=project
)[0]
except KeyError:
pass
# Install all dependencies, if none was provided.
# This basically ensures that we have a pipfile and lockfile, then it locks and
# installs from the lockfile
new_packages = []
if not packages and not editable_packages:
# Update project settings with pre preference.
# Update project settings with prerelease preference.
if pre:
project.update_settings({"allow_prereleases": pre})
do_init(
Expand All @@ -203,7 +178,6 @@ def do_install(
pre=pre,
requirements_dir=requirements_directory,
pypi_mirror=pypi_mirror,
keep_outdated=keep_outdated,
extra_pip_args=extra_pip_args,
categories=categories,
)
Expand All @@ -220,7 +194,6 @@ def do_install(
dev=dev,
system=system,
allow_global=system,
keep_outdated=keep_outdated,
requirements_dir=requirements_directory,
deploy=deploy,
pypi_mirror=pypi_mirror,
Expand Down Expand Up @@ -324,7 +297,6 @@ def do_install(
dev=dev,
system=system,
allow_global=system,
keep_outdated=keep_outdated,
requirements_dir=requirements_directory,
deploy=deploy,
pypi_mirror=pypi_mirror,
Expand All @@ -345,7 +317,6 @@ def do_sync(
dev=False,
python=None,
bare=False,
dont_upgrade=False,
user=False,
clear=False,
unused=False,
Expand Down Expand Up @@ -709,7 +680,6 @@ def do_init(
system=False,
deploy=False,
pre=False,
keep_outdated=False,
requirements_dir=None,
pypi_mirror=None,
extra_pip_args=None,
Expand Down Expand Up @@ -775,7 +745,6 @@ def do_init(
project,
system=system,
pre=pre,
keep_outdated=keep_outdated,
write=True,
pypi_mirror=pypi_mirror,
categories=categories,
Expand All @@ -801,7 +770,6 @@ def do_init(
project,
system=system,
pre=pre,
keep_outdated=keep_outdated,
write=True,
pypi_mirror=pypi_mirror,
categories=categories,
Expand Down
Loading

0 comments on commit 205269c

Please sign in to comment.