Skip to content

Commit 48eb0ed

Browse files
committed
update pylama
1 parent 6033234 commit 48eb0ed

File tree

7 files changed

+183
-91
lines changed

7 files changed

+183
-91
lines changed

pymode/libs/pylama/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
66
"""
77

8-
version_info = 3, 0, 2
9-
10-
__version__ = version = '.'.join(map(str, version_info))
11-
__project__ = __name__
8+
__version__ = "3.1.1"
9+
__project__ = "pylama"
1210
__author__ = "Kirill Klenov <horneds@gmail.com>"
1311
__license__ = "GNU LGPL"

pymode/libs/pylama/config.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import logging
88
from argparse import ArgumentParser
99

10-
from . import version
10+
from . import __version__
1111
from .libs.inirama import Namespace
1212
from .lint.extensions import LINTERS
1313

@@ -72,7 +72,7 @@ def parse_linters(linters):
7272
"--verbose", "-v", action='store_true', help="Verbose mode.")
7373

7474
PARSER.add_argument('--version', action='version',
75-
version='%(prog)s ' + version)
75+
version='%(prog)s ' + __version__)
7676

7777
PARSER.add_argument(
7878
"--format", "-f", default=_Default('pep8'), choices=['pep8', 'pylint'],
@@ -116,7 +116,7 @@ def parse_linters(linters):
116116
ACTIONS = dict((a.dest, a) for a in PARSER._actions)
117117

118118

119-
def parse_options(args=None, **overrides): # noqa
119+
def parse_options(args=None, config=True, **overrides): # noqa
120120
""" Parse options from command line and configuration files.
121121
122122
:return argparse.Namespace:
@@ -127,44 +127,43 @@ def parse_options(args=None, **overrides): # noqa
127127

128128
# Parse args from command string
129129
options = PARSER.parse_args(args)
130-
131-
# Parse options from ini file
132-
cfg = get_config(str(options.options))
133-
134-
# Compile options from ini
135-
for k, v in cfg.default.items():
136-
LOGGER.info('Find option %s (%s)', k, v)
137-
passed_value = getattr(options, k, _Default())
138-
if isinstance(passed_value, _Default):
139-
setattr(options, k, _Default(v))
130+
options.file_params = dict()
131+
options.linter_params = dict()
140132

141133
# Override options
142134
for k, v in overrides.items():
143135
passed_value = getattr(options, k, _Default())
144136
if isinstance(passed_value, _Default):
145137
setattr(options, k, _Default(v))
146138

139+
# Compile options from ini
140+
if config:
141+
cfg = get_config(str(options.options))
142+
for k, v in cfg.default.items():
143+
LOGGER.info('Find option %s (%s)', k, v)
144+
passed_value = getattr(options, k, _Default())
145+
if isinstance(passed_value, _Default):
146+
setattr(options, k, _Default(v))
147+
148+
# Parse file related options
149+
for k, s in cfg.sections.items():
150+
if k == cfg.default_section:
151+
continue
152+
if k in LINTERS:
153+
options.linter_params[k] = dict(s)
154+
continue
155+
mask = re(fnmatch.translate(k))
156+
options.file_params[mask] = dict(s)
157+
options.file_params[mask]['lint'] = int(
158+
options.file_params[mask].get('lint', 1)
159+
)
160+
147161
# Postprocess options
148162
opts = dict(options.__dict__.items())
149163
for name, value in opts.items():
150164
if isinstance(value, _Default):
151165
setattr(options, name, process_value(name, value.value))
152166

153-
# Parse file related options
154-
options.file_params = dict()
155-
options.linter_params = dict()
156-
for k, s in cfg.sections.items():
157-
if k == cfg.default_section:
158-
continue
159-
if k in LINTERS:
160-
options.linter_params[k] = dict(s)
161-
continue
162-
mask = re(fnmatch.translate(k))
163-
options.file_params[mask] = dict(s)
164-
options.file_params[mask]['lint'] = int(
165-
options.file_params[mask].get('lint', 1)
166-
)
167-
168167
return options
169168

170169

pymode/libs/pylama/core.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ def run(path, code=None, options=None):
4747
item = (item, LINTERS.get(item))
4848

4949
name, linter = item
50-
LOGGER.debug("Run %s", name)
5150

5251
if not linter or not linter.allow(path):
5352
continue
5453

54+
LOGGER.info("Run %s", name)
5555
meta = options.linter_params.get(name, dict())
5656
result = linter.run(path, code=code, **meta)
5757
for e in result:
@@ -77,9 +77,8 @@ def run(path, code=None, options=None):
7777
))
7878

7979
except Exception as e:
80-
LOGGER.debug("Unknown exception %s", e)
8180
import traceback
82-
logging.debug(traceback.format_exc())
81+
LOGGER.info(traceback.format_exc())
8382

8483
errors = [er for er in errors if filter_errors(er, **params)]
8584

@@ -180,7 +179,7 @@ def __enter__(self):
180179

181180
def __exit__(self, t, value, traceback):
182181
""" Close opened file. """
183-
if not self._file is None:
182+
if self._file is not None:
184183
self._file.close()
185184

186185
if t and LOGGER.level == logging.DEBUG:

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from io import StringIO
99

1010

11-
1211
class Linter(BaseLinter):
1312

1413
""" PEP8 code check. """
@@ -42,12 +41,13 @@ def error(self, line_number, offset, text, check):
4241
code = super(_PEP8Report, self).error(
4342
line_number, offset, text, check)
4443

45-
self.errors.append(dict(
46-
text=text,
47-
type=code.replace('E', 'C'),
48-
col=offset + 1,
49-
lnum=line_number,
50-
))
44+
if code:
45+
self.errors.append(dict(
46+
text=text,
47+
type=code.replace('E', 'C'),
48+
col=offset + 1,
49+
lnum=line_number,
50+
))
5151

5252
def get_file_results(self):
5353
""" Get errors.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy