8000 Update pymode · python-mode/python-mode@24cf7ac · GitHub
[go: up one dir, main page]

Skip to content

Commit 24cf7ac

Browse files
committed
Update pymode
1 parent d7cf768 commit 24cf7ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1666
-927
lines changed

pymode/libs/pylama/config.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
""" Parse arguments from command line and configuration files. """
2+
23
import fnmatch
34
from os import getcwd, path
45
from re import compile as re
@@ -15,16 +16,13 @@
1516
#: A default checkers
1617
DEFAULT_LINTERS = 'pep8', 'pyflakes', 'mccabe'
1718

18-
#: A default complexity for mccabe checker
19-
DEFAULT_COMPLEXITY = 10
20-
2119
CURDIR = getcwd()
2220
DEFAULT_INI_PATH = path.join(CURDIR, 'pylama.ini')
2321

2422

2523
def parse_options(
2624
args=None, async=False, select='', ignore='', linters=DEFAULT_LINTERS,
27-
complexity=DEFAULT_COMPLEXITY, options=DEFAULT_INI_PATH):
25+
options=DEFAULT_INI_PATH):
2826
""" Parse options from command line and configuration files.
2927
3028
:return argparse.Namespace:
@@ -37,10 +35,9 @@ def parse_options(
3735
async=_Default(async), format=_Default('pep8'),
3836
select=_Default(select), ignore=_Default(ignore),
3937
report=_Default(None), verbose=_Default(False),
40-
linters=_Default(','.join(linters)), complexity=_Default(complexity),
41-
options=_Default(options))
38+
linters=_Default(','.join(linters)), options=_Default(options))
4239

43-
if not (args is None):
40+
if not args is None:
4441
options = parser.parse_args(args)
4542

4643
# Parse options from ini file
@@ -72,13 +69,18 @@ def parse_options(
7269

7370
# Parse file related options
7471
options.file_params = dict()
72+
options.linter_params = dict()
7573
for k, s in config.sections.items():
76-
if k != config.default_section:
77-
mask = re(fnmatch.translate(k))
78-
options.file_params[mask] = dict(s)
79-
options.file_params[mask]['lint'] = int(
80-
options.file_params[mask].get('lint', 1)
81-
)
74+
if k == config.default_section:
75+
continue
76+
if k in LINTERS:
77+
options.linter_params[k] = dict(s)
78+
continue
79+
mask = re(fnmatch.translate(k))
80+
options.file_params[mask] = dict(s)
81+
options.file_params[mask]['lint'] = int(
82+
options.file_params[mask].get('lint', 1)
83+
)
8284

8385
return options
8486

@@ -147,10 +149,6 @@ def parse_linters(csp_str):
147149
type=lambda s: [re(fnmatch.translate(p)) for p in s.split(',') if p],
148150
help="Skip files by masks (comma-separated, Ex. */messages.py)")
149151

150-
parser.add_argument(
151-
"--complexity", "-c", default=_Default(DEFAULT_COMPLEXITY), type=int,
152-
help="Set mccabe complexity.")
153-
154152
parser.add_argument("--report", "-r", help="Filename for report.")
155153
parser.add_argument(
156154
"--hook", action="store_true", help="Install Git (Mercurial) hook.")

pymode/libs/pylama/core.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import logging
77
import re
88
import sys
9+
910
from .lint.extensions import LINTERS
1011

12+
1113
#: The skip pattern
1214
SKIP_PATTERN = re.compile(r'# *noqa\b', re.I).search
1315

@@ -22,28 +24,30 @@
2224
LOGGER.addHandler(STREAM)
2325

2426

25-
def run(
26-
path, ignore=None, select=None, linters=None, config=None, code=None,
27-
**meta):
27+
def run(path, code=None, options=None):
2828
""" Run a code checkers with given params.
2929
3030
:return errors: list of dictionaries with error's information
3131
3232
"""
3333
errors = []
34-
linters = linters or LINTERS.items()
35-
params = dict(ignore=ignore, select=select)
34+
params = dict(ignore=options.ignore, select=options.select)
35+
config = dict()
36+
for mask in options.file_params:
37+
if mask.match(path):
38+
config.update(options.file_params[mask])
39+
3640
try:
3741
with CodeContext(code, path) as ctx:
3842
code = ctx.code
3943
params = prepare_params(
40-
parse_modeline(code), config, ignore=ignore, select=select
41-
)
44+
parse_modeline(code), config, ignore=options.ignore,
45+
select=options.select)
4246

4347
if not params['lint']:
4448
return errors
4549

46-
for item in linters:
50+
for item in options.linters:
4751

4852
if not isinstance(item, tuple):
4953
item = (item, LINTERS.get(item))
@@ -53,14 +57,15 @@ def run(
5357
if not linter or not linter.allow(path):
5458
continue
5559

60+
meta = options.linter_params.get(name, dict())
5661
result = linter.run(path, code=code, **meta)
5762
for e in result:
63+
e['linter'] = name
5864
e['col'] = e.get('col') or 0
5965
e['lnum'] = e.get('lnum') or 0
6066
e['type'] = e.get('type') or 'E'
61-
e['text'] = "{0} [{1}]".format((e.get(
62-
'text') or '').strip()
63-
.replace("'", "\"").split('\n')[0], name)
67+
e['text'] = "%s [%s]" % (
68+
e.get('text', '').strip().split('\n')[0], name)
6469
e['filename'] = path or ''
6570
errors.append(e)
6671

pymode/libs/pylama/lint/pylama_mccabe/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Linter(BaseLinter):
88
""" Mccabe code complexity. """
99

1010
@staticmethod
11-
def run(path, code=None, complexity=8, **meta):
11+
def run(path, code=None, complexity=10, **meta):
1212
""" MCCabe code checking.
1313
1414
:return list: List of errors.

pymode/libs/pylama/lint/pylama_pep8/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class Linter(BaseLinter):
1414
""" PEP8 code check. """
1515

1616
@staticmethod
17-
def run(path, code=None, **meta):
17+
def run(path, code=None, **options):
1818
""" PEP8 code checking.
1919
2020
:return list: List of errors.
2121
2222
"""
23-
P8Style = StyleGuide(reporter=_PEP8Report)
23+
P8Style = StyleGuide(reporter=_PEP8Report, **options)
2424
buf = StringIO(code)
2525
return P8Style.input_file(path, lines=buf.readlines())
2626

pymode/libs/pylama/lint/pylama_pyflakes/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ class Linter(BaseLinter):
88
""" Pyflakes code check. """
99

1010
@staticmethod
11-
def run(path, code=None, **meta):
11+
def run(path, code=None, builtins=None, **meta):
1212
""" Pyflake code checking.
1313
1414
:return list: List of errors.
1515
1616
"""
1717
import _ast
1818
from .pyflakes import checker
19+
import os
20+
21+
os.environ.setdefault('PYFLAKES_BUILTINS', builtins)
1922

2023
errors = []
2124
tree = compile(code, path, "exec", _ast.PyCF_ONLY_AST)

pymode/libs/pylama/lint/pylama_pylint/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
__author__ = "horneds <horneds@gmail.com>"
1010
__license__ = "BSD"
1111

12-
try:
13-
from .main import Linter
14-
except ImportError:
15-
Linter = None
12+
import os.path
13+
import sys
14+
15+
CURDIR = os.path.abspath(os.path.dirname(__file__))
16+
sys.path.insert(0, CURDIR)
17+
18+
from .main import Linter
19+
assert Linter
20+

pymode/libs/pylama/lint/pylama_pylint/pylint/astroid/__init__.py renamed to pymode/libs/pylama/lint/pylama_pylint/astroid/__init__.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,23 +48,23 @@
4848
# WARNING: internal imports order matters !
4949

5050
# make all exception classes accessible from astroid package
51-
from .exceptions import *
51+
from astroid.exceptions import *
5252

5353
# make all node classes accessible from astroid package
54-
from .nodes import *
54+
from astroid.nodes import *
5555

5656
# trigger extra monkey-patching
57-
from . import inference
57+
from astroid import inference
5858

5959
# more stuff available
60-
from . import raw_building
61-
from .bases import YES, Instance, BoundMethod, UnboundMethod
62-
from .node_classes import are_exclusive, unpack_infer
63-
from .scoped_nodes import builtin_lookup
60+
from astroid import raw_building
61+
from astroid.bases import YES, Instance, BoundMethod, UnboundMethod
62+
from astroid.node_classes import are_exclusive, unpack_infer
63+
from astroid.scoped_nodes import builtin_lookup
6464

6565
# make a manager instance (borg) as well as Project and Package classes
6666
# accessible from astroid package
67-
from .manager import AstroidManager, Project
67+
from astroid.manager import AstroidManager, Project
6868
MANAGER = AstroidManager()
6969
del AstroidManager
7070

@@ -106,13 +106,13 @@ def transform(node, infer_function=infer_function):
106106
return transform
107107

108108
# load brain plugins
109-
# from os import listdir
110-
# from os.path import join, dirname
111-
# BRAIN_MODULES_DIR = join(dirname(__file__), 'brain')
112-
# if BRAIN_MODULES_DIR not in sys.path:
113-
# # add it to the end of the list so user path take precedence
114-
# sys.path.append(BRAIN_MODULES_DIR)
109+
from os import listdir
110+
from os.path import join, dirname
111+
BRAIN_MODULES_DIR = join(dirname(__file__), 'brain')
112+
if BRAIN_MODULES_DIR not in sys.path:
113+
# add it to the end of the list so user path take precedence
114+
sys.path.append(BRAIN_MODULES_DIR)
115115
# load modules in this directory
116-
# for module in listdir(BRAIN_MODULES_DIR):
117-
# if module.endswith('.py'):
118-
# __import__(module[:-3])
116+
for module in listdir(BRAIN_MODULES_DIR):
117+
if module.endswith('.py'):
118+
__import__(module[:-3])

pymode/libs/pylama/lint/pylama_pylint/pylint/astroid/__pkginfo__.py renamed to pymode/libs/pylama/lint/pylama_pylint/astroid/__pkginfo__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
modname = 'astroid'
2323

24-
numversion = (1, 0, 0)
24+
numversion = (1, 0, 1)
2525
version = '.'.join([str(num) for num in numversion])
2626

2727
install_requires = ['logilab-common >= 0.60.0']

pymode/libs/pylama/lint/pylama_pylint/pylint/astroid/bases.py renamed to pymode/libs/pylama/lint/pylama_pylint/astroid/bases.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import sys
2525
from contextlib import contextmanager
2626

27-
from .exceptions import (InferenceError, AstroidError, NotFoundError,
27+
from astroid.exceptions import (InferenceError, AstroidError, NotFoundError,
2828
UnresolvableName, UseInferenceDefault)
2929

3030

@@ -583,11 +583,11 @@ def eq(self, value):
583583
return False
584584

585585
def as_string(self):
586-
from .as_string import to_code
586+
from astroid.as_string import to_code
587587
return to_code(self)
588588

589589
def repr_tree(self, ids=False):
590-
from .as_string import dump
590+
from astroid.as_string import dump
591591
return dump(self)
592592

593593

0 commit comments

Comments
 (0)
0