Skip to content

Commit

Permalink
Merge pull request #97 from diraol/fix-96-pydocstyle_v2
Browse files Browse the repository at this point in the history
Fix #96 pydocstyle 2.0.0
  • Loading branch information
klen committed Jun 26, 2017
2 parents a1686fe + 9f331a7 commit 84621a2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ python:
- "2.7"

env:
- TOXENV=py26
- TOXENV=py27
- TOXENV=py33
- TOXENV=py35
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Docs are available at https://pylama.readthedocs.org/. Pull requests with docume
Requirements:
=============

- Python (2.6, 2.7, 3.2, 3.3)
- Python (2.7, 3.2, 3.3)
- To use JavaScript checker (``gjslint``) you need to install ``python-gflags`` with ``pip install python-gflags``.
- If your tests are failing on Win platform you are missing: ``curses`` - http://www.lfd.uci.edu/~gohlke/pythonlibs/
(The curses library supplies a terminal-independent screen-painting and keyboard-handling facility for text-based terminals)
Expand Down
41 changes: 22 additions & 19 deletions pylama/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
LOGGER.addHandler(STREAM)


class _Default(object):
class _Default(object): # pylint: disable=too-few-public-methods

def __init__(self, value=None):
self.value = value
Expand All @@ -42,14 +42,14 @@ def __repr__(self):
return "<_Default [%s]>" % self.value


def split_csp_str(s):
def split_csp_str(val):
""" Split comma separated string into unique values, keeping their order.
:returns: list of splitted values
"""
seen = set()
values = s if isinstance(s, (list, tuple)) else s.strip().split(',')
values = val if isinstance(val, (list, tuple)) else val.strip().split(',')
return [x for x in values if x and not (x in seen or seen.add(x))]


Expand All @@ -65,7 +65,7 @@ def parse_linters(linters):
if linter:
result.append((name, linter))
else:
logging.warn("Linter `%s` not found.", name)
logging.warning("Linter `%s` not found.", name)
return result


Expand Down Expand Up @@ -131,7 +131,7 @@ def parse_linters(linters):
help="Use absolute paths in output.")


ACTIONS = dict((a.dest, a) for a in PARSER._actions)
ACTIONS = dict((a.dest, a) for a in PARSER._actions) # pylint: disable=protected-access


def parse_options(args=None, config=True, rootdir=CURDIR, **overrides): # noqa
Expand All @@ -140,8 +140,7 @@ def parse_options(args=None, config=True, rootdir=CURDIR, **overrides): # noqa
:return argparse.Namespace:
"""
if args is None:
args = []
args = args or []

# Parse args from command string
options = PARSER.parse_args(args)
Expand All @@ -162,10 +161,7 @@ def parse_options(args=None, config=True, rootdir=CURDIR, **overrides): # noqa
# Parse file related options
for name, opts in cfg.sections.items():

if not name.startswith('pylama'):
continue

if name == cfg.default_section:
if not name.startswith('pylama') or name == cfg.default_section:
continue

name = name[7:]
Expand All @@ -178,12 +174,7 @@ def parse_options(args=None, config=True, rootdir=CURDIR, **overrides): # noqa
options.file_params[mask] = dict(opts)

# Override options
for opt, val in overrides.items():
passed_value = getattr(options, opt, _Default())
if opt in ('ignore', 'select') and passed_value:
setattr(options, opt, process_value(opt, passed_value.value) + process_value(opt, val))
elif isinstance(passed_value, _Default):
setattr(options, opt, process_value(opt, val))
_override_options(options, **overrides)

# Postprocess options
for name in options.__dict__:
Expand All @@ -192,12 +183,24 @@ def parse_options(args=None, config=True, rootdir=CURDIR, **overrides): # noqa
setattr(options, name, process_value(name, value.value))

if options.async and 'pylint' in options.linters:
LOGGER.warn('Cant parse code asynchronously while pylint is enabled.')
LOGGER.warning('Can\'t parse code asynchronously with pylint enabled.')
options.async = False

return options


def _override_options(options, **overrides):
"""Override options."""
for opt, val in overrides.items():
passed_value = getattr(options, opt, _Default())
if opt in ('ignore', 'select') and passed_value:
value = process_value(opt, passed_value.value)
value += process_value(opt, val)
setattr(options, opt, value)
elif isinstance(passed_value, _Default):
setattr(options, opt, process_value(opt, val))


def process_value(name, value):
""" Compile option value. """
action = ACTIONS.get(name)
Expand Down Expand Up @@ -234,7 +237,7 @@ def get_config(ini_path=None, rootdir=CURDIR):


def setup_logger(options):
""" Setup logger with options. """
"""Do the logger setup with options."""
LOGGER.setLevel(logging.INFO if options.verbose else logging.WARN)
if options.report:
LOGGER.removeHandler(STREAM)
Expand Down
12 changes: 10 additions & 2 deletions pylama/lint/pylama_pydocstyle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
"""pydocstyle support."""

from pydocstyle import PEP257Checker
THIRD_ARG = True
try:
#: Import for pydocstyle 2.0.0 and newer
from pydocstyle import ConventionChecker as PyDocChecker
except ImportError:
#: Backward compatibility for pydocstyle prior to 2.0.0
from pydocstyle import PEP257Checker as PyDocChecker
THIRD_ARG = False

from pylama.lint import Linter as Abstract

Expand All @@ -15,11 +22,12 @@ def run(path, code=None, **meta):
:return list: List of errors.
"""
check_source_args = (code, path, None) if THIRD_ARG else (code, path)
return [{
'lnum': e.line,
# Remove colon after error code ("D403: ..." => "D403 ...").
'text': (e.message[0:4] + e.message[5:]
if e.message[4] == ':' else e.message),
'type': 'D',
'number': e.code
} for e in PEP257Checker().check_source(code, path)]
} for e in PyDocChecker().check_source(*check_source_args)]
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
install_requires = [
l.replace('==', '>=') for l in _read('requirements.txt').split('\n')
if l and not l.startswith('#') and not l.startswith('-')]
if sys.version_info < (2, 7):
install_requires += ['argparse']


meta = dict(
name=_project,
Expand Down
7 changes: 1 addition & 6 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py26,py27,py34,cov
envlist = py27,py34,cov

[pytest]
addopts = -s
Expand All @@ -13,11 +13,6 @@ deps =
pytest
-rrequirements.txt

[testenv:py26]
deps =
argparse
{[testenv]deps}

[testenv:cov]
deps =
coverage
Expand Down

0 comments on commit 84621a2

Please sign in to comment.