diff --git a/fabric/decorators.py b/fabric/decorators.py index fcf60ddc..17fd6de7 100644 --- a/fabric/decorators.py +++ b/fabric/decorators.py @@ -171,7 +171,7 @@ def parallel(pool_size=None): .. versionadded:: 1.3 """ - called_without_args = type(pool_size) == types.FunctionType + called_without_args = isinstance(pool_size, types.FunctionType) def real_decorator(func): @wraps(func) diff --git a/fabric/docs.py b/fabric/docs.py index 1f6ad6ee..205dfeba 100644 --- a/fabric/docs.py +++ b/fabric/docs.py @@ -29,7 +29,7 @@ def unwrap_tasks(module, hide_nontasks=False): ``hide_nontasks`` is thus useful when you have a fabfile mixing in subroutines with real tasks and want to document *just* the real tasks. - + If you run this within an actual Fabric-code-using session (instead of within a Sphinx ``conf.py``), please seek immediate medical attention. diff --git a/fabric/main.py b/fabric/main.py index a231bb98..655a45e7 100644 --- a/fabric/main.py +++ b/fabric/main.py @@ -766,14 +766,12 @@ def main(fabfile_locations=None): # If we got here, no errors occurred, so print a final note. if state.output.status: print("\nDone.") - except SystemExit: - # a number of internal functions might raise this one. - raise + except KeyboardInterrupt: if state.output.status: sys.stderr.write("\nStopped.\n") sys.exit(1) - except: + except Exception: # do not catch SystemExit sys.excepthook(*sys.exc_info()) # we might leave stale threads if we don't explicitly exit() sys.exit(1) diff --git a/fabric/network.py b/fabric/network.py index c1d96335..c4816629 100644 --- a/fabric/network.py +++ b/fabric/network.py @@ -556,7 +556,7 @@ def connect(user, host, port, cache, seek_gateway=True): # ssh raises PasswordRequiredException. text = None if e.__class__ is ssh.PasswordRequiredException \ - or is_key_load_error(e): + or is_key_load_error(e): # NOTE: we can't easily say WHICH key's passphrase is needed, # because ssh doesn't provide us with that info, and # env.key_filename may be a list of keys, so we can't know @@ -687,7 +687,7 @@ def host_prompting_wrapper(*args, **kwargs): if six.PY3 is True: host_string = input(prompt) else: - host_string = raw_input(prompt) + host_string = raw_input(prompt) # noqa: F821 env.update(to_dict(host_string)) return func(*args, **kwargs) host_prompting_wrapper.undecorated = func diff --git a/fabric/operations.py b/fabric/operations.py index 6e734692..2ae5287f 100644 --- a/fabric/operations.py +++ b/fabric/operations.py @@ -210,10 +210,12 @@ def prompt(text, key=None, default='', validate=None): value = None while value is None: # Get input + # WARNING: do not use six.moves.input, because test cases to not + # overwrite that method with a faked method from Fudge if six.PY3 is True: - value = input(prompt_str) or default + value = input(prompt_str) or default # noqa: F821 else: - value = raw_input(prompt_str) or default + value = raw_input(prompt_str) or default # noqa: F821 # Handle validation if validate: # Callable diff --git a/fabric/utils.py b/fabric/utils.py index ad8d3bbd..d16ce0a2 100644 --- a/fabric/utils.py +++ b/fabric/utils.py @@ -10,7 +10,8 @@ def _encode(msg, stream): - if six.PY2 and isinstance(msg, unicode) and hasattr(stream, 'encoding') and not stream.encoding is None: + if six.PY2 and isinstance(msg, six.text_type) \ + and hasattr(stream, 'encoding') and stream.encoding is not None: return msg.encode(stream.encoding) else: return str(msg) diff --git a/integration/test_contrib.py b/integration/test_contrib.py index 4638f405..cc180773 100644 --- a/integration/test_contrib.py +++ b/integration/test_contrib.py @@ -46,14 +46,14 @@ def test_exists(self): self.remote.append(target) run("touch %s" % escape(target)) expect(target) - + def test_sed(self): for target in ('~/sed_test', '~/sed test with space'): self.remote.append(target) run("echo 'before' > %s" % escape(target)) files.sed(target, 'before', 'after') expect_contains(target, 'after') - + def test_upload_template(self): for i, target in enumerate(( '~/upload_template_test', diff --git a/setup.cfg b/setup.cfg index 1e7073c2..8b6ae249 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,50 @@ [flake8] exclude = tests/support,tests/Python26SocketServer.py,sites,fabric/api.py +max-line-length = 164 +ignore = + # continuation line under-indented for hanging indent + E121, + # continuation line missing indentation or outdented + E122, + # closing bracket does not match indentation of opening bracket's line + E123 + # closing bracket does not match visual indentation + E124, + # continuation line with same indent as next logical line + E125, + # continuation line over-indented for hanging indent + E126, + # continuation line over-indented for visual indent + E127, + # continuation line under-indented for visual indent + E128, + # multiple spaces before operator + E221, + # missing whitespace after ':' + E231, + # at least two spaces before inline comment + E261, + # block comment should start with '# ' + E265, + # too many leading '#' for block comment + E266, + # expected 2 blank lines, found 1 + E302, + # too many blank lines + E303, + # expected 1 blank line before a nested definition, found 0 + E306, + # expected 2 blank lines after class or function definition, found 1 + E305, + # the backslash is redundant between brackets + E502, + # line break before binary operator + W503, + # multiple statements on one line + E704, + # do not assign a lambda expression, use a def + E731, + [metadata] license_file = LICENSE diff --git a/tests/fake_filesystem.py b/tests/fake_filesystem.py index c826f45a..3d3a53dd 100644 --- a/tests/fake_filesystem.py +++ b/tests/fake_filesystem.py @@ -40,7 +40,7 @@ def close(self): def __cmp__(self, other): me = str(self) if isinstance(other, six.string_types) else self - return cmp(me, other) + return cmp(me, other) # noqa: F821 class FakeFilesystem(dict): diff --git a/tests/mock_streams.py b/tests/mock_streams.py index 33650f05..ddc3755a 100644 --- a/tests/mock_streams.py +++ b/tests/mock_streams.py @@ -81,5 +81,3 @@ def inner_wrapper(*args, **kwargs): del sys.stdall return inner_wrapper return mocked_streams_decorator - - diff --git a/tests/test_contrib.py b/tests/test_contrib.py index 621ca3a1..45f24a06 100644 --- a/tests/test_contrib.py +++ b/tests/test_contrib.py @@ -3,7 +3,6 @@ import os import six -from fabric.api import hide, get from fabric.contrib.files import upload_template, contains from fabric.context_managers import hide, lcd from fabric.operations import get @@ -72,7 +71,7 @@ def test_contains_checks_only_succeeded_flag(self): """ with hide('everything'): result = contains('/file.txt', 'text', use_sudo=True) - assert result == False + assert result is False @server(responses={ r'egrep "Include other\\.conf" /etc/apache2/apache2.conf': "Include other.conf" @@ -84,7 +83,7 @@ def test_contains_performs_case_sensitive_search(self): with hide('everything'): result = contains('/etc/apache2/apache2.conf', 'Include other.conf', use_sudo=True) - assert result == True + assert result is True @server(responses={ r'egrep -i "include Other\\.CONF" /etc/apache2/apache2.conf': "Include other.conf" @@ -98,7 +97,7 @@ def test_contains_performs_case_insensitive_search(self): 'include Other.CONF', use_sudo=True, case_sensitive=False) - assert result == True + assert result is True @server() def test_upload_template_handles_jinja_template(self): diff --git a/tests/test_main.py b/tests/test_main.py index b28688b6..fff73a10 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -54,7 +54,7 @@ def test_argument_parsing(): # Exclude hosts ('abc:hosts=foo;bar,exclude_hosts=foo', ('abc', [], {}, ['foo', 'bar'], [], ['foo'])), ('abc:hosts=foo;bar,exclude_hosts=foo;bar', ('abc', [], {}, ['foo', 'bar'], [], ['foo','bar'])), - # Empty string args + # Empty string args ("task:x=y,z=", ('task', [], {'x': 'y', 'z': ''}, [], [], [])), ("task:foo,,x=y", ('task', ['foo', ''], {'x': 'y'}, [], [], [])), ]: diff --git a/tests/test_network.py b/tests/test_network.py index b8a13878..21a81ef4 100644 --- a/tests/test_network.py +++ b/tests/test_network.py @@ -9,7 +9,7 @@ from fabric.context_managers import settings, hide, show from fabric.network import (HostConnectionCache, join_host_strings, normalize, denormalize, key_filenames, ssh, NetworkError, connect) -import fabric.network # So I can call patch_object correctly. Sigh. +import fabric.network # noqa: F401 # So I can call patch_object correctly from fabric.state import env, output, _get_system_username from fabric.operations import run, sudo, prompt from fabric.tasks import execute @@ -259,7 +259,8 @@ def generate_fake_client(): fake_ssh.PasswordRequiredException = ssh.PasswordRequiredException patched_connect = patch_object('fabric.network', 'ssh', fake_ssh) - patched_password = patch_object('fabric.network', 'prompt_for_password', Fake('prompt_for_password', callable = True).times_called(0)) + patched_password = patch_object('fabric.network', 'prompt_for_password', + Fake('prompt_for_password', callable=True).times_called(0)) try: connect('user', 'localhost', 22, HostConnectionCache()) finally: diff --git a/tests/test_parallel.py b/tests/test_parallel.py index 0ee95c55..4a86bbe9 100644 --- a/tests/test_parallel.py +++ b/tests/test_parallel.py @@ -10,7 +10,8 @@ # TODO: move this into test_tasks? meh. -class OhNoesException(Exception): pass +class OhNoesException(Exception): + pass class TestParallel(FabricTest): diff --git a/tests/test_project.py b/tests/test_project.py index 2fa4b707..508f7f5f 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -174,4 +174,3 @@ def test_path_to_remote_folder_can_be_specified(self): # Exercise project.upload_project(local_dir=local_dir, remote_dir=remote_path) - diff --git a/tests/test_tasks.py b/tests/test_tasks.py index 80bd61c7..157b1b93 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -615,5 +615,5 @@ def mytask(arg1): Arguments: arg1 -""" +""" # noqa: W293 ) diff --git a/tests/test_utils.py b/tests/test_utils.py index 3c68e4c0..b96037cf 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,7 +1,6 @@ from __future__ import with_statement import sys -from unittest import TestCase from fudge import Fake, patched_context, with_fakes from fudge.patcher import with_patched_object