Skip to content

Commit

Permalink
Fix whitespace, etc for pep8 compliance
Browse files Browse the repository at this point in the history
Reran tests after changes on 2.4, 2.6, 3.2 all pass.

=====================================================
================== Running pep8 =====================

Searching for pep8
Reading http://pypi.python.org/simple/pep8/
Reading http://github.com/cburroughs/pep8.py/tree/master
Reading http://github.com/jcrocholl/pep8
Best match: pep8 0.6.1
Processing pep8-0.6.1-py2.6.egg
pep8 0.6.1 is already the active version in easy-install.pth
Installing pep8 script to /Users/pnasrat/Development/pip/pip_virtualenv/bin

Using /Users/pnasrat/Development/pip/pip_virtualenv/lib/python2.6/site-packages/pep8-0.6.1-py2.6.egg
Processing dependencies for pep8
Finished processing dependencies for pep8

==================== Ended pep8 =====================
=====================================================
  • Loading branch information
pnasrat committed May 4, 2011
1 parent 3b4f620 commit 2860dc7
Show file tree
Hide file tree
Showing 24 changed files with 78 additions and 30 deletions.
3 changes: 2 additions & 1 deletion contrib/get-pip.py
Expand Up @@ -1106,6 +1106,7 @@
import tempfile
import shutil


def unpack(sources):
temp_dir = tempfile.mkdtemp('-scratchdir', 'unpacker-')
for package, content in sources.items():
Expand All @@ -1122,7 +1123,7 @@ def unpack(sources):
return temp_dir

if __name__ == "__main__":
if sys.version_info >= (3,0):
if sys.version_info >= (3, 0):
exec("def do_exec(co, loc): exec(co, loc)\n")
import pickle
sources = sources.encode("ascii") # ensure bytes
Expand Down
3 changes: 3 additions & 0 deletions contrib/packager/__init__.py
Expand Up @@ -8,6 +8,7 @@
import os
import fnmatch


def find_toplevel(name):
for syspath in sys.path:
lib = os.path.join(syspath, name)
Expand All @@ -18,10 +19,12 @@ def find_toplevel(name):
return mod
raise LookupError(name)


def pkgname(toplevel, rootpath, path):
parts = path.split(os.sep)[len(rootpath.split(os.sep)):]
return '.'.join([toplevel] + [os.path.splitext(x)[0] for x in parts])


def pkg_to_mapping(name):
toplevel = find_toplevel(name)
if os.path.isfile(toplevel):
Expand Down
4 changes: 3 additions & 1 deletion contrib/packager/template.py
Expand Up @@ -10,6 +10,7 @@
import tempfile
import shutil


def unpack(sources):
temp_dir = tempfile.mkdtemp('-scratchdir', 'unpacker-')
for package, content in sources.items():
Expand All @@ -25,8 +26,9 @@ def unpack(sources):
mod.close()
return temp_dir


if __name__ == "__main__":
if sys.version_info >= (3,0):
if sys.version_info >= (3, 0):
exec("def do_exec(co, loc): exec(co, loc)\n")
import pickle
sources = sources.encode("ascii") # ensure bytes
Expand Down
1 change: 1 addition & 0 deletions pip/__init__.py
Expand Up @@ -115,6 +115,7 @@ def main(initial_args=None):
command = command_dict[command]
return command.main(initial_args, args[1:], options)


def bootstrap():
"""
Bootstrapping function to be called from install-pip.py script.
Expand Down
8 changes: 8 additions & 0 deletions pip/backwardcompat.py
Expand Up @@ -50,12 +50,16 @@ def any(seq):
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')

def console_to_str(s):
return s.decode(console_encoding)
bytes = bytes
Expand All @@ -73,10 +77,13 @@ def console_to_str(s):
import ConfigParser
import xmlrpclib
import httplib

def b(s):
return s

def u(s):
return s

def console_to_str(s):
return s
bytes = str
Expand All @@ -93,6 +100,7 @@ def console_to_str(s):

from distutils.sysconfig import get_python_lib, get_python_version


def copytree(src, dst):
if sys.version_info < (2, 5):
before_last_dir = os.path.dirname(dst)
Expand Down
2 changes: 0 additions & 2 deletions pip/basecommand.py
Expand Up @@ -154,8 +154,6 @@ def main(self, complete_args, args, initial_options):
return exit




def format_exc(exc_info=None):
if exc_info is None:
exc_info = sys.exc_info()
Expand Down
3 changes: 2 additions & 1 deletion pip/commands/install.py
@@ -1,4 +1,5 @@
import os, sys
import os
import sys
from pip.req import InstallRequirement, RequirementSet
from pip.req import parse_requirements
from pip.log import logger
Expand Down
1 change: 1 addition & 0 deletions pip/commands/uninstall.py
Expand Up @@ -2,6 +2,7 @@
from pip.basecommand import Command
from pip.exceptions import InstallationError


class UninstallCommand(Command):
name = 'uninstall'
usage = '%prog [OPTIONS] PACKAGE_NAMES ...'
Expand Down
1 change: 1 addition & 0 deletions pip/download.py
Expand Up @@ -64,6 +64,7 @@ def get_file_content(url, comes_from=None):
_scheme_re = re.compile(r'^(http|https|file):', re.I)
_url_slash_drive_re = re.compile(r'/*([a-z])\|', re.I)


class URLOpener(object):
"""
pip's own URL helper that adds HTTP auth and proxy support
Expand Down
14 changes: 7 additions & 7 deletions pip/req.py
Expand Up @@ -91,15 +91,15 @@ def from_line(cls, name, comes_from=None):
# If the line has an egg= definition, but isn't editable, pull the requirement out.
# Otherwise, assume the name is the req for the non URL/path/archive case.
if link and req is None:
url = link.url_fragment
req = link.egg_fragment
url = link.url_fragment
req = link.egg_fragment

# Handle relative file URLs
if link.scheme == 'file' and re.search(r'\.\./', url):
url = path_to_url(os.path.normpath(os.path.abspath(link.path)))
# Handle relative file URLs
if link.scheme == 'file' and re.search(r'\.\./', url):
url = path_to_url(os.path.normpath(os.path.abspath(link.path)))

else:
req = name
req = name

return cls(req, comes_from, url=url)

Expand Down Expand Up @@ -768,7 +768,7 @@ def __getitem__(self, key):
return self._dict[key]

def __repr__(self):
values = [ '%s: %s' % (repr(k), repr(self[k])) for k in self.keys() ]
values = ['%s: %s' % (repr(k), repr(self[k])) for k in self.keys()]
return 'Requirements({%s})' % ', '.join(values)


Expand Down
3 changes: 2 additions & 1 deletion pip/util.py
Expand Up @@ -98,10 +98,11 @@ def find_command(cmd, paths=None, pathext=None):
def get_pathext(default_pathext=None):
"""Returns the path extensions from environment or a default"""
if default_pathext is None:
default_pathext = os.pathsep.join([ '.COM', '.EXE', '.BAT', '.CMD' ])
default_pathext = os.pathsep.join(['.COM', '.EXE', '.BAT', '.CMD'])
pathext = os.environ.get('PATHEXT', default_pathext)
return pathext


def ask(message, options):
"""Ask the message interactively, with the given possible responses"""
while 1:
Expand Down
1 change: 0 additions & 1 deletion pip/vcs/bazaar.py
Expand Up @@ -18,7 +18,6 @@ class Bazaar(VersionControl):
guide = ('# This was a Bazaar branch; to make it a branch again run:\n'
'bzr branch -r %(rev)s %(url)s .\n')


def __init__(self, url=None, *args, **kwargs):
super(Bazaar, self).__init__(url, *args, **kwargs)
urlparse.non_hierarchical.extend(['lp'])
Expand Down
1 change: 1 addition & 0 deletions pip/vcs/git.py
Expand Up @@ -8,6 +8,7 @@
urlsplit = urlparse.urlsplit
urlunsplit = urlparse.urlunsplit


class Git(VersionControl):
name = 'git'
dirname = '.git'
Expand Down
3 changes: 2 additions & 1 deletion tests/path.py
Expand Up @@ -15,6 +15,7 @@

from pip.util import rmtree


class Path(_base):
""" Models a path in an object oriented way. """

Expand All @@ -32,7 +33,7 @@ def __div__(self, path):
""" path_obj / 'bc.d' """
""" path_obj / path_obj2 """
return Path(self, path)

__truediv__ = __div__

def __rdiv__(self, path):
Expand Down
36 changes: 23 additions & 13 deletions tests/test_basic.py
Expand Up @@ -17,6 +17,7 @@
from tests.local_repos import local_checkout
from tests.path import Path


def test_correct_pip_version():
"""
Check we are running proper version of pip in run_pip.
Expand Down Expand Up @@ -388,6 +389,7 @@ def test_install_subversion_usersite_editable_with_setuptools_fails():
expect_error=True)
assert '--user --editable not supported with setuptools, use distribute' in result.stdout


def test_install_pardir():
"""
Test installing parent directory ('..').
Expand Down Expand Up @@ -419,6 +421,7 @@ def test_install_with_pax_header():
run_from = abspath(join(here, 'packages'))
run_pip('install', 'paxpkg.tar.bz2', cwd=run_from)


def test_install_using_install_option_and_editable():
"""
Test installing a tool using -e and --install-option
Expand Down Expand Up @@ -502,6 +505,7 @@ def test_install_folder_using_relative_path():
egg_folder = env.site_packages / 'mock-100.1-py%s.egg-info' % pyversion
assert egg_folder in result.files_created, str(result)


def test_install_package_which_contains_dev_in_name():
"""
Test installing package from pypi which contains 'dev' in name
Expand All @@ -513,37 +517,42 @@ def test_install_package_which_contains_dev_in_name():
assert devserver_folder in result.files_created, str(result.stdout)
assert egg_info_folder in result.files_created, str(result)


def test_find_command_folder_in_path():
"""
If a folder named e.g. 'git' is in PATH, and find_command is looking for
the 'git' executable, it should not match the folder, but rather keep
looking.
"""
env = reset_env()
mkdir('path_one'); path_one = env.scratch_path/'path_one'
mkdir('path_one')
path_one = env.scratch_path/'path_one'
mkdir(path_one/'foo')
mkdir('path_two'); path_two = env.scratch_path/'path_two'
mkdir('path_two')
path_two = env.scratch_path/'path_two'
write_file(path_two/'foo', '# nothing')
found_path = find_command('foo', map(str, [path_one, path_two]))
assert found_path == path_two/'foo'


def test_does_not_find_command_because_there_is_no_path():
"""
Test calling `pip.utils.find_command` when there is no PATH env variable
"""
environ_before = os.environ
os.environ = {}
try:
try:
find_command('anycommand')
except BadCommand:
e = sys.exc_info()[1]
assert e.args == ("Cannot find command 'anycommand'",)
else:
raise AssertionError("`find_command` should raise `BadCommand`")
try:
find_command('anycommand')
except BadCommand:
e = sys.exc_info()[1]
assert e.args == ("Cannot find command 'anycommand'",)
else:
raise AssertionError("`find_command` should raise `BadCommand`")
finally:
os.environ = environ_before


@patch('pip.util.get_pathext')
@patch('os.path.isfile')
def test_find_command_trys_all_pathext(mock_isfile, getpath_mock):
Expand All @@ -558,8 +567,8 @@ def test_find_command_trys_all_pathext(mock_isfile, getpath_mock):

getpath_mock.return_value = os.pathsep.join([".COM", ".EXE"])

paths = [ os.path.join('path_one', f) for f in ['foo.com', 'foo.exe', 'foo'] ]
expected = [ ((p,),) for p in paths ]
paths = [os.path.join('path_one', f) for f in ['foo.com', 'foo.exe', 'foo']]
expected = [((p,),) for p in paths]

try:
assert_raises(BadCommand, find_command, 'foo', 'path_one')
Expand All @@ -568,6 +577,7 @@ def test_find_command_trys_all_pathext(mock_isfile, getpath_mock):
finally:
os.pathsep = old_sep


@patch('pip.util.get_pathext')
@patch('os.path.isfile')
def test_find_command_trys_supplied_pathext(mock_isfile, getpath_mock):
Expand All @@ -582,8 +592,8 @@ def test_find_command_trys_supplied_pathext(mock_isfile, getpath_mock):

pathext = os.pathsep.join([".RUN", ".CMD"])

paths = [ os.path.join('path_one', f) for f in ['foo.run', 'foo.cmd', 'foo'] ]
expected = [ ((p,),) for p in paths ]
paths = [os.path.join('path_one', f) for f in ['foo.run', 'foo.cmd', 'foo']]
expected = [((p,),) for p in paths]

try:
assert_raises(BadCommand, find_command, 'foo', 'path_one', pathext)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_cleanup.py
Expand Up @@ -6,6 +6,7 @@
from tests.local_repos import local_checkout
from tests.path import Path


def test_cleanup_after_install_from_pypi():
"""
Test clean up after installing a package from PyPI.
Expand Down Expand Up @@ -49,6 +50,7 @@ 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/.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_freeze.py
Expand Up @@ -32,6 +32,7 @@ def banner(msg):
return '\n========== %s ==========\n' % msg
assert checker.check_output(expected, actual, ELLIPSIS), banner('EXPECTED')+expected+banner('ACTUAL')+actual+banner(6*'=')


def test_freeze_basic():
"""
Some tests of freeze, first we have to install some stuff. Note that
Expand All @@ -57,6 +58,7 @@ def test_freeze_basic():
<BLANKLINE>""")
_check_output(result, expected)


def test_freeze_svn():
"""Now lets try it with an svn checkout"""
env = reset_env()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_index.py
@@ -1,9 +1,10 @@
from pip.index import package_to_requirement


def test_package_name_should_be_converted_to_requirement():
"""
Test that it translates a name like Foo-1.2 to Foo==1.3
"""
assert package_to_requirement('Foo-1.2') == 'Foo==1.2'
assert package_to_requirement('Foo-dev') == 'Foo==dev'
assert package_to_requirement('Foo') == 'Foo'
assert package_to_requirement('Foo') == 'Foo'
1 change: 1 addition & 0 deletions tests/test_pip.py
Expand Up @@ -468,6 +468,7 @@ def __init__(self, environ=None):
def __del__(self):
pass # shutil.rmtree(str(self.root_path), ignore_errors=True)


def run_pip(*args, **kw):
result = env.run('pip', *args, **kw)
ignore = []
Expand Down

0 comments on commit 2860dc7

Please sign in to comment.