Permalink
Browse files

example using InstallRequirement.upgrade property

  • Loading branch information...
qwcode committed Jul 12, 2012
1 parent c6789f6 commit 99a89279731cb97f4016b8238f1f2bd7ef96bb0b
Showing with 27 additions and 19 deletions.
  1. +10 −4 pip/commands/install.py
  2. +17 −15 pip/req.py
View
@@ -113,7 +113,12 @@ def __init__(self):
'-U', '--upgrade',
dest='upgrade',
action='store_true',
- help='Upgrade all packages to the newest available version')
+ help='Upgrade packages to the latest version, but not dependencies')
+ self.parser.add_option(
+ '-R', '--upgrade-recursive',
+ dest='upgrade_recursive',
+ action='store_true',
+ help='Upgrade packages to the latest version, including dependencies')
self.parser.add_option(
'--force-reinstall',
dest='force_reinstall',
@@ -213,18 +218,19 @@ def run(self, options, args):
src_dir=options.src_dir,
download_dir=options.download_dir,
download_cache=options.download_cache,
- upgrade=options.upgrade,
+ upgrade_recursive=options.upgrade_recursive,
as_egg=options.as_egg,
ignore_installed=options.ignore_installed,
ignore_dependencies=options.ignore_dependencies,
force_reinstall=options.force_reinstall,
use_user_site=options.use_user_site)
+ upgrade = options.upgrade or options.upgrade_recursive
for name in args:
requirement_set.add_requirement(
- InstallRequirement.from_line(name, None))
+ InstallRequirement.from_line(name, None, upgrade=upgrade))
for name in options.editables:
requirement_set.add_requirement(
- InstallRequirement.from_editable(name, default_vcs=options.default_vcs))
+ InstallRequirement.from_editable(name, default_vcs=options.default_vcs, upgrade=upgrade))
for filename in options.requirements:
for req in parse_requirements(filename, finder=finder, options=options):
requirement_set.add_requirement(req)
View
@@ -36,7 +36,7 @@
class InstallRequirement(object):
def __init__(self, req, comes_from, source_dir=None, editable=False,
- url=None, as_egg=False, update=True):
+ url=None, as_egg=False, update=True, upgrade=False):
self.extras = ()
if isinstance(req, string_types):
req = pkg_resources.Requirement.parse(req)
@@ -63,24 +63,25 @@ def __init__(self, req, comes_from, source_dir=None, editable=False,
# UninstallPathSet of uninstalled distribution (for possible rollback)
self.uninstalled = None
self.use_user_site = False
+ self.upgrade=upgrade
@classmethod
- def from_editable(cls, editable_req, comes_from=None, default_vcs=None):
+ def from_editable(cls, editable_req, comes_from=None, default_vcs=None, upgrade=False):
name, url, extras_override = parse_editable(editable_req, default_vcs)
if url.startswith('file:'):
source_dir = url_to_path(url)
else:
source_dir = None
- res = cls(name, comes_from, source_dir=source_dir, editable=True, url=url)
+ res = cls(name, comes_from, source_dir=source_dir, editable=True, url=url, upgrade=upgrade)
if extras_override is not None:
res.extras = extras_override
return res
@classmethod
- def from_line(cls, name, comes_from=None):
+ def from_line(cls, name, comes_from=None, upgrade=False):
"""Creates an InstallRequirement from a name, which might be a
requirement, directory containing 'setup.py', filename, or URL.
"""
@@ -114,7 +115,7 @@ def from_line(cls, name, comes_from=None):
else:
req = name
- return cls(req, comes_from, url=url)
+ return cls(req, comes_from, url=url, upgrade=upgrade)
def __str__(self):
if self.req:
@@ -808,13 +809,13 @@ 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,
+ upgrade_recursive=False, ignore_installed=False, as_egg=False,
ignore_dependencies=False, force_reinstall=False, use_user_site=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.upgrade_recursive = upgrade_recursive
self.ignore_installed = ignore_installed
self.force_reinstall = force_reinstall
self.requirements = Requirements()
@@ -908,7 +909,7 @@ def locate_files(self):
if not self.ignore_installed and not req_to_install.editable:
req_to_install.check_if_exists()
if req_to_install.satisfied_by:
- if self.upgrade:
+ if req_to_install.upgrade:
req_to_install.conflicts_with = req_to_install.satisfied_by
req_to_install.satisfied_by = None
else:
@@ -946,11 +947,11 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
if not self.ignore_installed and not req_to_install.editable:
req_to_install.check_if_exists()
if req_to_install.satisfied_by:
- if self.upgrade:
+ if req_to_install.upgrade:
if not self.force_reinstall and not req_to_install.url:
try:
url = finder.find_requirement(
- req_to_install, self.upgrade)
+ req_to_install, req_to_install.upgrade)
except BestVersionAlreadyInstalled:
best_installed = True
install = False
@@ -1012,7 +1013,7 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
if req_to_install.url is None:
if not_found:
raise not_found
- url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
+ url = finder.find_requirement(req_to_install, upgrade=req_to_install.upgrade)
else:
## FIXME: should req_to_install.url already be a link?
url = Link(req_to_install.url)
@@ -1057,7 +1058,7 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
# repeat check_if_exists to uninstall-on-upgrade (#14)
req_to_install.check_if_exists()
if req_to_install.satisfied_by:
- if self.upgrade or self.ignore_installed:
+ if req_to_install.upgrade or self.ignore_installed:
req_to_install.conflicts_with = req_to_install.satisfied_by
req_to_install.satisfied_by = None
else:
@@ -1079,7 +1080,7 @@ def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
if self.has_requirement(name):
## FIXME: check for conflict
continue
- subreq = InstallRequirement(req, req_to_install)
+ subreq = InstallRequirement(req, req_to_install, upgrade=self.upgrade_recursive)
reqs.append(subreq)
self.add_requirement(subreq)
if req_to_install.name not in self.requirements:
@@ -1322,16 +1323,17 @@ def parse_requirements(filename, finder=None, comes_from=None, options=None):
if finder:
finder.index_urls.append(line)
else:
+ upgrade = options.upgrade or options.upgrade_recursive
comes_from = '-r %s (line %s)' % (filename, line_number)
if line.startswith('-e') or line.startswith('--editable'):
if line.startswith('-e'):
line = line[2:].strip()
else:
line = line[len('--editable'):].strip().lstrip('=')
req = InstallRequirement.from_editable(
- line, comes_from=comes_from, default_vcs=options.default_vcs)
+ line, comes_from=comes_from, default_vcs=options.default_vcs, upgrade=upgrade)
else:
- req = InstallRequirement.from_line(line, comes_from)
+ req = InstallRequirement.from_line(line, comes_from, upgrade=upgrade)
yield req

0 comments on commit 99a8927

Please sign in to comment.