Skip to content

Commit

Permalink
Update pylama
Browse files Browse the repository at this point in the history
  • Loading branch information
klen committed Jun 15, 2014
1 parent e0dd007 commit e5f1486
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 51 deletions.
20 changes: 11 additions & 9 deletions Changelog.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
Changelog
=========

* Pylama updated to version 5.0.5

## 2014-06-11 0.8.1
-------------------
* Pylama updated to version 3.3.2
* Get fold's expression symbol from &fillchars;
* Fixed error when setting g:pymode_breakpoint_cmd (expobrain);
* Fixed code running;
* Ability to override rope project root and .ropeproject folder
* Added path argument to `PymodeRopeNewProject` which skips prompt
* Disable `pymode_rope_lookup_project` by default
* Options added:
'pymode_rope_project_root', 'pymode_rope_ropefolder'
* Pylama updated to version 3.3.2
* Get fold's expression symbol from &fillchars;
* Fixed error when setting g:pymode_breakpoint_cmd (expobrain);
* Fixed code running;
* Ability to override rope project root and .ropeproject folder
* Added path argument to `PymodeRopeNewProject` which skips prompt
* Disable `pymode_rope_lookup_project` by default
* Options added:
'pymode_rope_project_root', 'pymode_rope_ropefolder'


## 2013-12-04 0.7.8b
Expand Down
2 changes: 1 addition & 1 deletion pymode/libs/pylama/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

__version__ = "5.0.1"
__version__ = "5.0.5"
__project__ = "pylama"
__author__ = "Kirill Klenov <[email protected]>"
__license__ = "GNU LGPL"
4 changes: 2 additions & 2 deletions pymode/libs/pylama/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def parse_options(args=None, config=True, **overrides): # noqa
# Parse args from command string
options = PARSER.parse_args(args)
options.file_params = dict()
options.linter_params = dict()
options.linters_params = dict()

# Override options
for k, v in overrides.items():
Expand Down Expand Up @@ -165,7 +165,7 @@ def parse_options(args=None, config=True, **overrides): # noqa
name = name[7:]

if name in LINTERS:
options.linter_params[name] = dict(opts)
options.linters_params[name] = dict(opts)
continue

mask = re(fnmatch.translate(name))
Expand Down
16 changes: 10 additions & 6 deletions pymode/libs/pylama/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def run(path='', code=None, options=None):
fileconfig = dict()
params = dict()
linters = LINTERS
linter_params = dict()
linters_params = dict()

if options:
linters = options.linters
linter_params = options.linter_params
linters_params = options.linters_params
for mask in options.file_params:
if mask.match(path):
fileconfig.update(options.file_params[mask])
Expand All @@ -45,6 +45,7 @@ def run(path='', code=None, options=None):
with CodeContext(code, path) as ctx:
code = ctx.code
params = prepare_params(parse_modeline(code), fileconfig, options)
LOGGER.debug('Checking params: %s', params)

if params.get('skip'):
return errors
Expand All @@ -59,10 +60,13 @@ def run(path='', code=None, options=None):
if not linter:
continue

LOGGER.info("Run %s", lname)
meta = linter_params.get(lname, dict())
errors += [Error(filename=path, linter=lname, **e)
for e in linter.run(path, code=code, **meta)]
lparams = linters_params.get(lname, dict())
LOGGER.info("Run %s %s", lname, lparams)

for er in linter.run(
path, code=code, ignore=params.get("ignore", set()),
select=params.get("select", set()), params=lparams):
errors.append(Error(filename=path, linter=lname, **er))

except IOError as e:
LOGGER.debug("IOError %s", e)
Expand Down
2 changes: 1 addition & 1 deletion pymode/libs/pylama/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ def get(self, name, default=None):
def __repr__(self):
return "<Error: %s %s>" % (self.number, self.linter)

# pylama:ignore=W0622,D
# pylama:ignore=W0622,D,R0924
17 changes: 9 additions & 8 deletions pymode/libs/pylama/libs/inirama.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
"""
from __future__ import unicode_literals, print_function


__version__ = "0.8.0"
__project__ = "Inirama"
__author__ = "Kirill Klenov <[email protected]>"
__license__ = "BSD"


import io
import re
import logging
Expand Down Expand Up @@ -66,12 +73,6 @@ def keys(self):
iteritems = DictMixin.iteritems


__version__ = "0.7.0"
__project__ = "Inirama"
__author__ = "Kirill Klenov <[email protected]>"
__license__ = "BSD"


NS_LOGGER = logging.getLogger('inirama')


Expand Down Expand Up @@ -169,7 +170,7 @@ class INIScanner(Scanner):
('SECTION', re.compile(r'\[[^]]+\]')),
('IGNORE', re.compile(r'[ \r\t\n]+')),
('COMMENT', re.compile(r'[;#].*')),
('KEY', re.compile(r'[\w_]+\s*[:=].*')),
('KEY_VALUE', re.compile(r'[^=\s]+\s*[:=].*')),
('CONTINUATION', re.compile(r'.*'))
]

Expand Down Expand Up @@ -346,7 +347,7 @@ def parse(self, source, update=True, **params):
name = None

for token in scanner.tokens:
if token[0] == 'KEY':
if token[0] == 'KEY_VALUE':
name, value = re.split('[=:]', token[1], 1)
name, value = name.strip(), value.strip()
if not update and name in self[section]:
Expand Down
3 changes: 2 additions & 1 deletion pymode/libs/pylama/lint/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pkg_resources import iter_entry_points

for entry in iter_entry_points('pylama.linter'):
LINTERS[entry.name] = entry.load()()
if entry.name not in LINTERS:
LINTERS[entry.name] = entry.load()()
except ImportError:
pass
3 changes: 2 additions & 1 deletion pymode/libs/pylama/lint/pylama_mccabe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ class Linter(BaseLinter):
""" Mccabe code complexity. """

@staticmethod
def run(path, code=None, complexity=10, **meta):
def run(path, code=None, params=None, **meta):
""" MCCabe code checking.
:return list: List of errors.
"""
from .mccabe import get_code_complexity

complexity = params.get('complexity', 10)
return get_code_complexity(code, complexity, filename=path) or []
4 changes: 2 additions & 2 deletions pymode/libs/pylama/lint/pylama_pep8/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ class Linter(BaseLinter):
""" PEP8 code check. """

@staticmethod
def run(path, code=None, **options):
def run(path, code=None, params=None, **meta):
""" PEP8 code checking.
:return list: List of errors.
"""
P8Style = StyleGuide(reporter=_PEP8Report, **options)
P8Style = StyleGuide(reporter=_PEP8Report, **params)
buf = StringIO(code)
return P8Style.input_file(path, lines=buf.readlines())

Expand Down
10 changes: 6 additions & 4 deletions pymode/libs/pylama/lint/pylama_pyflakes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ def __init__(self):
monkey_patch_messages(checker.messages)

@staticmethod
def run(path, code=None, builtins="", **meta):
def run(path, code=None, params=None, **meta):
""" Pyflake code checking.
:return list: List of errors.
"""
import _ast
import os

os.environ.setdefault('PYFLAKES_BUILTINS', builtins)
builtins = params.get("builtins", "")

if builtins:
builtins = builtins.split(",")

errors = []
tree = compile(code, path, "exec", _ast.PyCF_ONLY_AST)
w = checker.Checker(tree, path)
w = checker.Checker(tree, path, builtins=builtins)
w.messages = sorted(w.messages, key=lambda m: m.lineno)
for w in w.messages:
errors.append(dict(
Expand Down
2 changes: 1 addition & 1 deletion pymode/libs/pylama/lint/pylama_pylint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ==================


__version__ = "0.2.1"
__version__ = "0.3.1"
__project__ = "pylama_pylint"
__author__ = "horneds <[email protected]>"
__license__ = "BSD"
Expand Down
8 changes: 4 additions & 4 deletions pymode/libs/pylama/lint/pylama_pylint/astroid/rebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,16 +516,16 @@ def visit_function(self, node, parent):
frame = newnode.parent.frame()
if isinstance(frame, new.Class):
if newnode.name == '__new__':
newnode.type = 'classmethod'
newnode._type = 'classmethod'
else:
newnode.type = 'method'
newnode._type = 'method'
if newnode.decorators is not None:
for decorator_expr in newnode.decorators.nodes:
if isinstance(decorator_expr, new.Name):
if decorator_expr.name in ('classmethod', 'staticmethod'):
newnode.type = decorator_expr.name
newnode._type = decorator_expr.name
elif decorator_expr.name == 'classproperty':
newnode.type = 'classmethod'
newnode._type = 'classmethod'
frame.set_local(newnode.name, newnode)
return newnode

Expand Down
34 changes: 32 additions & 2 deletions pymode/libs/pylama/lint/pylama_pylint/astroid/scoped_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
from cStringIO import StringIO as BytesIO

from logilab.common.compat import builtins
from logilab.common.decorators import cached
from logilab.common.decorators import cached, cachedproperty

from astroid.exceptions import NotFoundError, \
AstroidBuildingException, InferenceError
from astroid.node_classes import Const, DelName, DelAttr, \
Dict, From, List, Pass, Raise, Return, Tuple, Yield, YieldFrom, \
LookupMixIn, const_factory as cf, unpack_infer
LookupMixIn, const_factory as cf, unpack_infer, Name
from astroid.bases import NodeNG, InferenceContext, Instance,\
YES, Generator, UnboundMethod, BoundMethod, _infer_stmts, copy_context, \
BUILTINS
Expand Down Expand Up @@ -476,6 +476,34 @@ class ListComp(_ListComp):
"""class representing a ListComp node"""

# Function ###################################################################

def _function_type(self):
"""
Function type, possible values are:
method, function, staticmethod, classmethod.
"""
# Can't infer that this node is decorated
# with a subclass of `classmethod` where `type` is first set,
# so do it here.
if self.decorators:
for node in self.decorators.nodes:
if not isinstance(node, Name):
continue
try:
for infered in node.infer():
if not isinstance(infered, Class):
continue
for ancestor in infered.ancestors():
if isinstance(ancestor, Class):
if (ancestor.name == 'classmethod' and
ancestor.root().name == BUILTINS):
return 'classmethod'
elif (ancestor.name == 'staticmethod' and
ancestor.root().name == BUILTINS):
return 'staticmethod'
except InferenceError:
pass
return self._type


class Lambda(LocalsDictNodeNG, FilterStmtsMixin):
Expand Down Expand Up @@ -539,6 +567,8 @@ class Function(Statement, Lambda):
# attributes below are set by the builder module or by raw factories
blockstart_tolineno = None
decorators = None
_type = "function"
type = cachedproperty(_function_type)

def __init__(self, name, doc):
self.locals = {}
Expand Down
Loading

0 comments on commit e5f1486

Please sign in to comment.