diff options
Diffstat (limited to 'pip/commands')
-rw-r--r-- | pip/commands/bundle.py | 13 | ||||
-rw-r--r-- | pip/commands/freeze.py | 4 | ||||
-rw-r--r-- | pip/commands/help.py | 12 | ||||
-rw-r--r-- | pip/commands/install.py | 66 | ||||
-rw-r--r-- | pip/commands/search.py | 17 | ||||
-rw-r--r-- | pip/commands/uninstall.py | 1 |
6 files changed, 83 insertions, 30 deletions
diff --git a/pip/commands/bundle.py b/pip/commands/bundle.py index fb0f75704..f782f1bc3 100644 --- a/pip/commands/bundle.py +++ b/pip/commands/bundle.py @@ -13,14 +13,19 @@ class BundleCommand(InstallCommand): def __init__(self): super(BundleCommand, self).__init__() + # bundle uses different default source and build dirs + build_opt = self.parser.get_option("--build") + build_opt.default = backup_dir(build_prefix, '-bundle') + src_opt = self.parser.get_option("--src") + src_opt.default = backup_dir(src_prefix, '-bundle') + self.parser.set_defaults(**{ + src_opt.dest: src_opt.default, + build_opt.dest: build_opt.default, + }) def run(self, options, args): if not args: raise InstallationError('You must give a bundle filename') - if not options.build_dir: - options.build_dir = backup_dir(build_prefix, '-bundle') - if not options.src_dir: - options.src_dir = backup_dir(src_prefix, '-bundle') # We have to get everything when creating a bundle: options.ignore_installed = True logger.notify('Putting temporary build files in %s and source/develop files in %s' diff --git a/pip/commands/freeze.py b/pip/commands/freeze.py index 01b5df934..03ac80f55 100644 --- a/pip/commands/freeze.py +++ b/pip/commands/freeze.py @@ -85,7 +85,9 @@ class FreezeCommand(Command): elif (line.startswith('-r') or line.startswith('--requirement') or line.startswith('-Z') or line.startswith('--always-unzip') or line.startswith('-f') or line.startswith('-i') - or line.startswith('--extra-index-url')): + or line.startswith('--extra-index-url') + or line.startswith('--find-links') + or line.startswith('--index-url')): f.write(line) continue else: diff --git a/pip/commands/help.py b/pip/commands/help.py index b5b31e702..4d504c521 100644 --- a/pip/commands/help.py +++ b/pip/commands/help.py @@ -1,5 +1,7 @@ -from pip.basecommand import Command, command_dict, load_all_commands -from pip.exceptions import InstallationError +from pip.basecommand import (Command, command_dict, + load_all_commands, SUCCESS, + ERROR) +from pip.exceptions import CommandError from pip.baseparser import parser @@ -14,10 +16,10 @@ class HelpCommand(Command): ## FIXME: handle errors better here command = args[0] if command not in command_dict: - raise InstallationError('No command with the name: %s' % command) + raise CommandError('No command with the name: %s' % command) command = command_dict[command] command.parser.print_help() - return + return SUCCESS parser.print_help() print('\nCommands available:') commands = list(set(command_dict.values())) @@ -26,6 +28,6 @@ class HelpCommand(Command): if command.hidden: continue print(' %s: %s' % (command.name, command.summary)) - + return SUCCESS HelpCommand() 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 diff --git a/pip/commands/search.py b/pip/commands/search.py index 1a6bf9c52..9f287e594 100644 --- a/pip/commands/search.py +++ b/pip/commands/search.py @@ -2,10 +2,12 @@ import sys import textwrap import pkg_resources import pip.download -from pip.basecommand import Command +from pip.basecommand import Command, SUCCESS from pip.util import get_terminal_size from pip.log import logger from pip.backwardcompat import xmlrpclib, reduce, cmp +from pip.exceptions import CommandError +from pip.status_codes import NO_MATCHES_FOUND from distutils.version import StrictVersion, LooseVersion @@ -25,8 +27,7 @@ class SearchCommand(Command): def run(self, options, args): if not args: - logger.warn('ERROR: Missing required argument (search query).') - return + raise CommandError('Missing required argument (search query).') query = args index_url = options.index @@ -38,6 +39,9 @@ class SearchCommand(Command): terminal_width = get_terminal_size()[0] print_results(hits, terminal_width=terminal_width) + if pypi_hits: + return SUCCESS + return NO_MATCHES_FOUND def search(self, query, index_url): pypi = xmlrpclib.ServerProxy(index_url, pip.download.xmlrpclib_transport) @@ -106,7 +110,14 @@ def compare_versions(version1, version2): return cmp(StrictVersion(version1), StrictVersion(version2)) # in case of abnormal version number, fall back to LooseVersion except ValueError: + pass + try: return cmp(LooseVersion(version1), LooseVersion(version2)) + except TypeError: + # certain LooseVersion comparions raise due to unorderable types, + # fallback to string comparison + return cmp([str(v) for v in LooseVersion(version1).version], + [str(v) for v in LooseVersion(version2).version]) def highest_version(versions): diff --git a/pip/commands/uninstall.py b/pip/commands/uninstall.py index 7effd844e..9f2b89121 100644 --- a/pip/commands/uninstall.py +++ b/pip/commands/uninstall.py @@ -2,6 +2,7 @@ from pip.req import InstallRequirement, RequirementSet, parse_requirements from pip.basecommand import Command from pip.exceptions import InstallationError + class UninstallCommand(Command): name = 'uninstall' usage = '%prog [OPTIONS] PACKAGE_NAMES ...' |