Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a simple --upgrade_all argument #1506

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions pip/basecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,12 @@ def main(self, args):
logger.info('Exception information:\n%s' % format_exc())
store_log = True
exit = PREVIOUS_BUILD_DIR_ERROR
except (InstallationError, UninstallationError):
except (InstallationError, UninstallationError, BadCommand, CommandError):
e = sys.exc_info()[1]
logger.fatal(str(e))
logger.info('Exception information:\n%s' % format_exc())
store_log = True
exit = ERROR
except BadCommand:
e = sys.exc_info()[1]
logger.fatal(str(e))
logger.info('Exception information:\n%s' % format_exc())
store_log = True
exit = ERROR
except CommandError:
e = sys.exc_info()[1]
logger.fatal('ERROR: %s' % e)
logger.info('Exception information:\n%s' % format_exc())
exit = ERROR
except KeyboardInterrupt:
logger.fatal('Operation cancelled by user')
logger.info('Exception information:\n%s' % format_exc())
Expand Down
31 changes: 17 additions & 14 deletions pip/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ def make_option_group(group, parser):
option_group.add_option(option.make())
return option_group


class OptionMaker(object):
"""Class that stores the args/kwargs that would be used to make an Option,
for making them later, and uses deepcopy's to reset state."""

def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs

def make(self):
args_copy = copy.deepcopy(self.args)
kwargs_copy = copy.deepcopy(self.kwargs)
Expand Down Expand Up @@ -143,15 +146,15 @@ def make(self):
action='append',
metavar='action',
help="Default action when a path already exists: "
"(s)witch, (i)gnore, (w)ipe, (b)ackup.")
"(s)witch, (i)gnore, (w)ipe, (b)ackup.")

cert = OptionMaker(
'--cert',
dest='cert',
type='str',
default='',
metavar='path',
help = "Path to alternate CA bundle.")
help="Path to alternate CA bundle.")

index_url = OptionMaker(
'-i', '--index-url', '--pypi-url',
Expand All @@ -175,7 +178,7 @@ def make(self):
default=False,
help='Ignore package index (only looking at --find-links URLs instead).')

find_links = OptionMaker(
find_links = OptionMaker(
'-f', '--find-links',
dest='find_links',
action='append',
Expand Down Expand Up @@ -261,7 +264,7 @@ def make(self):
default=[],
metavar='file',
help='Install from the given requirements file. '
'This option can be used multiple times.')
'This option can be used multiple times.')

use_wheel = OptionMaker(
'--use-wheel',
Expand Down Expand Up @@ -299,26 +302,26 @@ def make(self):
metavar='dir',
default=build_prefix,
help='Directory to unpack packages into and build in. '
'The default in a virtualenv is "<venv path>/build". '
'The default for global installs is "<OS temp dir>/pip_build_<username>".')
'The default in a virtualenv is "<venv path>/build". '
'The default for global installs is "<OS temp dir>/pip_build_<username>".')

install_options = OptionMaker(
'--install-option',
dest='install_options',
action='append',
metavar='options',
help="Extra arguments to be supplied to the setup.py install "
"command (use like --install-option=\"--install-scripts=/usr/local/bin\"). "
"Use multiple --install-option options to pass multiple options to setup.py install. "
"If you are using an option with a directory path, be sure to use absolute path.")
"command (use like --install-option=\"--install-scripts=/usr/local/bin\"). "
"Use multiple --install-option options to pass multiple options to setup.py install. "
"If you are using an option with a directory path, be sure to use absolute path.")

global_options = OptionMaker(
'--global-option',
dest='global_options',
action='append',
metavar='options',
help="Extra global options to be supplied to the setup.py "
"call before the install command.")
"call before the install command.")

no_clean = OptionMaker(
'--no-clean',
Expand Down Expand Up @@ -349,8 +352,8 @@ def make(self):
skip_requirements_regex,
exists_action,
cert,
]
}
]
}

index_group = {
'name': 'Package Index Options',
Expand All @@ -367,5 +370,5 @@ def make(self):
allow_unsafe,
no_allow_unsafe,
process_dependency_links,
]
}
]
}
125 changes: 57 additions & 68 deletions pip/commands/install.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys
import tempfile
import shutil
from pip.req import InstallRequirement, RequirementSet, parse_requirements
Expand All @@ -8,7 +7,7 @@
from pip.basecommand import Command
from pip.index import PackageFinder
from pip.exceptions import InstallationError, CommandError, PreviousBuildDirError
from pip import cmdoptions
from pip import cmdoptions, get_installed_distributions


class InstallCommand(Command):
Expand Down Expand Up @@ -38,134 +37,121 @@ class InstallCommand(Command):
summary = 'Install packages.'
bundle = False

def __init__(self, *args, **kw):
super(InstallCommand, self).__init__(*args, **kw)

cmd_opts = self.cmd_opts

cmd_opts.add_option(
def populate_cmd_opts(self):
self.cmd_opts.add_option(
'-e', '--editable',
dest='editables',
action='append',
default=[],
metavar='path/url',
help='Install a project in editable mode (i.e. setuptools "develop mode") from a local project path or a VCS url.')

cmd_opts.add_option(cmdoptions.requirements.make())
cmd_opts.add_option(cmdoptions.build_dir.make())

cmd_opts.add_option(
self.cmd_opts.add_option(cmdoptions.requirements.make())
self.cmd_opts.add_option(cmdoptions.build_dir.make())
self.cmd_opts.add_option(
'-t', '--target',
dest='target_dir',
metavar='dir',
default=None,
help='Install packages into <dir>.')

cmd_opts.add_option(
self.cmd_opts.add_option(
'-d', '--download', '--download-dir', '--download-directory',
dest='download_dir',
metavar='dir',
default=None,
help="Download packages into <dir> instead of installing them, regardless of what's already installed.")

cmd_opts.add_option(cmdoptions.download_cache.make())

cmd_opts.add_option(
self.cmd_opts.add_option(cmdoptions.download_cache.make())
self.cmd_opts.add_option(
'--src', '--source', '--source-dir', '--source-directory',
dest='src_dir',
metavar='dir',
default=src_prefix,
help='Directory to check out editable projects into. '
'The default in a virtualenv is "<venv path>/src". '
'The default for global installs is "<current dir>/src".')

cmd_opts.add_option(
'The default in a virtualenv is "<venv path>/src". '
'The default for global installs is "<current dir>/src".')
self.cmd_opts.add_option(
'-U', '--upgrade',
dest='upgrade',
action='store_true',
help='Upgrade all packages to the newest available version. '
'This process is recursive regardless of whether a dependency is already satisfied.')

cmd_opts.add_option(
'This process is recursive regardless of whether a dependency is already satisfied.')
self.cmd_opts.add_option(
'--upgrade_all',
dest='upgrade_all',
action='store_true',
help='Upgrades all packages to the newest available version. '
'This process is recursive regardless of whether a dependency is already satisfied.')
self.cmd_opts.add_option(
'--force-reinstall',
dest='force_reinstall',
action='store_true',
help='When upgrading, reinstall all packages even if they are '
'already up-to-date.')

cmd_opts.add_option(
self.cmd_opts.add_option(
'-I', '--ignore-installed',
dest='ignore_installed',
action='store_true',
help='Ignore the installed packages (reinstalling instead).')

cmd_opts.add_option(cmdoptions.no_deps.make())

cmd_opts.add_option(
self.cmd_opts.add_option(cmdoptions.no_deps.make())
self.cmd_opts.add_option(
'--no-install',
dest='no_install',
action='store_true',
help="DEPRECATED. Download and unpack all packages, but don't actually install them.")

cmd_opts.add_option(
self.cmd_opts.add_option(
'--no-download',
dest='no_download',
action="store_true",
help="DEPRECATED. Don't download any packages, just install the ones already downloaded "
"(completes an install run with --no-install).")

cmd_opts.add_option(cmdoptions.install_options.make())
cmd_opts.add_option(cmdoptions.global_options.make())

cmd_opts.add_option(
"(completes an install run with --no-install).")
self.cmd_opts.add_option(cmdoptions.install_options.make())
self.cmd_opts.add_option(cmdoptions.global_options.make())
self.cmd_opts.add_option(
'--user',
dest='use_user_site',
action='store_true',
help='Install using the user scheme.')

cmd_opts.add_option(
self.cmd_opts.add_option(
'--egg',
dest='as_egg',
action='store_true',
help="Install packages as eggs, not 'flat', like pip normally does. This option is not about installing *from* eggs. (WARNING: Because this option overrides pip's normal install logic, requirements files may not behave as expected.)")

cmd_opts.add_option(
self.cmd_opts.add_option(
'--root',
dest='root_path',
metavar='dir',
default=None,
help="Install everything relative to this alternate root directory.")

cmd_opts.add_option(
self.cmd_opts.add_option(
"--compile",
action="store_true",
dest="compile",
default=True,
help="Compile py files to pyc",
)

cmd_opts.add_option(
self.cmd_opts.add_option(
"--no-compile",
action="store_false",
dest="compile",
help="Do not compile py files to pyc",
)

cmd_opts.add_option(cmdoptions.use_wheel.make())
cmd_opts.add_option(cmdoptions.no_use_wheel.make())

cmd_opts.add_option(
self.cmd_opts.add_option(cmdoptions.use_wheel.make())
self.cmd_opts.add_option(cmdoptions.no_use_wheel.make())
self.cmd_opts.add_option(
'--pre',
action='store_true',
default=False,
help="Include pre-release and development versions. By default, pip only finds stable versions.")
self.cmd_opts.add_option(cmdoptions.no_clean.make())

def __init__(self, *args, **kw):
super(InstallCommand, self).__init__(*args, **kw)

cmd_opts.add_option(cmdoptions.no_clean.make())
self.populate_cmd_opts()

index_opts = cmdoptions.make_option_group(cmdoptions.index_group, self.parser)

self.parser.insert_option_group(0, index_opts)
self.parser.insert_option_group(0, cmd_opts)
self.parser.insert_option_group(0, self.cmd_opts)

def _build_package_finder(self, options, index_urls, session):
"""
Expand All @@ -180,15 +166,17 @@ def _build_package_finder(self, options, index_urls, session):
allow_unverified=options.allow_unverified,
allow_all_external=options.allow_all_external,
allow_all_prereleases=options.pre,
process_dependency_links=
options.process_dependency_links,
session=session,
)
process_dependency_links=options.process_dependency_links,
session=session)

def run(self, options, args):
if options.upgrade_all:
args += [package.project_name for package in
get_installed_distributions(local_only=bool(options.use_user_site))]

if options.no_install or options.no_download:
logger.deprecated('1.7', "DEPRECATION: '--no-install' and '--no-download` are deprecated. See https://github.com/pypa/pip/issues/906.")
logger.deprecated('1.7',
"DEPRECATION: '--no-install' and '--no-download` are deprecated. See https://github.com/pypa/pip/issues/906.")

if options.download_dir:
options.no_install = True
Expand All @@ -198,7 +186,8 @@ def run(self, options, args):
install_options = options.install_options or []
if options.use_user_site:
if virtualenv_no_global():
raise InstallationError("Can not perform a '--user' install. User site-packages are not visible in this virtualenv.")
raise InstallationError(
"Can not perform a '--user' install. User site-packages are not visible in this virtualenv.")
install_options.append('--user')

temp_target_dir = None
Expand All @@ -218,15 +207,15 @@ def run(self, options, args):

if options.use_mirrors:
logger.deprecated("1.7",
"--use-mirrors has been deprecated and will be removed"
" in the future. Explicit uses of --index-url and/or "
"--extra-index-url is suggested.")
"--use-mirrors has been deprecated and will be removed"
" in the future. Explicit uses of --index-url and/or "
"--extra-index-url is suggested.")

if options.mirrors:
logger.deprecated("1.7",
"--mirrors has been deprecated and will be removed in "
" the future. Explicit uses of --index-url and/or "
"--extra-index-url is suggested.")
"--mirrors has been deprecated and will be removed in "
" the future. Explicit uses of --index-url and/or "
"--extra-index-url is suggested.")
index_urls += options.mirrors

session = self._build_session(options)
Expand Down Expand Up @@ -305,6 +294,6 @@ def run(self, options, args):
shutil.move(
os.path.join(lib_dir, item),
os.path.join(options.target_dir, item)
)
)
shutil.rmtree(temp_target_dir)
return requirement_set
Loading