Port to Python3

This commit is contained in:
Vinay Sajip 2011-03-15 15:49:48 -04:00 committed by Vitaly Babiy
parent 6c82a1bfdd
commit 680b5dfda0
43 changed files with 694 additions and 388 deletions

View File

@ -1,5 +1,4 @@
Copyright (c) 2008-2010 Ian Bicking and Contributors
Copyright (c) 2011 The virtualenv developers
Copyright (c) 2008-2011 The pip developers (see AUTHORS.txt file)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the

View File

@ -28,11 +28,7 @@ tip (unreleased)
* Fixed issue #204 - rmtree undefined in mercurial.py. Thanks Kelsey Hightower
* Fixed bug in Git vcs backend that would break during reinstallation.
* Fixed bug in Mercurial vcs backend related to pip freeze and branch/tag resolution.
* Fixed bug in version string parsing related to the suffix "-dev".
0.8.2
-----

View File

@ -12,7 +12,7 @@ from pip.baseparser import parser
from pip.exceptions import InstallationError
from pip.log import logger
from pip.util import get_installed_distributions
from pip.backwardcompat import walk_packages
from pip.backwardcompat import u, walk_packages
def autocomplete():
@ -53,7 +53,7 @@ def autocomplete():
# if there are no dists installed, fall back to option completion
if installed:
for dist in installed:
print dist
print(dist)
sys.exit(1)
subcommand = command_dict.get(subcommand_name)
options += [(opt.get_opt_string(), opt.nargs)
@ -61,7 +61,7 @@ def autocomplete():
if opt.help != optparse.SUPPRESS_HELP]
# filter out previously specified options from available options
prev_opts = [x.split('=')[0] for x in cwords[1:cword-1]]
options = filter(lambda (x, v): x not in prev_opts, options)
options = [(x, v) for (x, v) in options if x not in prev_opts]
# filter options by current input
options = [(k, v) for k, v in options if k.startswith(current)]
for option in options:
@ -69,14 +69,14 @@ def autocomplete():
# append '=' to options which require args
if option[1]:
opt_label += '='
print opt_label
print(opt_label)
else:
# show options of main parser only when necessary
if current.startswith('-') or current.startswith('--'):
subcommands += [opt.get_opt_string()
for opt in parser.option_list
if opt.help != optparse.SUPPRESS_HELP]
print ' '.join(filter(lambda x: x.startswith(current), subcommands))
print(' '.join([x for x in subcommands if x.startswith(current)]))
sys.exit(1)
@ -213,7 +213,8 @@ def call_subprocess(cmd, show_stdout=True,
proc = subprocess.Popen(
cmd, stderr=subprocess.STDOUT, stdin=None, stdout=stdout,
cwd=cwd, env=env)
except Exception, e:
except Exception:
e = sys.exc_info()[1]
logger.fatal(
"Error %s while executing command %s" % (e, command_desc))
raise
@ -221,7 +222,7 @@ def call_subprocess(cmd, show_stdout=True,
if stdout is not None:
stdout = proc.stdout
while 1:
line = stdout.readline()
line = u(stdout.readline())
if not line:
break
line = line.rstrip()

View File

@ -8,6 +8,7 @@ import sys
import imp
import os.path
from types import ModuleType
from pip.backwardcompat import string_types
__all__ = [
'get_importer', 'iter_importers', 'get_loader', 'find_loader',
@ -324,7 +325,7 @@ try:
from zipimport import zipimporter
def iter_zipimport_modules(importer, prefix=''):
dirlist = zipimport._zip_directory_cache[importer.archive].keys()
dirlist = list(zipimport._zip_directory_cache[importer.archive].keys())
dirlist.sort()
_prefix = importer.prefix
plen = len(_prefix)
@ -523,7 +524,7 @@ def extend_path(path, name):
path = path[:] # Start with a copy of the existing path
for dir in sys.path:
if not isinstance(dir, basestring) or not os.path.isdir(dir):
if not isinstance(dir, string_types) or not os.path.isdir(dir):
continue
subdir = os.path.join(dir, pname)
# XXX This may still add duplicate entries to path on
@ -537,7 +538,8 @@ def extend_path(path, name):
if os.path.isfile(pkgfile):
try:
f = open(pkgfile)
except IOError, msg:
except IOError:
msg = sys.exc_info()[1]
sys.stderr.write("Can't open %s: %s\n" %
(pkgfile, msg))
else:

View File

@ -1,4 +1,4 @@
"""Stuff that isn't in some old versions of Python"""
"""Stuff that differs in different Python versions"""
import sys
import os
@ -9,7 +9,9 @@ __all__ = ['any', 'WindowsError', 'md5', 'copytree']
try:
WindowsError = WindowsError
except NameError:
WindowsError = None
class NeverUsedException(Exception):
"""this exception should never be raised"""
WindowsError = NeverUsedException
try:
from hashlib import md5
except ImportError:
@ -20,7 +22,7 @@ try:
from pkgutil import walk_packages
except ImportError:
# let's fall back as long as we can
from _pkgutil import walk_packages
from pip._pkgutil import walk_packages
try:
any = any
@ -32,6 +34,56 @@ except NameError:
return True
return False
if sys.version_info >= (3,):
from io import StringIO
from functools import reduce
from urllib.error import URLError, HTTPError
from queue import Queue, Empty
from urllib.request import url2pathname
from urllib.request import urlretrieve
from email import message as emailmessage
import urllib.parse as urllib
import urllib.request as urllib2
import configparser as ConfigParser
import xmlrpc.client as xmlrpclib
import urllib.parse as urlparse
import http.client as httplib
def cmp(a, b):
return (a > b) - (a < b)
def b(s):
return s.encode('utf-8')
def u(s):
return s.decode('utf-8')
string_types = (str,)
raw_input = input
else:
from cStringIO import StringIO
from urllib2 import URLError, HTTPError
from Queue import Queue, Empty
from urllib import url2pathname, urlretrieve
from email import Message as emailmessage
import urllib
import urllib2
import urlparse
import ConfigParser
import xmlrpclib
import httplib
def b(s):
return s
def u(s):
return s
string_types = (basestring,)
reduce = reduce
cmp = cmp
raw_input = raw_input
try:
from email.parser import FeedParser
except ImportError:
# python lesser than 2.5
from email.FeedParser import FeedParser
from distutils.sysconfig import get_python_lib, get_python_version
def copytree(src, dst):
if sys.version_info < (2, 5):
@ -47,7 +99,7 @@ def copytree(src, dst):
def product(*args, **kwds):
# product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
# product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
pools = map(tuple, args) * kwds.get('repeat', 1)
pools = list(map(tuple, args)) * kwds.get('repeat', 1)
result = [[]]
for pool in pools:
result = [x+[y] for x in result for y in pool]

View File

@ -1,6 +1,5 @@
"""Base Command class, and related routines"""
from cStringIO import StringIO
import os
import socket
import sys
@ -13,7 +12,7 @@ from pip.baseparser import parser, ConfigOptionParser, UpdatingDefaultsHelpForma
from pip.download import urlopen
from pip.exceptions import BadCommand, InstallationError, UninstallationError
from pip.venv import restart_in_venv
from pip.backwardcompat import walk_packages
from pip.backwardcompat import StringIO, urllib, urllib2, walk_packages
__all__ = ['command_dict', 'Command', 'load_all_commands',
'load_command', 'command_names']
@ -125,11 +124,13 @@ class Command(object):
exit = 0
try:
self.run(options, args)
except (InstallationError, UninstallationError), e:
except (InstallationError, UninstallationError):
e = sys.exc_info()[1]
logger.fatal(str(e))
logger.info('Exception information:\n%s' % format_exc())
exit = 1
except BadCommand, e:
except BadCommand:
e = sys.exc_info()[1]
logger.fatal(str(e))
logger.info('Exception information:\n%s' % format_exc())
exit = 1
@ -174,8 +175,8 @@ def open_logfile(filename, mode='a'):
log_fp = open(filename, mode)
if exists:
print >> log_fp, '-'*60
print >> log_fp, '%s run on %s' % (sys.argv[0], time.strftime('%c'))
log_fp.write('%s\n' % ('-'*60))
log_fp.write('%s run on %s\n' % (sys.argv[0], time.strftime('%c')))
return log_fp

View File

@ -3,9 +3,9 @@
import sys
import optparse
import pkg_resources
import ConfigParser
import os
from distutils.util import strtobool
from pip.backwardcompat import ConfigParser, string_types
from pip.locations import default_config_file, default_log_file
@ -50,7 +50,7 @@ class ConfigOptionParser(optparse.OptionParser):
# 2. environmental variables
config.update(dict(self.get_environ_vars()))
# Then set the options with those values
for key, val in config.iteritems():
for key, val in config.items():
key = key.replace('_', '-')
if not key.startswith('--'):
key = '--%s' % key # only prefer long opts
@ -68,8 +68,9 @@ class ConfigOptionParser(optparse.OptionParser):
val = strtobool(val)
try:
val = option.convert_value(key, val)
except optparse.OptionValueError, e:
print ("An error occured during configuration: %s" % e)
except optparse.OptionValueError:
e = sys.exc_info()[1]
print("An error occured during configuration: %s" % e)
sys.exit(3)
defaults[option.dest] = val
return defaults
@ -82,7 +83,7 @@ class ConfigOptionParser(optparse.OptionParser):
def get_environ_vars(self, prefix='PIP_'):
"""Returns a generator with all environmental vars with prefix PIP_"""
for key, val in os.environ.iteritems():
for key, val in os.environ.items():
if key.startswith(prefix):
yield (key.replace(prefix, '').lower(), val)
@ -96,7 +97,7 @@ class ConfigOptionParser(optparse.OptionParser):
defaults = self.update_defaults(self.defaults.copy()) # ours
for option in self._get_all_options():
default = defaults.get(option.dest)
if isinstance(default, basestring):
if isinstance(default, string_types):
opt_str = option.get_opt_string()
defaults[option.dest] = option.check_value(opt_str, default)
return optparse.Values(defaults)

View File

@ -53,7 +53,7 @@ class CompletionCommand(Command):
shell_options = ['--'+shell for shell in sorted(shells)]
if options.shell in shells:
script = COMPLETION_SCRIPTS.get(options.shell, '')
print BASE_COMPLETION % {'script': script, 'shell': options.shell}
print(BASE_COMPLETION % {'script': script, 'shell': options.shell})
else:
sys.stderr.write('ERROR: You must pass %s\n' % ' or '.join(shell_options))

View File

@ -19,14 +19,13 @@ class HelpCommand(Command):
command.parser.print_help()
return
parser.print_help()
print
print 'Commands available:'
print('\nCommands available:')
commands = list(set(command_dict.values()))
commands.sort(key=lambda x: x.name)
for command in commands:
if command.hidden:
continue
print ' %s: %s' % (command.name, command.summary)
print(' %s: %s' % (command.name, command.summary))
HelpCommand()

View File

@ -1,11 +1,11 @@
import sys
import xmlrpclib
import textwrap
import pkg_resources
import pip.download
from pip.basecommand import Command
from pip.util import get_terminal_size
from pip.log import logger
from pip.backwardcompat import xmlrpclib, reduce, cmp
from distutils.version import StrictVersion, LooseVersion
@ -69,7 +69,7 @@ def transform_hits(hits):
packages[name]['score'] = score
# each record has a unique name now, so we will convert the dict into a list sorted by score
package_list = sorted(packages.values(), lambda x, y: cmp(y['score'], x['score']))
package_list = sorted(packages.values(), key=lambda x: x['score'], reverse=True)
return package_list

View File

@ -217,7 +217,7 @@ class ZipCommand(Command):
if lines != new_lines:
logger.info('Removing reference to %s from .pth file %s'
% (display_path(filename), display_path(pth)))
if not filter(None, new_lines):
if not [line for line in new_lines if line]:
logger.info('%s file would be empty: deleting' % display_path(pth))
if not self.simulate:
os.unlink(pth)

View File

@ -1,14 +1,12 @@
import xmlrpclib
import re
import getpass
import urllib
import urllib2
import urlparse
import sys
import os
import mimetypes
import shutil
import tempfile
from pip.backwardcompat import md5, copytree
from pip.backwardcompat import (md5, copytree, xmlrpclib, urllib, urllib2,
urlparse, string_types, HTTPError)
from pip.exceptions import InstallationError
from pip.util import (splitext, rmtree,
format_size, display_path, backup_dir, ask,
@ -54,7 +52,8 @@ def get_file_content(url, comes_from=None):
try:
f = open(url)
content = f.read()
except IOError, e:
except IOError:
e = sys.exc_info()[1]
raise InstallationError('Could not open requirements file: %s' % str(e))
else:
f.close()
@ -82,7 +81,8 @@ class URLOpener(object):
if username is None:
try:
response = urllib2.urlopen(self.get_request(url))
except urllib2.HTTPError, e:
except urllib2.HTTPError:
e = sys.exc_info()[1]
if e.code != 401:
raise
response = self.get_response(url)
@ -95,7 +95,7 @@ class URLOpener(object):
Wraps the URL to retrieve to protects against "creative"
interpretation of the RFC: http://bugs.python.org/issue8732
"""
if isinstance(url, basestring):
if isinstance(url, string_types):
url = urllib2.Request(url, headers={'Accept-encoding': 'identity'})
return url
@ -455,10 +455,12 @@ def unpack_http_url(link, location, download_cache, only_download):
def _get_response_from_url(target_url, link):
try:
resp = urlopen(target_url)
except urllib2.HTTPError, e:
except urllib2.HTTPError:
e = sys.exc_info()[1]
logger.fatal("HTTP error %s while getting %s" % (e.code, link))
raise
except IOError, e:
except IOError:
e = sys.exc_info()[1]
# Typically an FTP error
logger.fatal("Error %s while getting %s" % (e, link))
raise

View File

@ -7,19 +7,18 @@ import mimetypes
import threading
import posixpath
import pkg_resources
import urllib
import urllib2
import urlparse
import random
import socket
import string
from Queue import Queue
from Queue import Empty as QueueEmpty
from pip.log import logger
from pip.util import Inf
from pip.util import normalize_name, splitext
from pip.exceptions import DistributionNotFound
from pip.backwardcompat import WindowsError, product
from pip.backwardcompat import (WindowsError,
Queue, httplib, urlparse,
URLError, HTTPError, u,
product, url2pathname)
from pip.backwardcompat import Empty as QueueEmpty
from pip.download import urlopen, path_to_url2, url_to_path, geturl, Urllib2HeadRequest
__all__ = ['PackageFinder']
@ -432,7 +431,7 @@ class HTMLPage(object):
# Tack index.html onto file:// URLs that point to directories
(scheme, netloc, path, params, query, fragment) = urlparse.urlparse(url)
if scheme == 'file' and os.path.isdir(urllib.url2pathname(path)):
if scheme == 'file' and os.path.isdir(url2pathname(path)):
# add trailing slash if not present so urljoin doesn't trim final segment
if not url.endswith('/'):
url += '/'
@ -443,21 +442,22 @@ class HTMLPage(object):
real_url = geturl(resp)
headers = resp.info()
inst = cls(resp.read(), real_url, headers)
except (urllib2.HTTPError, urllib2.URLError, socket.timeout, socket.error, OSError, WindowsError), e:
inst = cls(u(resp.read()), real_url, headers)
except (HTTPError, URLError, socket.timeout, socket.error, OSError, WindowsError):
e = sys.exc_info()[1]
desc = str(e)
if isinstance(e, socket.timeout):
log_meth = logger.info
level =1
desc = 'timed out'
elif isinstance(e, urllib2.URLError):
elif isinstance(e, URLError):
log_meth = logger.info
if hasattr(e, 'reason') and isinstance(e.reason, socket.timeout):
desc = 'timed out'
level = 1
else:
level = 2
elif isinstance(e, urllib2.HTTPError) and e.code == 404:
elif isinstance(e, HTTPError) and e.code == 404:
## FIXME: notify?
log_meth = logger.info
level = 2

View File

@ -2,7 +2,7 @@
import sys
import os
from distutils import sysconfig
from pip.backwardcompat import get_python_lib
def running_under_virtualenv():
@ -29,7 +29,7 @@ src_prefix = os.path.abspath(src_prefix)
# FIXME doesn't account for venv linked to global site-packages
site_packages = sysconfig.get_python_lib()
site_packages = get_python_lib()
user_dir = os.path.expanduser('~')
if sys.platform == 'win32':
bin_py = os.path.join(sys.prefix, 'Scripts')

View File

@ -5,12 +5,6 @@ import re
import zipfile
import pkg_resources
import tempfile
import urlparse
import urllib2
import urllib
import ConfigParser
from distutils.sysconfig import get_python_version
from email.FeedParser import FeedParser
from pip.locations import bin_py, running_under_virtualenv
from pip.exceptions import InstallationError, UninstallationError
from pip.vcs import vcs
@ -21,7 +15,10 @@ from pip.util import is_installable_dir, is_local, dist_is_local
from pip.util import renames, normalize_path, egg_link_path
from pip.util import make_path_relative
from pip import call_subprocess
from pip.backwardcompat import any, copytree
from pip.backwardcompat import (any, copytree, urlparse, urllib,
ConfigParser, string_types, HTTPError,
FeedParser, get_python_version,
b)
from pip.index import Link
from pip.locations import build_prefix
from pip.download import (get_file_content, is_url, url_to_path,
@ -37,7 +34,7 @@ class InstallRequirement(object):
def __init__(self, req, comes_from, source_dir=None, editable=False,
url=None, update=True):
if isinstance(req, basestring):
if isinstance(req, string_types):
req = pkg_resources.Requirement.parse(req)
self.req = req
self.comes_from = comes_from
@ -110,7 +107,7 @@ class InstallRequirement(object):
if self.satisfied_by is not None:
s += ' in %s' % display_path(self.satisfied_by.location)
if self.comes_from:
if isinstance(self.comes_from, basestring):
if isinstance(self.comes_from, string_types):
comes_from = self.comes_from
else:
comes_from = self.comes_from.from_path()
@ -123,7 +120,7 @@ class InstallRequirement(object):
return None
s = str(self.req)
if self.comes_from:
if isinstance(self.comes_from, basestring):
if isinstance(self.comes_from, string_types):
comes_from = self.comes_from
else:
comes_from = self.comes_from.from_path()
@ -239,7 +236,7 @@ def replacement_run(self):
writer(self, ep.name, egg_info.os.path.join(self.egg_info,ep.name))
self.find_sources()
egg_info.egg_info.run = replacement_run
execfile(__file__)
exec(compile(open(__file__).read(), __file__, 'exec'))
"""
def egg_info_data(self, filename):
@ -521,7 +518,7 @@ execfile(__file__)
dirname = os.path.join(dirpath, dirname)
name = self._clean_zip_name(dirname, dir)
zipdir = zipfile.ZipInfo(self.name + '/' + name + '/')
zipdir.external_attr = 0755 << 16L
zipdir.external_attr = 0x1ED << 16
zip.writestr(zipdir, '')
for filename in filenames:
if filename == PIP_DELETE_MARKER_FILENAME:
@ -551,7 +548,7 @@ execfile(__file__)
install_args = [
sys.executable, '-c',
"import setuptools;__file__=%r;"\
"execfile(__file__)" % self.setup_py] +\
"exec(compile(open(__file__).read(), __file__, 'exec'))" % self.setup_py] +\
list(global_options) + [
'install',
'--single-version-externally-managed',
@ -621,7 +618,7 @@ execfile(__file__)
## FIXME: should we do --install-headers here too?
call_subprocess(
[sys.executable, '-c',
"import setuptools; __file__=%r; execfile(%r)" % (self.setup_py, self.setup_py)]
"import setuptools; __file__=%r; exec(compile(open(__file__).read(), __file__, 'exec'))" % self.setup_py]
+ list(global_options) + ['develop', '--no-deps'] + list(install_options),
cwd=self.source_dir, filter_stdout=self._filter_install,
@ -818,7 +815,7 @@ class RequirementSet(object):
@property
def has_requirements(self):
return self.requirements.values() or self.unnamed_requirements
return list(self.requirements.values()) or self.unnamed_requirements
@property
def has_editables(self):
@ -858,7 +855,7 @@ class RequirementSet(object):
## FIXME: duplicates code from install_files; relevant code should
## probably be factored out into a separate method
unnamed = list(self.unnamed_requirements)
reqs = self.requirements.values()
reqs = list(self.requirements.values())
while reqs or unnamed:
if unnamed:
req_to_install = unnamed.pop(0)
@ -894,7 +891,7 @@ class RequirementSet(object):
def prepare_files(self, finder, force_root_egg_info=False, bundle=False):
"""Prepare process. Create temp directories, download and/or unpack files."""
unnamed = list(self.unnamed_requirements)
reqs = self.requirements.values()
reqs = list(self.requirements.values())
while reqs or unnamed:
if unnamed:
req_to_install = unnamed.pop(0)
@ -957,7 +954,8 @@ class RequirementSet(object):
if url:
try:
self.unpack_url(url, location, self.is_download)
except urllib2.HTTPError, e:
except HTTPError:
e = sys.exc_info()[1]
logger.fatal('Could not install requirement %s because of error %s'
% (req_to_install, e))
raise InstallationError(
@ -1007,7 +1005,8 @@ class RequirementSet(object):
for req in req_to_install.requirements():
try:
name = pkg_resources.Requirement.parse(req).project_name
except ValueError, e:
except ValueError:
e = sys.exc_info()[1]
## FIXME: proper warning
logger.error('Invalid requirement: %r (%s) in requirement %s' % (req, e, req_to_install))
continue
@ -1439,19 +1438,21 @@ class UninstallPthEntries(object):
def remove(self):
logger.info('Removing pth entries from %s:' % self.file)
fh = open(self.file, 'r')
fh = open(self.file, 'rb')
# windows uses '\r\n' with py3k, but uses '\n' with py2.x
lines = fh.readlines()
self._saved_lines = lines
fh.close()
try:
for entry in self.entries:
logger.info('Removing entry: %s' % entry)
if any(b('\r\n') in line for line in lines):
endline = '\r\n'
else:
endline = '\n'
for entry in self.entries:
try:
lines.remove(entry + '\n')
logger.info('Removing entry: %s' % entry)
lines.remove(b(entry + endline))
except ValueError:
pass
finally:
pass
fh = open(self.file, 'wb')
fh.writelines(lines)
fh.close()
@ -1475,6 +1476,12 @@ class FakeFile(object):
def readline(self):
try:
return self._gen.next()
try:
return next(self._gen)
except NameError:
return self._gen.next()
except StopIteration:
return ''
def __iter__(self):
return self._gen

View File

@ -8,7 +8,7 @@ import pkg_resources
import zipfile
import tarfile
from pip.exceptions import InstallationError
from pip.backwardcompat import WindowsError
from pip.backwardcompat import WindowsError, string_types, raw_input
from pip.locations import site_packages, running_under_virtualenv
from pip.log import logger
@ -70,7 +70,7 @@ def find_command(cmd, paths=None, pathext=None):
"""Searches the PATH for the given command and returns its path"""
if paths is None:
paths = os.environ.get('PATH', []).split(os.pathsep)
if isinstance(paths, basestring):
if isinstance(paths, string_types):
paths = [paths]
# check if there are funny path extensions for executables, e.g. Windows
if pathext is None:
@ -101,8 +101,8 @@ def ask(message, options):
response = raw_input(message)
response = response.strip().lower()
if response not in options:
print 'Your response (%r) was not one of the expected responses: %s' % (
response, ', '.join(options))
print('Your response (%r) was not one of the expected responses: %s' % (
response, ', '.join(options)))
else:
return response
@ -158,7 +158,7 @@ def is_svn_page(html):
def file_contents(filename):
fp = open(filename, 'rb')
try:
return fp.read()
return fp.read().decode('utf-8')
finally:
fp.close()
@ -418,7 +418,8 @@ def untar_file(filename, location):
else:
try:
fp = tar.extractfile(member)
except (KeyError, AttributeError), e:
except (KeyError, AttributeError):
e = sys.exc_info()[1]
# Some corrupt tar files seem to produce this
# (specifically bad symlinks)
logger.warn(

View File

@ -2,9 +2,8 @@
import os
import shutil
import urlparse
import urllib
from pip.backwardcompat import urlparse, urllib
from pip.exceptions import BadCommand
from pip.log import logger
from pip.util import display_path, backup_dir, find_command, ask, rmtree
@ -28,7 +27,7 @@ class VcsSupport(object):
@property
def backends(self):
return self._registry.values()
return list(self._registry.values())
@property
def dirnames(self):

View File

@ -4,8 +4,9 @@ from pip import call_subprocess
from pip.util import display_path, rmtree
from pip.vcs import vcs, VersionControl
from pip.log import logger
from urllib import url2pathname
from urlparse import urlsplit, urlunsplit
from pip.backwardcompat import url2pathname, urlparse
urlsplit = urlparse.urlsplit
urlunsplit = urlparse.urlunsplit
class Git(VersionControl):
name = 'git'
@ -66,7 +67,7 @@ class Git(VersionControl):
"""
revisions = self.get_tag_revs(dest)
revisions.update(self.get_branch_revs(dest))
inverse_revisions = dict((v, k) for k, v in revisions.iteritems())
inverse_revisions = dict((v, k) for k, v in revisions.items())
# Check if rev is a branch name
origin_rev = 'origin/%s' % rev
if origin_rev in inverse_revisions:

View File

@ -1,12 +1,13 @@
import os
import tempfile
import re
import ConfigParser
import sys
from pip import call_subprocess
from pip.util import display_path, rmtree
from pip.log import logger
from pip.vcs import vcs, VersionControl
from pip.download import path_to_url2
from pip.backwardcompat import ConfigParser
class Mercurial(VersionControl):
@ -53,7 +54,8 @@ class Mercurial(VersionControl):
config_file = open(repo_config, 'w')
config.write(config_file)
config_file.close()
except (OSError, ConfigParser.NoSectionError), e:
except (OSError, ConfigParser.NoSectionError):
e = sys.exc_info()[1]
logger.warn(
'Could not switch Mercurial repository to %s: %s'
% (url, e))

View File

@ -124,7 +124,7 @@ class Subversion(VersionControl):
f.close()
if data.startswith('8') or data.startswith('9') or data.startswith('10'):
data = map(str.splitlines, data.split('\n\x0c\n'))
data = list(map(str.splitlines, data.split('\n\x0c\n')))
del data[0][0] # get rid of the '8'
dirurl = data[0][3]
revs = [int(d[9]) for d in data if len(d)>9 and d[9]]+[0]
@ -174,7 +174,7 @@ class Subversion(VersionControl):
data = f.read()
f.close()
if data.startswith('8') or data.startswith('9') or data.startswith('10'):
data = map(str.splitlines, data.split('\n\x0c\n'))
data = list(map(str.splitlines, data.split('\n\x0c\n')))
del data[0][0] # get rid of the '8'
return data[0][3]
elif data.startswith('<?xml'):

View File

@ -25,10 +25,10 @@ def restart_in_venv(venv, base, site_packages, args):
try:
import virtualenv
except ImportError:
print 'The virtual environment does not exist: %s' % venv
print 'and virtualenv is not installed, so a new environment cannot be created'
print('The virtual environment does not exist: %s' % venv)
print('and virtualenv is not installed, so a new environment cannot be created')
sys.exit(3)
print 'Creating new virtualenv environment in %s' % venv
print('Creating new virtualenv environment in %s' % venv)
virtualenv.logger = logger
logger.indent += 2
virtualenv.create_environment(venv, site_packages=site_packages)

7
run-tests-py3k Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
python -c 'import mock' 2>/dev/null || easy_install mock
python -c 'import nose' 2>/dev/null || easy_install http://bitbucket.org/jpellerin/nose3/get/539ffaa993f4.zip
python -c 'import scripttest' 2>/dev/null || easy_install http://bitbucket.org/ianb/scripttest/get/4782629a179f.zip
python setup.py install
nosetests3 -v

View File

@ -2,7 +2,7 @@ import sys
import os
from setuptools import setup
version = "0.8.3"
version = "0.8.2"
doc_dir = os.path.join(os.path.dirname(__file__), 'docs')
index_filename = os.path.join(doc_dir, 'index.txt')

0
tests/__init__.py Normal file
View File

View File

@ -1,10 +1,9 @@
import os
import subprocess
import urllib
from pip.vcs import subversion, git, bazaar, mercurial
from path import Path
from test_pip import path_to_url, here
from pypi_server import PyPIProxy
from pip.backwardcompat import urlretrieve
from tests.test_pip import path_to_url
from tests.pypi_server import PyPIProxy
def _create_initools_repository():
@ -12,7 +11,7 @@ def _create_initools_repository():
def _dump_initools_repository():
filename, _ = urllib.urlretrieve('http://bitbucket.org/hltbra/pip-initools-dump/raw/8b55c908a320/INITools_modified.dump')
filename, _ = urlretrieve('http://bitbucket.org/hltbra/pip-initools-dump/raw/8b55c908a320/INITools_modified.dump')
initools_folder = os.path.join(_get_vcs_folder(), 'INITools')
devnull = open(os.devnull, 'w')
dump = open(filename)

View File

@ -1,8 +1,16 @@
# -*- coding: utf-8 -*-
# Author: Aziz Köksal
import os
import sys
import shutil
if sys.version_info >= (3,):
unicode = str
u = str
else:
unicode = unicode
u = lambda s: s.decode('utf-8')
_base = os.path.supports_unicode_filenames and unicode or str
@ -23,17 +31,23 @@ class Path(_base):
""" path_obj / 'bc.d' """
""" path_obj / path_obj2 """
return Path(self, path)
__truediv__ = __div__
def __rdiv__(self, path):
""" Joins this path with another path. """
""" "/home/a" / path_obj """
return Path(path, self)
__rtruediv__ = __rdiv__
def __idiv__(self, path):
""" Like __div__ but also assigns to the variable. """
""" path_obj /= 'bc.d' """
return Path(self, path)
__itruediv__ = __idiv__
def __floordiv__(self, paths):
""" Returns a list of paths prefixed with 'self'. """
""" '/home/a' // [bc.d, ef.g] -> [/home/a/bc.d, /home/a/ef.g] """
@ -59,7 +73,7 @@ class Path(_base):
return Path(path + _base(self))
def __repr__(self):
return u"Path(%s)" % _base.__repr__(self)
return u("Path(%s)" % _base.__repr__(self))
def __hash__(self):
return _base.__hash__(self)
@ -145,12 +159,12 @@ class Path(_base):
del kwargs["followlinks"]
return os.walk(self, **kwargs)
def mkdir(self, mode=0777):
def mkdir(self, mode=0x1FF):
""" Creates a directory, if it doesn't exist already. """
if not self.exists:
os.mkdir(self, mode)
def makedirs(self, mode=0777):
def makedirs(self, mode=0x1FF):
""" Like mkdir(), but also creates parent directories. """
if not self.exists:
os.makedirs(self, mode)
@ -188,6 +202,6 @@ class Path(_base):
def glob(self, pattern):
from glob import glob
return map(Path, glob(_base(self/pattern)))
return list(map(Path, glob(_base(self/pattern))))
curdir = Path(os.path.curdir)

View File

@ -1,25 +1,9 @@
import urllib
import urllib2
import os
from UserDict import DictMixin
import pip.backwardcompat
from pip.backwardcompat import urllib, string_types, b, u, emailmessage
urlopen_original = urllib2.urlopen
class IgnoringCaseDict(DictMixin):
def __init__(self):
self._dict = dict()
def __getitem__(self, key):
return self._dict[key.lower()]
def __setitem__(self, key, value):
self._dict[key.lower()] = value
def keys(self):
return self._dict.keys()
urlopen_original = pip.backwardcompat.urllib2.urlopen
class CachedResponse(object):
@ -32,16 +16,17 @@ class CachedResponse(object):
"""
def __init__(self, url, folder):
self.headers = IgnoringCaseDict() # maybe use httplib.HTTPMessage ??
self.headers = emailmessage.Message()
self.code = 500
self.msg = 'Internal Server Error'
# url can be a simple string, or a urllib2.Request object
if isinstance(url, basestring):
if isinstance(url, string_types):
self.url = url
else:
self.url = url.get_full_url()
self.headers.update(url.headers)
self._body = ''
for key, value in url.headers.items():
self.headers[key] = value
self._body = b('')
self._set_all_fields(folder)
def _set_all_fields(self, folder):
@ -50,16 +35,17 @@ class CachedResponse(object):
self._cache_url(filename)
fp = open(filename, 'rb')
try:
line = fp.next().strip()
line = fp.readline().strip()
self.code, self.msg = line.split(None, 1)
except ValueError:
raise ValueError('Bad field line: %r' % line)
self.code = int(self.code)
self.msg = u(self.msg)
for line in fp:
if line == '\n':
if line == b('\n'):
break
key, value = line.split(': ')
self.headers[key] = value.strip()
key, value = line.split(b(': '), 1)
self.headers[u(key)] = u(value.strip())
for line in fp:
self._body += line
fp.close()
@ -91,10 +77,10 @@ class CachedResponse(object):
fp = open(filepath, 'wb')
# when it uses file:// scheme, code is None and there is no msg attr
# but it has been successfully opened
status = '%s %s' % (getattr(response, 'code', 200) or 200, getattr(response, 'msg', 'OK'))
headers = ['%s: %s' % (key, value) for key, value in response.headers.items()]
status = b('%s %s' % (getattr(response, 'code', 200) or 200, getattr(response, 'msg', 'OK')))
headers = [b('%s: %s' % (key, value)) for key, value in list(response.headers.items())]
body = response.read()
fp.write('\n'.join([status] + headers + ['', body]))
fp.write(b('\n').join([status] + headers + [b(''), body]))
fp.close()
@ -111,29 +97,33 @@ class PyPIProxy(object):
def _monkey_patch_urllib2_to_cache_everything(self):
def urlopen(url):
return CachedResponse(url, self.CACHE_PATH)
urllib2.urlopen = urlopen
pip.backwardcompat.urllib2.urlopen = urlopen
def _create_cache_folder(self):
if not os.path.exists(self.CACHE_PATH):
os.mkdir(self.CACHE_PATH)
def assert_equal(a, b):
assert a == b, "\nexpected:\n%r\ngot:\n%r" % (b, a)
def test_cache_proxy():
url = 'http://example.com'
here = os.path.dirname(os.path.abspath(__file__))
filepath = os.path.join(here, urllib.quote(url, ''))
if os.path.exists(filepath):
os.remove(filepath)
response = urllib2.urlopen(url)
response = pip.backwardcompat.urllib2.urlopen(url)
r = CachedResponse(url, here)
try:
assert r.code == response.code
assert r.msg == response.msg
assert r.read() == response.read()
assert r.url == response.url
assert r.geturl() == response.geturl()
assert r.headers.keys() == response.headers.keys()
assert r.info().keys() == response.info().keys()
assert r.headers['content-length'] == response.headers['content-length']
assert_equal(r.code, response.code)
assert_equal(r.msg, response.msg)
assert_equal(r.read(), response.read())
assert_equal(r.url, response.url)
assert_equal(r.geturl(), response.geturl())
assert_equal(set(r.headers.keys()), set(response.headers.keys()))
assert_equal(set(r.info().keys()), set(response.info().keys()))
assert_equal(r.headers['content-length'], response.headers['content-length'])
finally:
os.remove(filepath)

View File

@ -20,60 +20,60 @@ def main(args=None):
if args is None:
args = sys.argv[1:]
if not args:
print 'Usage: test_all_pip.py <output-dir>'
print('Usage: test_all_pip.py <output-dir>'
sys.exit(1)
output = os.path.abspath(args[0])
if not os.path.exists(output):
print 'Creating %s' % output
print('Creating %s' % output)
os.makedirs(output)
pending_fn = os.path.join(output, 'pending.txt')
if not os.path.exists(pending_fn):
print 'Downloading pending list'
print('Downloading pending list')
projects = all_projects()
print 'Found %s projects' % len(projects)
print('Found %s projects' % len(projects)
f = open(pending_fn, 'w')
for name in projects:
f.write(name + '\n')
f.close()
print 'Starting testing...'
print('Starting testing...')
while os.stat(pending_fn).st_size:
_test_packages(output, pending_fn)
print 'Finished all pending!'
print('Finished all pending!')
def _test_packages(output, pending_fn):
package = get_last_item(pending_fn)
print 'Testing package %s' % package
print('Testing package %s' % package)
dest_dir = os.path.join(output, package)
print 'Creating virtualenv in %s' % dest_dir
print('Creating virtualenv in %s' % dest_dir)
create_venv(dest_dir)
print 'Uninstalling actual pip'
print('Uninstalling actual pip')
code = subprocess.check_call([os.path.join(dest_dir, 'bin', 'pip'),
'uninstall', '-y', 'pip'])
assert not code, 'pip uninstallation failed'
print 'Installing development pip'
print('Installing development pip')
code = subprocess.check_call([os.path.join(dest_dir, 'bin', 'python'),
'setup.py', 'install'],
cwd=src_folder)
assert not code, 'pip installation failed'
print 'Trying installation of %s' % dest_dir
print('Trying installation of %s' % dest_dir)
code = subprocess.check_call([os.path.join(dest_dir, 'bin', 'pip'),
'install', package])
if code:
print 'Installation of %s failed' % package
print 'Now checking easy_install...'
print('Installation of %s failed' % package)
print('Now checking easy_install...')
create_venv(dest_dir)
code = subprocess.check_call([os.path.join(dest_dir, 'bin', 'easy_install'),
package])
if code:
print 'easy_install also failed'
print('easy_install also failed')
add_package(os.path.join(output, 'easy-failure.txt'), package)
else:
print 'easy_install succeeded'
print('easy_install succeeded')
add_package(os.path.join(output, 'failure.txt'), package)
pop_last_item(pending_fn, package)
else:
print 'Installation of %s succeeded' % package
print('Installation of %s succeeded' % package)
add_package(os.path.join(output, 'success.txt'), package)
pop_last_item(pending_fn, package)
shutil.rmtree(dest_dir)

View File

@ -4,10 +4,10 @@ import filecmp
import textwrap
import sys
from os.path import abspath, join, curdir, pardir
from test_pip import here, reset_env, run_pip, pyversion, mkdir, src_folder, write_file
from local_repos import local_checkout
from path import Path
from tests.test_pip import (here, reset_env, run_pip, pyversion, mkdir,
src_folder, write_file, LOCAL_PYPI_ARGS)
from tests.local_repos import local_checkout
from tests.path import Path
def test_correct_pip_version():
"""
@ -213,10 +213,13 @@ def test_install_editable_from_git():
Test cloning from Git.
"""
reset_env()
result = run_pip('install', '-e',
'%s#egg=django-feedutil' %
local_checkout('git+http://github.com/jezdez/django-feedutil.git'),
expect_error=True)
args = ['install']
if pyversion >= '3':
args.extend(LOCAL_PYPI_ARGS)
args.extend(['-e',
'%s#egg=django-feedutil' %
local_checkout('git+http://github.com/jezdez/django-feedutil.git')])
result = run_pip(*args, expect_error=True)
result.assert_installed('django-feedutil', with_files=['.git'])
@ -333,7 +336,7 @@ else:
assert egg_info_folder in result.files_created, str(result)
def test_install_subversion_usersite_editable_with_distribute():
def test_install_subversion_usersite_editable_with_distribute(): # VMS fails because abiflags not in environment
"""
Test installing current directory ('.') into usersite after installing distribute
"""
@ -348,18 +351,20 @@ else:
result.assert_installed('INITools', use_user_site=True)
def test_install_subversion_usersite_editable_with_setuptools_fails():
"""
Test installing current directory ('.') into usersite using setuptools
"""
env = reset_env()
(env.lib_path/'no-global-site-packages.txt').rm() # this one reenables user_site
if sys.version_info < (3,):
# We don't try to use setuptools for 3.X.
def test_install_subversion_usersite_editable_with_setuptools_fails():
"""
Test installing current directory ('.') into usersite using setuptools
"""
env = reset_env()
(env.lib_path/'no-global-site-packages.txt').rm() # this one reenables user_site
result = run_pip('install', '--user', '-e',
'%s#egg=initools-dev' %
local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'),
expect_error=True)
assert '--user --editable not supported with setuptools, use distribute' in result.stdout
result = run_pip('install', '--user', '-e',
'%s#egg=initools-dev' %
local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'),
expect_error=True)
assert '--user --editable not supported with setuptools, use distribute' in result.stdout
def test_install_pardir():
"""
@ -399,8 +404,12 @@ def test_install_using_install_option_and_editable():
env = reset_env()
folder = 'script_folder'
mkdir(folder)
if pyversion[0] >= '3':
url = 'hg+http://bitbucket.org/vinay.sajip/virtualenv'
else:
url = 'hg+http://bitbucket.org/ianb/virtualenv'
result = run_pip('install', '-e', '%s#egg=virtualenv' %
local_checkout('hg+http://bitbucket.org/ianb/virtualenv'),
local_checkout(url),
'--install-option=--script-dir=%s' % folder)
virtualenv_bin = env.venv/'src'/'virtualenv'/folder/'virtualenv'+env.exe
assert virtualenv_bin in result.files_created
@ -411,10 +420,17 @@ def test_install_global_option_using_editable():
Test using global distutils options, but in an editable installation
"""
reset_env()
if pyversion >= '3':
url = 'hg+http://bitbucket.org/vinay.sajip/virtualenv'
else:
url = 'hg+http://bitbucket.org/ianb/virtualenv@1.4.1'
result = run_pip('install', '--global-option=--version',
'-e', '%s#egg=virtualenv' %
local_checkout('hg+http://bitbucket.org/ianb/virtualenv@1.4.1'))
assert '1.4.1\n' in result.stdout
local_checkout(url))
if pyversion >= '3':
print(result.stdout)
else:
assert '1.4.1\n' in result.stdout
def test_install_package_with_same_name_in_curdir():

View File

@ -2,9 +2,9 @@ import zipfile
import textwrap
from os.path import join
from pip.download import path_to_url2
from test_pip import here, reset_env, run_pip, write_file
from path import Path
from local_repos import local_checkout
from tests.test_pip import here, reset_env, run_pip, write_file
from tests.path import Path
from tests.local_repos import local_checkout
def test_create_bundle():

View File

@ -1,10 +1,10 @@
import os
import textwrap
from os.path import abspath, exists, join
from test_pip import here, reset_env, run_pip, write_file, mkdir
from local_repos import local_checkout
from path import Path
from tests.test_pip import (here, reset_env, run_pip, write_file, mkdir,
pyversion, LOCAL_PYPI_ARGS)
from tests.local_repos import local_checkout
from tests.path import Path
def test_cleanup_after_install_from_pypi():
"""
@ -49,7 +49,6 @@ def test_cleanup_after_install_from_local_directory():
assert not exists(build), "unexpected build/ dir exists: %s" % build
assert not exists(src), "unexpected src/ dir exist: %s" % src
def test_cleanup_after_create_bundle():
"""
Test clean up after making a bundle. Make sure (build|src)-bundle/ dirs are removed but not src/.
@ -57,9 +56,13 @@ def test_cleanup_after_create_bundle():
"""
env = reset_env()
# Install an editable to create a src/ dir.
run_pip('install', '-e',
'%s#egg=django-feedutil' %
local_checkout('git+http://github.com/jezdez/django-feedutil.git'))
args = ['install']
if pyversion >= '3':
args.extend(LOCAL_PYPI_ARGS)
args.extend(['-e',
'%s#egg=django-feedutil' %
local_checkout('git+http://github.com/jezdez/django-feedutil.git')])
run_pip(*args)
build = env.venv_path/"build"
src = env.venv_path/"src"
assert not exists(build), "build/ dir still exists: %s" % build

View File

@ -1,5 +1,5 @@
import os
from test_pip import reset_env, run_pip, get_env
from tests.test_pip import reset_env, run_pip, get_env
def test_completion_for_bash():

View File

@ -1,7 +1,7 @@
import os
import tempfile
import textwrap
from test_pip import reset_env, run_pip, clear_environ, write_file
from tests.test_pip import reset_env, run_pip, clear_environ, write_file
def test_options_from_env_vars():
@ -58,7 +58,7 @@ def test_command_line_appends_correctly():
environ['PIP_FIND_LINKS'] = 'http://pypi.pinaxproject.com http://example.com'
reset_env(environ)
result = run_pip('install', '-vvv', 'INITools', expect_error=True)
print result.stdout
print(result.stdout)
assert "Analyzing links from page http://pypi.pinaxproject.com" in result.stdout
assert "Analyzing links from page http://example.com" in result.stdout

View File

@ -1,6 +1,6 @@
import textwrap
from test_pip import reset_env, run_pip, write_file
from path import Path
from tests.test_pip import reset_env, run_pip, write_file
from tests.path import Path
def test_download_if_requested():

View File

@ -1,6 +1,6 @@
import urllib
from test_pip import here, reset_env, run_pip, pyversion
from path import Path
from pip.backwardcompat import urllib
from tests.test_pip import here, reset_env, run_pip, pyversion
from tests.path import Path
index_url = 'file://' + urllib.quote(str(Path(here).abspath/'in dex').replace('\\', '/'))

View File

@ -2,10 +2,12 @@ import sys
import re
import textwrap
from doctest import OutputChecker, ELLIPSIS
from test_pip import reset_env, run_pip, write_file, get_env
from local_repos import local_checkout, local_repo
from tests.test_pip import reset_env, run_pip, write_file, get_env, pyversion
from tests.local_repos import local_checkout, local_repo
simplejson_works = (pyversion[0] <= '2')
distribute_re = re.compile('^distribute==[0-9.]+\n', re.MULTILINE)
@ -32,82 +34,82 @@ def _check_output(result, expected):
return '\n========== %s ==========\n' % msg
assert checker.check_output(expected, actual, ELLIPSIS), banner('EXPECTED')+expected+banner('ACTUAL')+actual+banner(6*'=')
if simplejson_works:
def test_freeze():
"""
Some tests of freeze, first we have to install some stuff. Note that
the test is a little crude at the end because Python 2.5+ adds egg
info to the standard library, so stuff like wsgiref will show up in
the freezing. (Probably that should be accounted for in pip, but
currently it is not).
def test_freeze():
"""
Some tests of freeze, first we have to install some stuff. Note that
the test is a little crude at the end because Python 2.5+ adds egg
info to the standard library, so stuff like wsgiref will show up in
the freezing. (Probably that should be accounted for in pip, but
currently it is not).
TODO: refactor this test into multiple tests? (and maybe different
test style instead of using doctest output checker)
TODO: refactor this test into multiple tests? (and maybe different
test style instead of using doctest output checker)
"""
env = reset_env()
write_file('initools-req.txt', textwrap.dedent("""\
INITools==0.2
# and something else to test out:
simplejson<=1.7.4
"""))
result = run_pip('install', '-r', env.scratch_path/'initools-req.txt')
result = run_pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: pip freeze
-- stdout: --------------------
INITools==0.2
simplejson==1.7.4...
<BLANKLINE>""")
_check_output(result, expected)
"""
env = reset_env()
write_file('initools-req.txt', textwrap.dedent("""\
INITools==0.2
# and something else to test out:
simplejson<=1.7.4
"""))
result = run_pip('install', '-r', env.scratch_path/'initools-req.txt')
result = run_pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: pip freeze
-- stdout: --------------------
INITools==0.2
simplejson==1.7.4...
<BLANKLINE>""")
_check_output(result, expected)
# Now lets try it with an svn checkout::
result = env.run('svn', 'co', '-r10',
local_repo('svn+http://svn.colorstudy.com/INITools/trunk'),
'initools-trunk')
result = env.run('python', 'setup.py', 'develop',
cwd=env.scratch_path/ 'initools-trunk')
result = run_pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
-e %s@10#egg=INITools-0.3.1dev_r10-py2...-dev_r10
simplejson==1.7.4...
<BLANKLINE>""" % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))
_check_output(result, expected)
# Now lets try it with an svn checkout::
result = env.run('svn', 'co', '-r10',
local_repo('svn+http://svn.colorstudy.com/INITools/trunk'),
'initools-trunk')
result = env.run('python', 'setup.py', 'develop',
cwd=env.scratch_path/ 'initools-trunk')
result = run_pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
-e %s@10#egg=INITools-0.3.1dev_r10-py2...-dev_r10
simplejson==1.7.4...
<BLANKLINE>""" % local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'))
_check_output(result, expected)
# Now, straight from trunk (but not editable/setup.py develop)::
result = env.run('svn', 'co',
local_repo('svn+http://svn.colorstudy.com/INITools/trunk'),
'initools_to_easy_install')
result = env.run('easy_install', env.scratch_path/'initools_to_easy_install')
result = run_pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stderr: --------------------
Warning: cannot find svn location for INITools==...dev-r...
<BLANKLINE>
-- stdout: --------------------
## FIXME: could not find svn URL in dependency_links for this package:
INITools==...dev-r...
simplejson==1.7.4...
<BLANKLINE>""")
_check_output(result, expected)
# Now, straight from trunk (but not editable/setup.py develop)::
result = env.run('svn', 'co',
local_repo('svn+http://svn.colorstudy.com/INITools/trunk'),
'initools_to_easy_install')
result = env.run('easy_install', env.scratch_path/'initools_to_easy_install')
result = run_pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stderr: --------------------
Warning: cannot find svn location for INITools==...dev-r...
<BLANKLINE>
-- stdout: --------------------
## FIXME: could not find svn URL in dependency_links for this package:
INITools==...dev-r...
simplejson==1.7.4...
<BLANKLINE>""")
_check_output(result, expected)
# Bah, that's no good! Let's give it a hint::
result = run_pip('freeze', '-f',
'%s#egg=INITools-dev' %
local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'),
expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze -f %(repo)s#egg=INITools-dev
-- stdout: --------------------
-f %(repo)s#egg=INITools-dev
# Installing as editable to satisfy requirement INITools==...dev-r...:
-e %(repo)s@...#egg=INITools-...dev_r...
simplejson==1.7.4...
<BLANKLINE>""" % {'repo': local_checkout('svn+http://svn.colorstudy.com/INITools/trunk')})
_check_output(result, expected)
# Bah, that's no good! Let's give it a hint::
result = run_pip('freeze', '-f',
'%s#egg=INITools-dev' %
local_checkout('svn+http://svn.colorstudy.com/INITools/trunk'),
expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze -f %(repo)s#egg=INITools-dev
-- stdout: --------------------
-f %(repo)s#egg=INITools-dev
# Installing as editable to satisfy requirement INITools==...dev-r...:
-e %(repo)s@...#egg=INITools-...dev_r...
simplejson==1.7.4...
<BLANKLINE>""" % {'repo': local_checkout('svn+http://svn.colorstudy.com/INITools/trunk')})
_check_output(result, expected)
def test_freeze_git_clone():
@ -122,22 +124,41 @@ def test_freeze_git_clone():
result = env.run('python', 'setup.py', 'develop',
cwd=env.scratch_path / 'django-pagination')
result = run_pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
-e %s@...#egg=django_pagination-...
...""" % local_checkout('git+http://github.com/jezdez/django-pagination.git'))
if pyversion >= '3':
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
distribute==0.6.15dev
-e %s@...#egg=django_pagination-...
wsgiref==0.1.2
...""" % local_checkout('git+http://github.com/jezdez/django-pagination.git'))
else:
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
-e %s@...#egg=django_pagination-...
...""" % local_checkout('git+http://github.com/jezdez/django-pagination.git'))
_check_output(result, expected)
result = run_pip('freeze', '-f',
'%s#egg=django_pagination' % local_checkout('git+http://github.com/jezdez/django-pagination.git'),
expect_stderr=True)
expected = textwrap.dedent("""\
Script result: pip freeze -f %(repo)s#egg=django_pagination
-- stdout: --------------------
-f %(repo)s#egg=django_pagination
-e %(repo)s@...#egg=django_pagination-dev
...""" % {'repo': local_checkout('git+http://github.com/jezdez/django-pagination.git')})
if pyversion >= '3':
expected = textwrap.dedent("""\
Script result: pip freeze -f %(repo)s#egg=django_pagination
-- stdout: --------------------
-f %(repo)s#egg=django_pagination
distribute==0.6.15dev
-e %(repo)s@...#egg=django_pagination-dev
wsgiref==0.1.2
...""" % {'repo': local_checkout('git+http://github.com/jezdez/django-pagination.git')})
else:
expected = textwrap.dedent("""\
Script result: pip freeze -f %(repo)s#egg=django_pagination
-- stdout: --------------------
-f %(repo)s#egg=django_pagination
-e %(repo)s@...#egg=django_pagination-dev
...""" % {'repo': local_checkout('git+http://github.com/jezdez/django-pagination.git')})
_check_output(result, expected)
@ -155,22 +176,41 @@ def test_freeze_mercurial_clone():
result = env.run('python', 'setup.py', 'develop',
cwd=env.scratch_path/'django-dbtemplates')
result = run_pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
-e %s@...#egg=django_dbtemplates-...
...""" % local_checkout('hg+http://bitbucket.org/jezdez/django-dbtemplates'))
if pyversion >= '3':
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
distribute==0.6.15dev
-e %s@...#egg=django_dbtemplates-...
wsgiref==0.1.2
...""" % local_checkout('hg+http://bitbucket.org/jezdez/django-dbtemplates'))
else:
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
-e %s@...#egg=django_dbtemplates-...
...""" % local_checkout('hg+http://bitbucket.org/jezdez/django-dbtemplates'))
_check_output(result, expected)
result = run_pip('freeze', '-f',
'%s#egg=django_dbtemplates' % local_checkout('hg+http://bitbucket.org/jezdez/django-dbtemplates'),
expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze -f %(repo)s#egg=django_dbtemplates
-- stdout: --------------------
-f %(repo)s#egg=django_dbtemplates
-e %(repo)s@...#egg=django_dbtemplates-dev
...""" % {'repo': local_checkout('hg+http://bitbucket.org/jezdez/django-dbtemplates')})
if pyversion >= '3':
expected = textwrap.dedent("""\
Script result: ...pip freeze -f %(repo)s#egg=django_dbtemplates
-- stdout: --------------------
-f %(repo)s#egg=django_dbtemplates
distribute==0.6.15dev
-e %(repo)s@...#egg=django_dbtemplates-dev
wsgiref==0.1.2
...""" % {'repo': local_checkout('hg+http://bitbucket.org/jezdez/django-dbtemplates')})
else:
expected = textwrap.dedent("""\
Script result: ...pip freeze -f %(repo)s#egg=django_dbtemplates
-- stdout: --------------------
-f %(repo)s#egg=django_dbtemplates
-e %(repo)s@...#egg=django_dbtemplates-dev
...""" % {'repo': local_checkout('hg+http://bitbucket.org/jezdez/django-dbtemplates')})
_check_output(result, expected)
@ -187,24 +227,44 @@ def test_freeze_bazaar_clone():
result = env.run('python', 'setup.py', 'develop',
cwd=env.scratch_path/'django-wikiapp')
result = run_pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
-e %s@...#egg=django_wikiapp-...
...""" % local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1'))
if pyversion >= '3':
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
distribute==0.6.15dev
-e %s@...#egg=django_wikiapp-...
wsgiref==0.1.2
...""" % local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1'))
else:
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
-e %s@...#egg=django_wikiapp-...
...""" % local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1'))
_check_output(result, expected)
result = run_pip('freeze', '-f',
'%s/#egg=django-wikiapp' %
local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1'),
expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze -f %(repo)s/#egg=django-wikiapp
-- stdout: --------------------
-f %(repo)s/#egg=django-wikiapp
-e %(repo)s@...#egg=django_wikiapp-...
...""" % {'repo':
local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1')})
if pyversion >= '3':
expected = textwrap.dedent("""\
Script result: ...pip freeze -f %(repo)s/#egg=django-wikiapp
-- stdout: --------------------
-f %(repo)s/#egg=django-wikiapp
distribute==0.6.15dev
-e %(repo)s@...#egg=django_wikiapp-...
wsgiref==0.1.2
...""" % {'repo':
local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1')})
else:
expected = textwrap.dedent("""\
Script result: ...pip freeze -f %(repo)s/#egg=django-wikiapp
-- stdout: --------------------
-f %(repo)s/#egg=django-wikiapp
-e %(repo)s@...#egg=django_wikiapp-...
...""" % {'repo':
local_checkout('bzr+http://bazaar.launchpad.net/%7Edjango-wikiapp/django-wikiapp/release-0.1')})
_check_output(result, expected)
@ -216,12 +276,21 @@ def test_freeze_with_local_option():
reset_env()
result = run_pip('install', 'initools==0.2')
result = run_pip('freeze', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
INITools==0.2
wsgiref==...
<BLANKLINE>""")
if pyversion >= '3':
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
INITools==0.2
distribute==0.6.15dev
wsgiref==...
<BLANKLINE>""")
else:
expected = textwrap.dedent("""\
Script result: ...pip freeze
-- stdout: --------------------
INITools==0.2
wsgiref==...
<BLANKLINE>""")
# The following check is broken (see
# http://bitbucket.org/ianb/pip/issue/110). For now we are simply
@ -231,9 +300,17 @@ def test_freeze_with_local_option():
# _check_output(result, expected)
result = run_pip('freeze', '--local', expect_stderr=True)
expected = textwrap.dedent("""\
Script result: ...pip freeze --local
-- stdout: --------------------
INITools==0.2
<BLANKLINE>""")
if pyversion >= '3':
expected = textwrap.dedent("""\
Script result: ...pip freeze --local
-- stdout: --------------------
INITools==0.2
distribute==0.6.15dev
<BLANKLINE>""")
else:
expected = textwrap.dedent("""\
Script result: ...pip freeze --local
-- stdout: --------------------
INITools==0.2
<BLANKLINE>""")
_check_output(result, expected)

View File

@ -6,12 +6,16 @@ import shutil
import glob
import atexit
import textwrap
import urllib
from scripttest import TestFileEnvironment
from path import Path, curdir
from pip.backwardcompat import urllib
from tests.path import Path, curdir, u
pyversion = sys.version[:3]
# Used for Python 3 local repo with Python-3 compatible stuff
#LOCAL_PYPI_ARGS = ['-i', 'http://localhost:8000/']
LOCAL_PYPI_ARGS = []
# the directory containing all the tests
here = Path(__file__).abspath.folder
@ -81,7 +85,7 @@ except NameError:
def clear_environ(environ):
return dict(((k, v) for k, v in environ.iteritems()
return dict(((k, v) for k, v in environ.items()
if not k.lower().startswith('pip_')))
@ -105,7 +109,7 @@ env = None
def reset_env(environ=None):
global env
env = TestPipEnvironment(environ)
env = FastTestPipEnvironment(environ)
return env
@ -137,11 +141,11 @@ class TestPipResult(object):
self._impl = impl
if verbose:
print self.stdout
print(self.stdout)
if self.stderr:
print '======= stderr ========'
print self.stderr
print '======================='
print('======= stderr ========')
print(self.stderr)
print('=======================')
def __getattr__(self, attr):
return getattr(self._impl, attr)
@ -187,15 +191,15 @@ class TestPipResult(object):
if not (# FIXME: I don't understand why there's a trailing . here
egg_link_file.bytes.endswith('.')
and egg_link_file.bytes[:-1].strip().endswith(pkg_dir)):
raise TestFailure(textwrap.dedent(u'''\
raise TestFailure(textwrap.dedent(u('''\
Incorrect egg_link file %r
Expected ending: %r
------- Actual contents -------
%s
-------------------------------''' % (
egg_link_file,
pkg_dir + u'\n.',
egg_link_file.bytes)))
pkg_dir + u('\n.'),
egg_link_file.bytes))))
if use_user_site:
pth_file = Path.string(e.user_site / 'easy-install.pth')
@ -268,7 +272,7 @@ class TestPipEnvironment(TestFileEnvironment):
if not environ:
environ = os.environ.copy()
environ = clear_environ(environ)
environ['PIP_DOWNLOAD_CACHE'] = download_cache
environ['PIP_DOWNLOAD_CACHE'] = str(download_cache)
environ['PIP_NO_INPUT'] = '1'
environ['PIP_LOG_FILE'] = str(self.root_path/'pip-log.txt')
@ -309,7 +313,7 @@ class TestPipEnvironment(TestFileEnvironment):
self.environ['PATH'] = Path.pathsep.join((self.bin_path, self.environ['PATH']))
# test that test-scratch virtualenv creation produced sensible venv python
result = self.run('python', '-c', 'import sys; print sys.executable')
result = self.run('python', '-c', 'import sys; print(sys.executable)')
pythonbin = result.stdout.strip()
if Path(pythonbin).noext != self.bin_path/'python':
@ -325,16 +329,23 @@ class TestPipEnvironment(TestFileEnvironment):
# Earlier versions of pip were incapable of
# self-uninstallation on Windows, so we use the one we're testing.
self.run('python', '-c',
'import sys;sys.path.insert(0, %r);import pip;sys.exit(pip.main());' % os.path.dirname(here),
'"import sys; sys.path.insert(0, %r); import pip; sys.exit(pip.main());"' % os.path.dirname(here),
'uninstall', '-vvv', '-y', 'pip')
# Install this version instead
self.run('python', 'setup.py', 'install', cwd=src_folder, expect_stderr=True)
self._use_cached_pypi_server()
def _ignore_file(self, fn):
if fn.endswith('__pycache__'):
result = True
else:
result = super(TestPipEnvironment, self)._ignore_file(fn)
return result
def run(self, *args, **kw):
if self.verbose:
print '>> running', args, kw
print('>> running %s %s' % (args, kw))
cwd = kw.pop('cwd', None)
run_from = kw.pop('run_from', None)
assert not cwd or not run_from, "Don't use run_from; it's going away"
@ -354,9 +365,109 @@ class TestPipEnvironment(TestFileEnvironment):
pth.write('sys.path.remove(%r); ' % str(here))
pth.close()
class FastTestPipEnvironment(TestPipEnvironment):
def __init__(self, environ=None):
import virtualenv
self.root_path = here / 'test_ws'
self.backup_path = here / 'test_ws_backup'
self.scratch_path = self.root_path / self.scratch
# We will set up a virtual environment at root_path.
self.venv_path = self.root_path / self.venv
if not environ:
environ = os.environ.copy()
environ = clear_environ(environ)
environ['PIP_DOWNLOAD_CACHE'] = str(download_cache)
environ['PIP_NO_INPUT'] = '1'
environ['PIP_LOG_FILE'] = str(self.root_path/'pip-log.txt')
TestFileEnvironment.__init__(self,
self.root_path, ignore_hidden=False,
environ=environ, split_cmd=False, start_clear=False,
cwd=self.scratch_path, capture_temp=True, assert_no_temp=True)
virtualenv_paths = virtualenv.path_locations(self.venv_path)
for id, path in zip(('venv', 'lib', 'include', 'bin'), virtualenv_paths):
setattr(self, id+'_path', Path(path))
setattr(self, id, relpath(self.root_path, path))
assert self.venv == TestPipEnvironment.venv # sanity check
self.site_packages = self.lib/'site-packages'
self.user_base_path = self.venv_path/'user'
self.user_site_path = self.venv_path/'user'/'lib'/self.lib.name/'site-packages'
self.user_site = relpath(self.root_path, self.user_site_path)
self.environ["PYTHONUSERBASE"] = self.user_base_path
# put the test-scratch virtualenv's bin dir first on the PATH
self.environ['PATH'] = Path.pathsep.join((self.bin_path, self.environ['PATH']))
if self.root_path.exists:
shutil.rmtree(self.root_path)
if self.backup_path.exists:
shutil.copytree(self.backup_path, self.root_path, True)
else:
demand_dirs(self.venv_path)
demand_dirs(self.scratch_path)
use_distribute = os.environ.get('PIP_TEST_USE_DISTRIBUTE', False)
# Create a virtualenv and remember where it's putting things.
create_virtualenv(self.venv_path, distribute=use_distribute)
demand_dirs(self.user_site_path)
# create easy-install.pth in user_site, so we always have it updated instead of created
open(self.user_site_path/'easy-install.pth', 'w').close()
# test that test-scratch virtualenv creation produced sensible venv python
result = self.run('python', '-c', 'import sys; print(sys.executable)')
pythonbin = result.stdout.strip()
if Path(pythonbin).noext != self.bin_path/'python':
raise RuntimeError(
"Oops! 'python' in our test environment runs %r"
" rather than expected %r" % (pythonbin, self.bin_path/'python'))
# make sure we have current setuptools to avoid svn incompatibilities
if not use_distribute:
install_setuptools(self)
# Uninstall whatever version of pip came with the virtualenv.
# Earlier versions of pip were incapable of
# self-uninstallation on Windows, so we use the one we're testing.
self.run('python', '-c',
'"import sys; sys.path.insert(0, %r); import pip; sys.exit(pip.main());"' % os.path.dirname(here),
'uninstall', '-vvv', '-y', 'pip')
# Install this version instead
self.run('python', 'setup.py', 'install', cwd=src_folder, expect_stderr=True)
shutil.copytree(self.root_path, self.backup_path, True)
self._use_cached_pypi_server()
assert self.root_path.exists
def __del__(self):
pass # shutil.rmtree(str(self.root_path), ignore_errors=True)
def run_pip(*args, **kw):
return env.run('pip', *args, **kw)
result = env.run('pip', *args, **kw)
ignore = []
for path, f in result.files_before.items():
if path in result.files_updated:
full_path = env.base_path / path
s = str(full_path)
if os.path.isdir(s) and '__pycache__' in os.listdir(s):
ignore.append(path)
for path in ignore:
del result.files_updated[path]
return result
def write_file(filename, text, dest=None):
@ -452,7 +563,7 @@ def assert_all_changes(start_state, end_state, expected_changes):
end_files = end_state.files_after
diff = diff_states(start_files, end_files, ignore=expected_changes)
if diff.values() != [{}, {}, {}]:
if list(diff.values()) != [{}, {}, {}]:
raise TestFailure('Unexpected changes:\n' + '\n'.join(
[k + ': ' + ', '.join(v.keys()) for k, v in diff.items()]))

View File

@ -13,10 +13,11 @@ import os
import pip
import getpass
from pip.basecommand import get_proxy
from test_pip import here
from tests.test_pip import here
def new_getpass(prompt, answer='passwd'):
print '%s%s' % (prompt, answer)
print('%s%s' % (prompt, answer))
return answer

View File

@ -1,25 +1,29 @@
import textwrap
from pip.req import Requirements
from test_pip import reset_env, run_pip, write_file, pyversion
from local_repos import local_checkout
from tests.test_pip import reset_env, run_pip, write_file, pyversion
from tests.local_repos import local_checkout
def test_requirements_file():
"""
Test installing from a requirements file.
"""
if pyversion >= '3':
other_lib_name, other_lib_version = 'anyjson', '0.3'
else:
other_lib_name, other_lib_version = 'simplejson', '1.7.4'
env = reset_env()
write_file('initools-req.txt', textwrap.dedent("""\
INITools==0.2
# and something else to test out:
simplejson<=1.7.4
"""))
%s<=%s
""" % (other_lib_name, other_lib_version)))
result = run_pip('install', '-r', env.scratch_path / 'initools-req.txt')
assert env.site_packages/'INITools-0.2-py%s.egg-info' % pyversion in result.files_created
assert env.site_packages/'initools' in result.files_created
assert result.files_created[env.site_packages/'simplejson'].dir
assert result.files_created[env.site_packages/'simplejson-1.7.4-py%s.egg-info' % pyversion].dir
assert result.files_created[env.site_packages/other_lib_name].dir
fn = '%s-%s-py%s.egg-info' % (other_lib_name, other_lib_version, pyversion)
assert result.files_created[env.site_packages/fn].dir
def test_multiple_requirements_files():
@ -27,16 +31,22 @@ def test_multiple_requirements_files():
Test installing from multiple nested requirements files.
"""
if pyversion >= '3':
other_lib_name, other_lib_version = 'anyjson', '0.3'
else:
other_lib_name, other_lib_version = 'simplejson', '1.7.4'
env = reset_env()
write_file('initools-req.txt', textwrap.dedent("""\
-e %s@10#egg=INITools-dev
-r simplejson-req.txt""" % local_checkout('http://svn.colorstudy.com/INITools/trunk')))
write_file('simplejson-req.txt', textwrap.dedent("""\
simplejson<=1.7.4
"""))
-r %s-req.txt""" % (local_checkout('http://svn.colorstudy.com/INITools/trunk'),
other_lib_name)))
write_file('%s-req.txt' % other_lib_name, textwrap.dedent("""\
%s<=%s
""" % (other_lib_name, other_lib_version)))
result = run_pip('install', '-r', env.scratch_path / 'initools-req.txt')
assert result.files_created[env.site_packages/'simplejson'].dir
assert result.files_created[env.site_packages/'simplejson-1.7.4-py%s.egg-info' % pyversion].dir
assert result.files_created[env.site_packages/other_lib_name].dir
fn = '%s-%s-py%s.egg-info' % (other_lib_name, other_lib_version, pyversion)
assert result.files_created[env.site_packages/fn].dir
assert env.venv/'src'/'initools' in result.files_created
@ -65,8 +75,8 @@ def test_requirements_data_structure_keeps_order():
requirements['nose'] = 'nose'
requirements['coverage'] = 'coverage'
assert ['pip', 'nose', 'coverage'] == requirements.values()
assert ['pip', 'nose', 'coverage'] == requirements.keys()
assert ['pip', 'nose', 'coverage'] == list(requirements.values())
assert ['pip', 'nose', 'coverage'] == list(requirements.keys())
def test_requirements_data_structure_implements__repr__():
requirements = Requirements()

View File

@ -1,11 +1,18 @@
import xmlrpclib
import pip.download
from pip.commands.search import (compare_versions,
highest_version,
transform_hits,
SearchCommand,)
from pip.backwardcompat import xmlrpclib, b
from mock import Mock
from test_pip import run_pip, reset_env
from tests.test_pip import run_pip, reset_env, pyversion
from tests.pypi_server import assert_equal
if pyversion >= '3':
VERBOSE_FALSE = False
else:
VERBOSE_FALSE = 0
def test_version_compare():
@ -30,7 +37,7 @@ def test_pypi_xml_transformation():
{'_pypi_ordering': 50, 'name': 'bar', 'summary': 'bar summary', 'version': '1.0'}]
expected = [{'score': 200, 'versions': ['1.0', '2.0'], 'name': 'foo', 'summary': 'foo summary v2'},
{'score': 50, 'versions': ['1.0'], 'name': 'bar', 'summary': 'bar summary'}]
assert expected == transform_hits(pypi_hits)
assert_equal(expected, transform_hits(pypi_hits))
def test_search():
@ -49,10 +56,10 @@ def test_searching_through_Search_class():
"""
pip.download.xmlrpclib_transport = fake_transport = Mock()
query = 'mylittlequerythatdoesnotexists'
dumped_xmlrpc_request = xmlrpclib.dumps(({'name': query, 'summary': query}, 'or'), 'search')
dumped_xmlrpc_request = b(xmlrpclib.dumps(({'name': query, 'summary': query}, 'or'), 'search'))
expected = [{'_pypi_ordering': 100, 'name': 'foo', 'summary': 'foo summary', 'version': '1.0'}]
fake_transport.request.return_value = (expected,)
pypi_searcher = SearchCommand()
result = pypi_searcher.search(query, 'http://pypi.python.org/pypi')
assert expected == result, result
fake_transport.request.assert_called_with('pypi.python.org', '/pypi', dumped_xmlrpc_request, verbose=0)
fake_transport.request.assert_called_with('pypi.python.org', '/pypi', dumped_xmlrpc_request, verbose=VERBOSE_FALSE)

View File

@ -3,8 +3,9 @@ import sys
import shutil
from os.path import join
from tempfile import mkdtemp
from test_pip import reset_env, run_pip, assert_all_changes, write_file
from local_repos import local_repo, local_checkout
from tests.test_pip import (reset_env, run_pip, assert_all_changes, write_file,
pyversion, LOCAL_PYPI_ARGS)
from tests.local_repos import local_repo, local_checkout
def test_simple_uninstall():
@ -53,7 +54,11 @@ def test_uninstall_console_scripts():
"""
env = reset_env()
result = run_pip('install', 'virtualenv', expect_error=True)
args = ['install']
if pyversion >= '3':
args.extend(LOCAL_PYPI_ARGS)
args.append('virtualenv')
result = run_pip(*args, expect_error=True)
assert env.bin/'virtualenv'+env.exe in result.files_created, sorted(result.files_created.keys())
result2 = run_pip('uninstall', 'virtualenv', '-y', expect_error=True)
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
@ -65,7 +70,11 @@ def test_uninstall_easy_installed_console_scripts():
"""
env = reset_env()
result = env.run('easy_install', 'virtualenv', expect_stderr=True)
args = ['easy_install']
if pyversion >= '3':
args.extend(LOCAL_PYPI_ARGS)
args.append('virtualenv')
result = env.run(*args, expect_stderr=True)
assert env.bin/'virtualenv'+env.exe in result.files_created, sorted(result.files_created.keys())
result2 = run_pip('uninstall', 'virtualenv', '-y')
assert_all_changes(result, result2, [env.venv/'build', 'cache'])
@ -102,7 +111,7 @@ def _test_uninstall_editable_with_source_outside_venv(tmpdir):
env = reset_env()
result = env.run('hg', 'clone', local_repo('hg+http://bitbucket.org/ianb/virtualenv'), tmpdir)
result2 = run_pip('install', '-e', tmpdir)
assert (join(env.site_packages, 'virtualenv.egg-link') in result2.files_created), result2.files_created.keys()
assert (join(env.site_packages, 'virtualenv.egg-link') in result2.files_created), list(result2.files_created.keys())
result3 = run_pip('uninstall', '-y', 'virtualenv', expect_error=True)
assert_all_changes(result, result3, [env.venv/'build'])

View File

@ -1,7 +1,8 @@
import textwrap
from test_pip import (here, reset_env, run_pip, assert_all_changes,
write_file, _create_test_package,
_change_test_package_version, pyversion)
from os.path import join
from tests.test_pip import (here, reset_env, run_pip, assert_all_changes,
write_file, pyversion, _create_test_package,
_change_test_package_version)
def test_no_upgrade_unless_requested():
@ -109,13 +110,12 @@ def test_uninstall_rollback():
"""
env = reset_env()
find_links = 'file://' + here/'packages'
find_links = 'file://' + join(here, 'packages')
result = run_pip('install', '-f', find_links, '--no-index', 'broken==0.1')
assert env.site_packages / 'broken.py' in result.files_created, result.files_created.keys()
assert env.site_packages / 'broken.py' in result.files_created, list(result.files_created.keys())
result2 = run_pip('install', '-f', find_links, '--no-index', 'broken==0.2broken', expect_error=True)
assert result2.returncode == 1, str(result2)
env.run('python', '-c', "import broken; print broken.VERSION").stdout
'0.1\n'
assert env.run('python', '-c', "import broken; print(broken.VERSION)").stdout == '0.1\n'
assert_all_changes(result.files_after, result2, [env.venv/'build', 'pip-log.txt'])

View File

@ -1,7 +1,6 @@
from test_pip import (reset_env, run_pip, pyversion,
from tests.test_pip import (reset_env, run_pip, pyversion,
_create_test_package, _change_test_package_version)
from local_repos import local_checkout
from tests.local_repos import local_checkout
def test_install_editable_from_git_with_https():
"""