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

Remove unnecessary imports, move some to six #1854

Merged
merged 1 commit into from
Jun 16, 2014
Merged
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
5 changes: 3 additions & 2 deletions pip/baseparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import textwrap
from distutils.util import strtobool

from pip.compat import ConfigParser, string_types
from pip._vendor.six import string_types
from pip._vendor.six.moves import configparser
from pip.locations import (
default_config_file, default_config_basename, running_under_virtualenv,
)
Expand Down Expand Up @@ -128,7 +129,7 @@ class ConfigOptionParser(CustomOptionParser):
configuration files and environmental variables"""

def __init__(self, *args, **kwargs):
self.config = ConfigParser.RawConfigParser()
self.config = configparser.RawConfigParser()
self.name = kwargs.pop('name')
self.files = self.get_config_files()
if self.files:
Expand Down
5 changes: 3 additions & 2 deletions pip/commands/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
from pip.basecommand import Command, SUCCESS
from pip.util import get_terminal_size
from pip.log import logger
from pip.compat import xmlrpclib, reduce, cmp
from pip.compat import reduce, cmp
from pip.exceptions import CommandError
from pip.status_codes import NO_MATCHES_FOUND
from pip._vendor import pkg_resources
from pip._vendor.six.moves import xmlrpc_client
from distutils.version import StrictVersion, LooseVersion


Expand Down Expand Up @@ -48,7 +49,7 @@ def run(self, options, args):
return NO_MATCHES_FOUND

def search(self, query, index_url):
pypi = xmlrpclib.ServerProxy(index_url)
pypi = xmlrpc_client.ServerProxy(index_url)
hits = pypi.search({'name': query, 'summary': query}, 'or')
return hits

Expand Down
19 changes: 1 addition & 18 deletions pip/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,13 @@ def binary(s):


if sys.version_info >= (3,):
from io import StringIO, BytesIO
from io import StringIO
from functools import reduce
from urllib.error import URLError, HTTPError
from queue import Queue, Empty
from urllib.request import url2pathname, urlretrieve, pathname2url
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)
Expand All @@ -75,21 +70,13 @@ def console_to_str(s):
def get_http_message_param(http_message, param, default_value):
return http_message.get_param(param, default_value)

bytes = bytes
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, pathname2url
from email import Message as emailmessage
import urllib
import urllib2
import urlparse
import ConfigParser
import xmlrpclib
import httplib

def b(s):
return s
Expand All @@ -104,12 +91,8 @@ def get_http_message_param(http_message, param, default_value):
result = http_message.getparam(param)
return result or default_value

bytes = str
string_types = (basestring,)
reduce = reduce
cmp = cmp
raw_input = raw_input
BytesIO = StringIO


def get_path_uid(path):
Expand Down
4 changes: 2 additions & 2 deletions pip/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import pip

from pip.compat import urllib, urlparse, raw_input
from pip.compat import urllib, urlparse
from pip.exceptions import InstallationError, HashMismatch
from pip.util import (splitext, rmtree, format_size, display_path,
backup_dir, ask_path_exists, unpack_file)
Expand Down Expand Up @@ -117,7 +117,7 @@ def handle_401(self, resp, **kwargs):
parsed = urlparse.urlparse(resp.url)

# Prompt the user for a new username and password
username = raw_input("User for %s: " % parsed.netloc)
username = six.moves.input("User for %s: " % parsed.netloc)
password = getpass.getpass("Password: ")

# Store the new username and password to use for future requests
Expand Down
13 changes: 6 additions & 7 deletions pip/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

import pip.wheel
from pip._vendor import pkg_resources, six
from pip.compat import (
urllib, ConfigParser, string_types,
)
from pip._vendor.six.moves import configparser
from pip.compat import urllib
from pip.download import is_url, url_to_path, path_to_url, is_archive_file
from pip.exceptions import (
InstallationError, UninstallationError, UnsupportedWheel,
Expand All @@ -38,7 +37,7 @@ def __init__(self, req, comes_from, source_dir=None, editable=False,
url=None, as_egg=False, update=True, prereleases=None,
editable_options=None, pycompile=True):
self.extras = ()
if isinstance(req, string_types):
if isinstance(req, six.string_types):
req = pkg_resources.Requirement.parse(req)
self.extras = req.extras
self.req = req
Expand Down Expand Up @@ -168,7 +167,7 @@ def __str__(self):
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, string_types):
if isinstance(self.comes_from, six.string_types):
comes_from = self.comes_from
else:
comes_from = self.comes_from.from_path()
Expand All @@ -181,7 +180,7 @@ def from_path(self):
return None
s = str(self.req)
if self.comes_from:
if isinstance(self.comes_from, string_types):
if isinstance(self.comes_from, six.string_types):
comes_from = self.comes_from
else:
comes_from = self.comes_from.from_path()
Expand Down Expand Up @@ -619,7 +618,7 @@ def uninstall(self, auto_confirm=False):

# find console_scripts
if dist.has_metadata('entry_points.txt'):
config = ConfigParser.SafeConfigParser()
config = configparser.SafeConfigParser()
config.readfp(
FakeFile(dist.get_metadata_lines('entry_points.txt'))
)
Expand Down
9 changes: 5 additions & 4 deletions pip/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@

from pip.exceptions import InstallationError, BadCommand
from pip.compat import(
string_types, raw_input, console_to_str, stdlib_pkgs
console_to_str, stdlib_pkgs
)
from pip.locations import (
site_packages, user_site, running_under_virtualenv, virtualenv_no_global,
write_delete_marker_file
)
from pip.log import logger
from pip._vendor import pkg_resources
from pip._vendor import pkg_resources, six
from pip._vendor.distlib import version
from pip._vendor.six.moves import input

__all__ = ['rmtree', 'display_path', 'backup_dir',
'find_command', 'ask', 'Inf',
Expand Down Expand Up @@ -85,7 +86,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, string_types):
if isinstance(paths, six.string_types):
paths = [paths]
# check if there are funny path extensions for executables, e.g. Windows
if pathext is None:
Expand Down Expand Up @@ -131,7 +132,7 @@ def ask(message, options):
'No input was expected ($PIP_NO_INPUT set); question: %s' %
message
)
response = raw_input(message)
response = input(message)
response = response.strip().lower()
if response not in options:
print(
Expand Down
6 changes: 3 additions & 3 deletions pip/vcs/mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pip.log import logger
from pip.vcs import vcs, VersionControl
from pip.download import path_to_url
from pip.compat import ConfigParser
from pip._vendor.six.moves import configparser


class Mercurial(VersionControl):
Expand All @@ -29,14 +29,14 @@ def export(self, location):

def switch(self, dest, url, rev_options):
repo_config = os.path.join(dest, self.dirname, 'hgrc')
config = ConfigParser.SafeConfigParser()
config = configparser.SafeConfigParser()
try:
config.read(repo_config)
config.set('paths', 'default', url)
config_file = open(repo_config, 'w')
config.write(config_file)
config_file.close()
except (OSError, ConfigParser.NoSectionError) as exc:
except (OSError, configparser.NoSectionError) as exc:
logger.warn(
'Could not switch Mercurial repository to %s: %s'
% (url, exc))
Expand Down
5 changes: 3 additions & 2 deletions pip/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
from base64 import urlsafe_b64encode
from email.parser import Parser

from pip.compat import ConfigParser, StringIO, binary
from pip.compat import StringIO, binary
from pip.exceptions import InvalidWheelFilename, UnsupportedWheel
from pip.locations import distutils_scheme
from pip.log import logger
from pip import pep425tags
from pip.util import call_subprocess, normalize_path, make_path_relative
from pip._vendor.distlib.scripts import ScriptMaker
from pip._vendor import pkg_resources
from pip._vendor.six.moves import configparser


wheel_ext = '.whl'
Expand Down Expand Up @@ -114,7 +115,7 @@ def get_entrypoints(filename):
data.write("\n")
data.seek(0)

cp = ConfigParser.RawConfigParser()
cp = configparser.RawConfigParser()
cp.readfp(data)

console = {}
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_download.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import hashlib
import os
from io import BytesIO
from shutil import rmtree, copy
from tempfile import mkdtemp

from mock import Mock, patch
import pytest

import pip
from pip.compat import BytesIO, b, pathname2url
from pip.compat import b, pathname2url
from pip.exceptions import HashMismatch
from pip.download import (
PipSession, SafeFileCache, path_to_url, unpack_http_url, url_to_path,
Expand Down