diff options
Diffstat (limited to 'pip/commands/install.py')
-rw-r--r-- | pip/commands/install.py | 66 |
1 files changed, 49 insertions, 17 deletions
diff --git a/pip/commands/install.py b/pip/commands/install.py index 861c332bf..925d57feb 100644 --- a/pip/commands/install.py +++ b/pip/commands/install.py @@ -1,11 +1,14 @@ -import os, sys +import os +import sys +import tempfile +import shutil from pip.req import InstallRequirement, RequirementSet from pip.req import parse_requirements from pip.log import logger from pip.locations import build_prefix, src_prefix from pip.basecommand import Command from pip.index import PackageFinder -from pip.exceptions import InstallationError +from pip.exceptions import InstallationError, CommandError class InstallCommand(Command): @@ -79,8 +82,14 @@ class InstallCommand(Command): '-b', '--build', '--build-dir', '--build-directory', dest='build_dir', metavar='DIR', + default=build_prefix, + help='Unpack packages into DIR (default %default) and build from there') + self.parser.add_option( + '-t', '--target', + dest='target_dir', + metavar='DIR', default=None, - help='Unpack packages into DIR (default %s) and build from there' % build_prefix) + help='Install packages into DIR.') self.parser.add_option( '-d', '--download', '--download-dir', '--download-directory', dest='download_dir', @@ -97,8 +106,8 @@ class InstallCommand(Command): '--src', '--source', '--source-dir', '--source-directory', dest='src_dir', metavar='DIR', - default=None, - help='Check out --editable packages into DIR (default %s)' % src_prefix) + default=src_prefix, + help='Check out --editable packages into DIR (default %default)') self.parser.add_option( '-U', '--upgrade', @@ -106,6 +115,12 @@ class InstallCommand(Command): action='store_true', help='Upgrade all packages to the newest available version') self.parser.add_option( + '--force-reinstall', + dest='force_reinstall', + action='store_true', + help='When upgrading, reinstall all packages even if they are ' + 'already up-to-date.') + self.parser.add_option( '-I', '--ignore-installed', dest='ignore_installed', action='store_true', @@ -162,10 +177,6 @@ class InstallCommand(Command): mirrors=options.mirrors) def run(self, options, args): - if not options.build_dir: - options.build_dir = build_prefix - if not options.src_dir: - options.src_dir = src_prefix if options.download_dir: options.no_install = True options.ignore_installed = True @@ -174,6 +185,13 @@ class InstallCommand(Command): install_options = options.install_options or [] if options.use_user_site: install_options.append('--user') + if options.target_dir: + options.ignore_installed = True + temp_target_dir = tempfile.mkdtemp() + options.target_dir = os.path.abspath(options.target_dir) + if os.path.exists(options.target_dir) and not os.path.isdir(options.target_dir): + raise CommandError("Target path exists but is not a directory, will not continue.") + install_options.append('--home=' + temp_target_dir) global_options = options.global_options or [] index_urls = [options.index_url] + options.extra_index_urls if options.no_index: @@ -189,7 +207,8 @@ class InstallCommand(Command): download_cache=options.download_cache, upgrade=options.upgrade, ignore_installed=options.ignore_installed, - ignore_dependencies=options.ignore_dependencies) + ignore_dependencies=options.ignore_dependencies, + force_reinstall=options.force_reinstall) for name in args: requirement_set.add_requirement( InstallRequirement.from_line(name, None)) @@ -199,14 +218,17 @@ class InstallCommand(Command): for filename in options.requirements: for req in parse_requirements(filename, finder=finder, options=options): requirement_set.add_requirement(req) - if not requirement_set.has_requirements: + opts = {'name': self.name} if options.find_links: - raise InstallationError('You must give at least one ' - 'requirement to %s (maybe you meant "pip install %s"?)' - % (self.name, " ".join(options.find_links))) - raise InstallationError('You must give at least one requirement ' - 'to %(name)s (see "pip help %(name)s")' % dict(name=self.name)) + msg = ('You must give at least one requirement to %(name)s ' + '(maybe you meant "pip %(name)s %(links)s"?)' % + dict(opts, links=' '.join(options.find_links))) + else: + msg = ('You must give at least one requirement ' + 'to %(name)s (see "pip help %(name)s")' % opts) + logger.warn(msg) + return if (options.use_user_site and sys.version_info < (2, 6)): @@ -239,8 +261,18 @@ class InstallCommand(Command): requirement_set.create_bundle(self.bundle_filename) logger.notify('Created bundle in %s' % self.bundle_filename) # Clean up - if not options.no_install: + if not options.no_install or options.download_dir: requirement_set.cleanup_files(bundle=self.bundle) + if options.target_dir: + if not os.path.exists(options.target_dir): + os.makedirs(options.target_dir) + lib_dir = os.path.join(temp_target_dir, "lib/python/") + for item in os.listdir(lib_dir): + shutil.move( + os.path.join(lib_dir, item), + os.path.join(options.target_dir, item) + ) + shutil.rmtree(temp_target_dir) return requirement_set |