Skip to content

Commit

Permalink
Adds --upgrade-recursive option, makes -U non-recursive by default.
Browse files Browse the repository at this point in the history
fixes pypa#304
  • Loading branch information
fdintino committed Jun 8, 2012
1 parent 8d92fc2 commit 8a38346
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
9 changes: 8 additions & 1 deletion pip/commands/install.py
Expand Up @@ -114,6 +114,12 @@ def __init__(self):
dest='upgrade',
action='store_true',
help='Upgrade all packages to the newest available version')
self.parser.add_option(
'-R', '--upgrade-recursive',
dest='upgrade_recursive',
action='store_true',
help='Upgrade package to the newest available version, recursing '
'into its dependencies')
self.parser.add_option(
'--force-reinstall',
dest='force_reinstall',
Expand Down Expand Up @@ -213,7 +219,8 @@ def run(self, options, args):
src_dir=options.src_dir,
download_dir=options.download_dir,
download_cache=options.download_cache,
upgrade=options.upgrade,
upgrade=options.upgrade or options.upgrade_recursive,
upgrade_recursive=options.upgrade_recursive,
as_egg=options.as_egg,
ignore_installed=options.ignore_installed,
ignore_dependencies=options.ignore_dependencies,
Expand Down
24 changes: 17 additions & 7 deletions pip/req.py
Expand Up @@ -797,13 +797,14 @@ def __repr__(self):
class RequirementSet(object):

def __init__(self, build_dir, src_dir, download_dir, download_cache=None,
upgrade=False, ignore_installed=False, as_egg=False,
ignore_dependencies=False, force_reinstall=False):
ignore_installed=False, as_egg=False, force_reinstall=False,
ignore_dependencies=False, upgrade=False, upgrade_recursive=False):
self.build_dir = build_dir
self.src_dir = src_dir
self.download_dir = download_dir
self.download_cache = download_cache
self.upgrade = upgrade
self.orig_upgrade = self.upgrade = upgrade or upgrade_recursive
self.upgrade_recursive = upgrade_recursive
self.ignore_installed = ignore_installed
self.force_reinstall = force_reinstall
self.requirements = Requirements()
Expand Down Expand Up @@ -901,9 +902,13 @@ def locate_files(self):
else:
install_needed = False
if req_to_install.satisfied_by:
if self.orig_upgrade and not self.upgrade:
upgrade_cmd = '--upgrade-recursive'
else:
upgrade_cmd = '--upgrade'
logger.notify('Requirement already satisfied '
'(use --upgrade to upgrade): %s'
% req_to_install)
'(use %s to upgrade): %s'
% (upgrade_cmd, req_to_install))

if req_to_install.editable:
if req_to_install.source_dir is None:
Expand Down Expand Up @@ -957,9 +962,13 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
logger.notify('Requirement already up-to-date: %s'
% req_to_install)
else:
if self.orig_upgrade and not self.upgrade:
upgrade_cmd = '--upgrade-recursive'
else:
upgrade_cmd = '--upgrade'
logger.notify('Requirement already satisfied '
'(use --upgrade to upgrade): %s'
% req_to_install)
'(use %s to upgrade): %s'
% (upgrade_cmd, req_to_install))
if req_to_install.editable:
logger.notify('Obtaining %s' % req_to_install)
elif install:
Expand Down Expand Up @@ -1055,6 +1064,7 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
if (req_to_install.extras):
logger.notify("Installing extra requirements: %r" % ','.join(req_to_install.extras))
if not self.ignore_dependencies:
self.upgrade = self.upgrade_recursive

This comment has been minimized.

Copy link
@qwcode

qwcode Jul 2, 2012

'-U' can be added when installing from a requirements file.
supposing the default case of self.upgrade_recursive=False, and that the first item in the requirements file has dependencies,
wouldn't setting self.upgrade here in this loop prevent all but the first top-level requirement from being upgraded?

I think each InstallRequirement will need to have an upgrade property that the logic works off of to keep this straight.

for req in req_to_install.requirements(req_to_install.extras):
try:
name = pkg_resources.Requirement.parse(req).project_name
Expand Down

1 comment on commit 8a38346

@joshmaker
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patch works great for me. I hope this gets pulled in soon, the bug with --upgrade is a big headache for our workflow.

Please sign in to comment.