8000 Update pylama to version 4.0.1 Supports configuration from setup.cfg,… · python-mode/python-mode@304a68e · GitHub
[go: up one dir, main page]

Skip to content

Commit 304a68e

Browse files
committed
Update pylama to version 4.0.1 Supports configuration from setup.cfg, tox.ini, pytest.ini files
1 parent d09e30d commit 304a68e

File tree

3 files changed

+71
-60
lines changed

3 files changed

+71
-60
lines changed

pymode/libs/pylama/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
"""
77

8-
__version__ = "3.3.2"
8+
__version__ = "4.0.1"
99
__project__ = "pylama"
1010
__author__ = "Kirill Klenov <horneds@gmail.com>"
1111
__license__ = "GNU LGPL"

pymode/libs/pylama/config.py

Lines changed: 36 additions & 20 deletions
F438
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" Parse arguments from command line and configuration files. """
22
import fnmatch
33
import sys
4-
from os import getcwd, path
4+
import os
55
from re import compile as re
66

77
import logging
@@ -21,8 +21,11 @@
2121
#: A default checkers
2222
DEFAULT_LINTERS = 'pep8', 'pyflakes', 'mccabe'
2323

24-
CURDIR = getcwd()
25-
DEFAULT_INI_PATH = path.join(CURDIR, 'pylama.ini')
24+
CURDIR = os.getcwd()
25+
CONFIG_FILES = [
26+
os.path.join(CURDIR, basename) for basename in
27+
('pylama.ini', 'setup.cfg', 'tox.ini', 'pytest.ini')
28+
]
2629

2730

2831
class _Default(object):
@@ -67,7 +70,7 @@ def parse_linters(linters):
6770
PARSER = ArgumentParser(description="Code audit tool for python.")
6871
PARSER.add_argument(
6972
"path", nargs='?', default=_Default(CURDIR),
70-
help="Path on file or directory.")
73+
help="Path on file or directory for code check.")
7174

7275
PARSER.add_argument(
7376
"--verbose", "-v", action='store_true', help="Verbose mode.")
@@ -77,11 +80,11 @@ def parse_linters(linters):
7780

7881
PARSER.add_argument(
7982
"--format", "-f", default=_Default('pep8'), choices=['pep8', 'pylint'],
80-
help="Error format.")
83+
help="Choose errors format (pep8, pylint).")
8184

8285
PARSER.add_argument(
8386
"--select", "-s", default=_Default(''), type=split_csp_str,
84-
help="Select errors and warnings. (comma-separated)")
87+
help="Select errors and warnings. (comma-separated list)")
8588

8689

8790
PARSER.add_argum 57AE ent(
@@ -100,7 +103,7 @@ def parse_linters(linters):
100103
type=lambda s: [re(fnmatch.translate(p)) for p in s.split(',') if p],
101104
help="Skip files by masks (comma-separated, Ex. */messages.py)")
102105

103-
PARSER.add_argument("--report", "-r", help="Filename for report.")
106+
PARSER.add_argument("--report", "-r", help="Send report to file [REPORT]")
104107
PARSER.add_argument(
105108
"--hook", action="store_true", help="Install Git (Mercurial) hook.")
106109

@@ -110,7 +113,7 @@ def parse_linters(linters):
110113
"Dont supported with pylint.")
111114

112115
PARSER.add_argument(
113-
"--options", "-o", default=_Default(DEFAULT_INI_PATH),
116+
"--options", "-o", default="",
114117
help="Select configuration file. By default is '<CURDIR>/pylama.ini'")
115118

116119
PARSER.add_argument(
@@ -151,17 +154,22 @@ def parse_options(args=None, config=True, **overrides): # noqa
151154
setattr(options, k, _Default(v))
152155

153156
# Parse file related options
154-
for k, s in cfg.sections.items():
155-
if k == cfg.default_section:
157+
for name, opts in cfg.sections.items():
158+
159+
if not name.startswith('pylama'):
160+
continue
161+
162+
if name == cfg.default_section:
156163
continue
157-
if k in LINTERS:
158-
options.linter_params[k] = dict(s)
164+
165+
name = name[7:]
166+
167+
if name in LINTERS:
168+
options.linter_params[name] = dict(opts)
159169
continue
160-
mask = re(fnmatch.translate(k))
161-
options.file_params[mask] = dict(s)
162-
options.file_params[mask]['lint'] = int(
163-
options.file_params[mask].get('lint', 1)
164-
)
170+
171+
mask = re(fnmatch.translate(name))
172+
options.file_params[mask] = dict(opts)
165173

166174
# Postprocess options
167175
opts = dict(options.__dict__.items())
@@ -187,15 +195,21 @@ def process_value(name, value):
187195
return value
188196

189197

190-
def get_config(ini_path=DEFAULT_INI_PATH):
198+
def get_config(ini_path=None):
191199
""" Load configuration from INI.
192200
193201
:return Namespace:
194202
195203
"""
196204
config = Namespace()
197-
config.default_section = 'main'
198-
config.read(ini_path)
205+
config.default_section = 'pylama'
206+
207+
if not ini_path:
208+
for path in CONFIG_FILES:
209+
if os.path.isfile(path) and os.access(path, os.R_OK):
210+
config.read(path)
211+
else:
212+
config.read(ini_path)
199213

200214
return config
201215

@@ -207,3 +221,5 @@ def setup_logger(options):
207221
LOGGER.removeHandler(STREAM)
208222
LOGGER.addHandler(logging.FileHandler(options.report, mode='w'))
209223
LOGGER.info('Try to read configuration from: ' + options.options)
224+
225+
# pylama:ignore=W0212

pymode/libs/pylama/libs/inirama.py

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import io
2020
import re
2121
import logging
22-
from collections import MutableMapping
2322
try:
2423
from collections import OrderedDict
2524
except ImportError:
@@ -67,7 +66,7 @@ def keys(self):
6766
iteritems = DictMixin.iteritems
6867

6968

70-
__version__ = "0.5.1"
69+
__version__ = "0.7.0"
7170
__project__ = "Inirama"
7271
__author__ = "Kirill Klenov <horneds@gmail.com>"
7372
__license__ = "BSD"
@@ -170,7 +169,9 @@ class INIScanner(Scanner):
170169
('SECTION', re.compile(r'\[[^]]+\]')),
171170
('IGNORE', re.compile(r'[ \r\t\n]+')),
172171
('COMMENT', re.compile(r'[;#].*')),
173-
('KEY', re.compile(r'[\w_]+\s*[:=].*'))]
172+
('KEY', re.compile(r'[\w_]+\s*[:=].*')),
173+
('CONTINUATION', re.compile(r'.*'))
174+
]
174175

175176
ignore = ['IGNORE']
176177

@@ -183,43 +184,20 @@ def pre_scan(self):
183184
undefined = object()
184185

185186

186-
class Section(MutableMapping):
187+
class Section(OrderedDict):
187188

188189
""" Representation of INI section. """
189190

190191
def __init__(self, namespace, *args, **kwargs):
191192
super(Section, self).__init__(*args, **kwargs)
192193
self.namespace = namespace
193-
self.__storage__ = dict()
194194

195195
def __setitem__(self, name, value):
196196
value = str(value)
197197
if value.isdigit():
198198
value = int(value)
199199

200-
self.__storage__[name] = value
201-
202-
def __getitem__(self, name):
203-
return self.__storage__[name]
204-
205-
def __delitem__(self, name):
206-
del self.__storage__[name]
207-
208-
def __len__(self):
209-
return len(self.__storage__)
210-
211-
def __iter__(self):
212-
return iter(self.__storage__)
213-
214-
def __repr__(self):
215-
return "<{0} {1}>".format(self.__class__.__name__, str(dict(self)))
216-
217-
def iteritems(self):
218-
""" Impletment iteritems. """
219-
for key in self.__storage__.keys():
220-
yield key, self[key]
221-
222-
items = lambda s: list(s.iteritems())
200+
super(Section, self).__setitem__(name, value)
223201

224202

225203
class InterpolationSection(Section):
@@ -246,19 +224,28 @@ def __interpolate__(self, math):
246224
except KeyError:
247225
return ''
248226

249-
def __getitem__(self, name):
227+
def __getitem__(self, name, raw=False):
250228
value = super(InterpolationSection, self).__getitem__(name)
251-
sample = undefined
252-
while sample != value:
253-
try:
254-
sample, value = value, self.var_re.sub(
255-
self.__interpolate__, value)
256-
except RuntimeError:
257-
message = "Interpolation failed: {0}".format(name)
258-
NS_LOGGER.error(message)
259-
raise ValueError(message)
229+
if not raw:
230+
sample = undefined
231+
while sample != value:
232+
try:
233+
sample, value = value, self.var_re.sub(
234+
self.__interpolate__, value)
235+
except RuntimeError:
236+
message = "Interpolation failed: {0}".format(name)
237+
NS_LOGGER.error(message)
238+
raise ValueError(message)
260239
return value
261240

241+
def iteritems(self, raw=False):
242+
""" Iterate self items. """
243+
244+
for key in self:
245+
yield key, self.__getitem__(key, raw=raw)
246+
247+
items = iteritems
248+
262249

263250
class Namespace(object):
264251

@@ -356,6 +343,7 @@ def parse(self, source, update=True, **params):
356343
scanner.scan()
357344

358345
section = self.default_section
346+
name = None
359347

360348
for token in scanner.tokens:
361349
if token[0] == 'KEY':
@@ -368,6 +356,13 @@ def parse(self, source, update=True, **params):
368356
elif token[0] == 'SECTION':
369357
section = token[1].strip('[]')
370358

359+
elif token[0] == 'CONTINUATION':
360+
if not name:
361+
raise SyntaxError(
362+
"SyntaxError[@char {0}: {1}]".format(
363+
token[2], "Bad continuation."))
364+
self[section][name] += '\n' + token[1].strip()
365+
371366
def __getitem__(self, name):
372367
""" Look name in self sections.
373368
@@ -406,4 +401,4 @@ class InterpolationNamespace(Namespace):
406401

407402
section_type = InterpolationSection
408403

409-
# lint_ignore=W0201,R0924,F0401
404+
# pylama:ignore=D,W02,E731,W0621

0 commit comments

Comments
 (0)
0