Skip to content

Commit

Permalink
.coafile: Add PycodestyleBear
Browse files Browse the repository at this point in the history
Adds PycodestyleBear in the autopep8 section and fixes the issues
discovered by the new bear.

Closes #3242
  • Loading branch information
lucianbc committed Jan 2, 2017
1 parent 0ba387f commit 0d4d49c
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .coafile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ preferred_quotation = '
default_actions = *: ApplyPatchAction

[autopep8]
bears = PEP8Bear
bears = PEP8Bear, PycodestyleBear

default_actions = PEP8Bear: ApplyPatchAction

Expand Down
7 changes: 3 additions & 4 deletions coala
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@

import sys

# Start ignoring PyImportSortBear, we need to assert the version before
# importing things that could cause an ImportError
# Start ignoring PyImportSortBear and PycodestyleBear*, we need to assert the
# version before importing things that could cause an ImportError
from coalib import assert_supported_version

assert_supported_version()
# Stop ignoring

from coalib.coala import main

# Stop ignoring

if __name__ == '__main__':
sys.exit(main())
2 changes: 1 addition & 1 deletion coalib/bearlib/abstractions/ExternalBearWrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _prepare_options(options):
'Invalid keyword arguments provided: ' +
', '.join(repr(s) for s in sorted(superfluous_options)))

if not 'settings' in options:
if 'settings' not in options:
options['settings'] = {}


Expand Down
2 changes: 1 addition & 1 deletion coalib/bearlib/languages/Language.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Sub(cls, metaclass=SubLanguageMeta):
aliases = tuple(sorted(getattr(arg, 'aliases', ())))
_attributes = {name: member for name, member in getmembers(arg)
if not name.startswith('_')
and not name in forbidden_attributes}
and name not in forbidden_attributes}

Sub.__name__ = arg.__name__
type(cls).all.append(Sub)
Expand Down
1 change: 1 addition & 0 deletions coalib/coala.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ def main():

return mode_normal(console_printer, log_printer)


if __name__ == '__main__': # pragma: no cover
main()
4 changes: 3 additions & 1 deletion coalib/coala_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
settings_changed, update_settings_db, get_settings_hash)
from coalib.misc.Constants import configure_logging

do_nothing = lambda *args: True

def do_nothing(*args):
return True


def run_coala(console_printer=None,
Expand Down
2 changes: 1 addition & 1 deletion coalib/collecting/Collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def filter_capabilities_by_languages(bears, languages):
language_bears_capabilities.update(
{language: (capabilities[0] | bear.can_detect,
capabilities[1] | bear.CAN_FIX)}
if language else {})
if language else {})
return language_bears_capabilities


Expand Down
8 changes: 6 additions & 2 deletions coalib/parsing/ConfParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ def __parse_lines(self, lines, origin):
Setting(key,
value,
origin,
# Ignore PEP8Bear, it fails to format that
# Start ignoring PEP8Bear, PycodestyleBear*
# they fail to resolve this
remove_empty_iter_elements=
self.__remove_empty_iter_elements),
# Stop ignoring
allow_appending=(keys == []))
else:
self.get_section(
Expand All @@ -124,9 +126,11 @@ def __parse_lines(self, lines, origin):
Setting(key,
value,
origin,
# Ignore PEP8Bear, it fails to format that
# Start ignoring PEP8Bear, PycodestyleBear*
# they fail to resolve this
remove_empty_iter_elements=
self.__remove_empty_iter_elements),
# Stop ignoring
allow_appending=(keys == []))

def __init_sections(self):
Expand Down
4 changes: 3 additions & 1 deletion coalib/settings/FunctionMetadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ def create_params_from_section(self, section):

@staticmethod
def _get_param(param, section, annotation):
def return_arg(x):
return x
if annotation is None:
annotation = lambda x: x
annotation = return_arg

try:
return annotation(section[param])
Expand Down
2 changes: 1 addition & 1 deletion coalib/settings/SectionFilling.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def fill_section(section, acquire_settings, log_printer, bears):
# Strip away existent settings.
needed_settings = {}
for setting, help_text in prel_needed_settings.items():
if not setting in section:
if setting not in section:
needed_settings[setting] = help_text

# Get missing ones.
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ def run(self):
errTwo = call(self.doc_command)
sys.exit(errOne or errTwo)


# Generate API documentation only if we are running on readthedocs.io
on_rtd = getenv('READTHEDOCS', None) != None
on_rtd = getenv('READTHEDOCS', None) is not None
if on_rtd:
call(BuildDocsCommand.apidoc_command)
if 'dev' in VERSION:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
import sys
import json

# Start ignoring PycodestyleBear* as those imports may raise
# import warnings
sys.path.append(os.path.join(os.path.dirname(__file__),
'..', '..', '..', '..'))

from coalib.results.Result import Result
from coalib.results.SourceRange import SourceRange
from coalib.output.JSONEncoder import create_json_encoder
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
# Stop ignoring

if __name__ == '__main__':

Expand Down
6 changes: 3 additions & 3 deletions tests/coalaTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def test_coala(self):
prepare_file(['#fixme'], None) as (lines, filename):
retval, output = execute_coala(
coala.main,
'coala', '-c', os.devnull,
'-f', re.escape(filename),
'-b', 'LineCountTestBear')
'coala', '-c', os.devnull,
'-f', re.escape(filename),
'-b', 'LineCountTestBear')
self.assertIn('This file has 1 lines.',
output,
'The output should report count as 1 lines')
Expand Down
1 change: 1 addition & 0 deletions tests/collecting/importers_test_dir/file_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def __init__(self, *args):
def method():
pass


a = [1, 2, 3]
b = [1, 2, 4]

Expand Down
4 changes: 2 additions & 2 deletions tests/results/SourcePositionTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def test_string_conversion(self):
self.assertRegex(
repr(uut),
"<SourcePosition object\\(file='.*filename', line=1, "
'column=None\\) at 0x[0-9a-fA-F]+>')
'column=None\\) at 0x[0-9a-fA-F]+>')

uut = SourcePosition('None', None)
self.assertRegex(
repr(uut),
"<SourcePosition object\\(file='.*None', line=None, column=None\\) "
'at 0x[0-9a-fA-F]+>')
'at 0x[0-9a-fA-F]+>')

def test_json(self):
with prepare_file([''], None) as (_, filename):
Expand Down

0 comments on commit 0d4d49c

Please sign in to comment.