Skip to content

Commit

Permalink
now flake8 clean, with many style rules disabled
Browse files Browse the repository at this point in the history
and a few minimal style fixes
and a few noqa comments
  • Loading branch information
ploxiln committed Jun 7, 2018
1 parent 01ec7c6 commit 88e94a7
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 27 deletions.
2 changes: 1 addition & 1 deletion fabric/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion fabric/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 2 additions & 4 deletions fabric/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions fabric/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions fabric/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion fabric/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions integration/test_contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
45 changes: 45 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion tests/fake_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions tests/mock_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,3 @@ def inner_wrapper(*args, **kwargs):
del sys.stdall
return inner_wrapper
return mocked_streams_decorator


7 changes: 3 additions & 4 deletions tests/test_contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}, [], [], [])),
]:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

# TODO: move this into test_tasks? meh.

class OhNoesException(Exception): pass
class OhNoesException(Exception):
pass


class TestParallel(FabricTest):
Expand Down
1 change: 0 additions & 1 deletion tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

2 changes: 1 addition & 1 deletion tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,5 +615,5 @@ def mytask(arg1):
Arguments: arg1
"""
""" # noqa: W293
)
1 change: 0 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 88e94a7

Please sign in to comment.