Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 740bd74

Browse files
committed
Update pylama
1 parent d17f039 commit 740bd74

Some content is hidden

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

81 files changed

+122
-61
lines changed

pylibs/pylama/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
:license: BSD, see LICENSE for more details.
66
"""
77

8-
version_info = 1, 0, 4
8+
version_info = 1, 1, 0
99

1010
__version__ = version = '.'.join(map(str, version_info))
1111
__project__ = __name__
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

pylibs/pylama/checkers/pylint/logilab/astng/brain/__init__.py

Whitespace-only changes.

pylibs/pylama/core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" Pylama core.
1+
""" Pylama core functionality. Get params and runs a checkers.
22
"""
33
import logging
44
import re
@@ -10,7 +10,7 @@
1010
LOGGER = logging.getLogger('pylama')
1111
MODERE = re.compile(r'^\s*#\s+(?:pymode\:)?((?:lint[\w_]*=[^:\n\s]+:?)+)',
1212
re.I | re.M)
13-
SKIP_PATTERN = '# nolint'
13+
SKIP_PATTERN = '# noqa'
1414
STREAM = logging.StreamHandler()
1515

1616
LOGGER.addHandler(STREAM)
@@ -32,6 +32,7 @@ def run(path, ignore=None, select=None, linters=DEFAULT_LINTERS, config=None,
3232
code = f.read() + '\n\n'
3333
params = config or __parse_modeline(code)
3434
params['skip'] = [False]
35+
3536
for line in code.split('\n'):
3637
params['skip'].append(line.endswith(SKIP_PATTERN))
3738

@@ -82,7 +83,7 @@ def run(path, ignore=None, select=None, linters=DEFAULT_LINTERS, config=None,
8283

8384
except Exception:
8485
import traceback
85-
logging.error(traceback.format_exc())
86+
logging.debug(traceback.format_exc())
8687

8788
errors = [er for er in errors if __ignore_error(er, select, ignore)]
8889
return sorted(errors, key=lambda x: x['lnum'])

pylibs/pylama/hook.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" SCM hooks.
1+
""" SCM hooks. Integration with git and mercurial.
22
"""
33
from __future__ import absolute_import
44

@@ -10,7 +10,7 @@
1010

1111

1212
try:
13-
from configparser import ConfigParser # nolint
13+
from configparser import ConfigParser # noqa
1414
except ImportError: # Python 2
1515
from ConfigParser import ConfigParser
1616

@@ -95,11 +95,15 @@ def install_hook(path):
9595
git = op.join(path, '.git', 'hooks')
9696
hg = op.join(path, '.hg')
9797
if op.exists(git):
98-
install_git(git) and LOGGER.warn('Git hook has been installed.') # nolint
98+
install_git(git)
99+
LOGGER.warn('Git hook has been installed.')
99100

100101
elif op.exists(hg):
101-
install_hg(git) and LOGGER.warn('Mercurial hook has been installed.') # nolint
102+
install_hg(git)
103+
LOGGER.warn('Mercurial hook has been installed.')
102104

103105
else:
104106
LOGGER.error('VCS has not found. Check your path.')
105107
sys.exit(1)
108+
109+
# lint_ignore=F0401

pylibs/pylama/inirama.py

Lines changed: 69 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
"""
22
Inirama is a python module that parses INI files.
33
4+
.. _badges:
45
.. include:: ../README.rst
5-
:start-line: 5
6-
:end-line: 12
6+
:start-after: .. _badges:
7+
:end-before: .. _contents:
8+
9+
.. _description:
10+
.. include:: ../README.rst
11+
:start-after: .. _description:
12+
:end-before: .. _badges:
713
814
:copyright: 2013 by Kirill Klenov.
915
:license: BSD, see LICENSE for more details.
@@ -20,7 +26,7 @@
2026
from ordereddict import OrderedDict
2127

2228

23-
__version__ = '0.4.0'
29+
__version__ = '0.4.1'
2430
__project__ = 'Inirama'
2531
__author__ = "Kirill Klenov <[email protected]>"
2632
__license__ = "BSD"
@@ -31,11 +37,14 @@
3137

3238
class Scanner(object):
3339

40+
""" Split a code string on tokens. """
41+
3442
def __init__(self, source, ignore=None, patterns=None):
3543
""" Init Scanner instance.
3644
37-
:param patterns: List of token patterns [(token, regexp)]
38-
:param ignore: List of ignored tokens
45+
:param patterns: List of token patterns [(token, regexp)]
46+
:param ignore: List of ignored tokens
47+
3948
"""
4049
self.reset(source)
4150
if patterns:
@@ -47,17 +56,18 @@ def __init__(self, source, ignore=None, patterns=None):
4756
self.ignore = ignore
4857

4958
def reset(self, source):
50-
""" Reset scanner.
59+
""" Reset scanner's state.
60+
61+
:param source: Source for parsing
5162
52-
:param source: Source for parsing
5363
"""
5464
self.tokens = []
5565
self.source = source
5666
self.pos = 0
5767

5868
def scan(self):
59-
""" Scan source and grab tokens.
60-
"""
69+
""" Scan source and grab tokens. """
70+
6171
self.pre_scan()
6272

6373
token = None
@@ -98,18 +108,23 @@ def scan(self):
98108
self.tokens.append(token)
99109

100110
def pre_scan(self):
101-
""" Prepare source.
102-
"""
111+
""" Prepare source. """
103112
pass
104113

105114
def __repr__(self):
106-
""" Print the last 5 tokens that have been scanned in
115+
""" Print the last 5 tokens that have been scanned in.
116+
117+
:return str:
118+
107119
"""
108120
return '<Scanner: ' + ','.join(
109121
"{0}({2}:{3})".format(*t) for t in self.tokens[-5:]) + ">"
110122

111123

112124
class INIScanner(Scanner):
125+
126+
""" Get tokens for INI. """
127+
113128
patterns = [
114129
('SECTION', re.compile(r'\[[^]]+\]')),
115130
('IGNORE', re.compile(r'[ \r\t\n]+')),
@@ -119,6 +134,7 @@ class INIScanner(Scanner):
119134
ignore = ['IGNORE']
120135

121136
def pre_scan(self):
137+
""" Prepare string for scaning. """
122138
escape_re = re.compile(r'\\\n[\t ]+')
123139
self.source = escape_re.sub('', self.source)
124140

@@ -128,6 +144,8 @@ def pre_scan(self):
128144

129145
class Section(MutableMapping):
130146

147+
""" Representation of INI section. """
148+
131149
def __init__(self, namespace, *args, **kwargs):
132150
super(Section, self).__init__(*args, **kwargs)
133151
self.namespace = namespace
@@ -152,6 +170,7 @@ def __repr__(self):
152170
return "<{0} {1}>".format(self.__class__.__name__, str(dict(self)))
153171

154172
def iteritems(self):
173+
""" Impletment iteritems. """
155174
for key in self.__storage__.keys():
156175
yield key, self[key]
157176

@@ -160,9 +179,17 @@ def iteritems(self):
160179

161180
class InterpolationSection(Section):
162181

182+
""" INI section with interpolation support. """
183+
163184
var_re = re.compile('{([^}]+)}')
164185

165186
def get(self, name, default=None):
187+
""" Get item by name.
188+
189+
:return object: value or None if name not exists
190+
191+
"""
192+
166193
if name in self:
167194
return self[name]
168195
return default
@@ -189,26 +216,28 @@ def __getitem__(self, name):
189216

190217

191218
class Namespace(object):
219+
192220
""" Default class for parsing INI.
193221
194-
:param **default_items: Default items for default section.
222+
:param **default_items: Default items for default section.
195223
196-
Usage
197-
-----
224+
Usage
225+
-----
198226
199-
::
227+
::
200228
201-
from inirama import Namespace
229+
from inirama import Namespace
202230
203-
ns = Namespace()
204-
ns.read('config.ini')
231+
ns = Namespace()
232+
ns.read('config.ini')
205233
206-
print ns['section']['key']
234+
print ns['section']['key']
207235
208-
ns['other']['new'] = 'value'
209-
ns.write('new_config.ini')
236+
ns['other']['new'] = 'value'
237+
ns.write('new_config.ini')
210238
211239
"""
240+
212241
#: Name of default section (:attr:`~inirama.Namespace.default`)
213242
default_section = 'DEFAULT'
214243

@@ -226,16 +255,20 @@ def __init__(self, **default_items):
226255
@property
227256
def default(self):
228257
""" Return default section or empty dict.
258+
259+
:return :class:`inirama.Section`: section
260+
229261
"""
230262
return self.sections.get(self.default_section, dict())
231263

232264
def read(self, *files, **params):
233265
""" Read and parse INI files.
234266
235-
:param *files: Files for reading
236-
:param **params: Params for parsing
267+
:param *files: Files for reading
268+
:param **params: Params for parsing
269+
270+
Set `update=False` for prevent values redefinition.
237271
238-
Set `update=False` for prevent values redefinition.
239272
"""
240273
for f in files:
241274
try:
@@ -248,10 +281,10 @@ def read(self, *files, **params):
248281
raise
249282

250283
def write(self, f):
251-
"""
252-
Write namespace as INI file.
284+
""" Write namespace as INI file.
285+
286+
:param f: File object or path to file.
253287
254-
:param f: File object or path to file.
255288
"""
256289
if isinstance(f, str):
257290
f = io.open(f, 'w', encoding='utf-8')
@@ -270,8 +303,9 @@ def write(self, f):
270303
def parse(self, source, update=True, **params):
271304
""" Parse INI source as string.
272305
273-
:param source: Source of INI
274-
:param update: Replace alredy defined items
306+
:param source: Source of INI
307+
:param update: Replace alredy defined items
308+
275309
"""
276310
scanner = INIScanner(source)
277311
scanner.scan()
@@ -291,6 +325,9 @@ def parse(self, source, update=True, **params):
291325

292326
def __getitem__(self, name):
293327
""" Look name in self sections.
328+
329+
:return :class:`inirama.Section`: section
330+
294331
"""
295332
if not name in self.sections:
296333
self.sections[name] = self.section_type(self)
@@ -304,6 +341,7 @@ def __repr__(self):
304341

305342

306343
class InterpolationNamespace(Namespace):
344+
307345
""" That implements the interpolation feature.
308346
309347
::
@@ -323,4 +361,4 @@ class InterpolationNamespace(Namespace):
323361

324362
section_type = InterpolationSection
325363

326-
# lint_ignore=W0201,R0924
364+
# lint_ignore=W0201,R0924,F0401

pylibs/pylama/main.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,14 @@ def shell():
102102
if op.isdir(options.path):
103103
paths = []
104104
for root, _, files in walk(options.path):
105-
paths += [op.join(root, f) for f in files if f.endswith('.py')]
105+
paths += [
106+
op.relpath(op.join(root, f), curdir)
107+
for f in files if f.endswith('.py')]
106108

107109
check_files(
108110
paths,
109111
async=options.async,
110-
rootpath=options.path,
112+
rootpath=curdir,
111113
skip=options.skip,
112114
frmt=options.format,
113115
ignore=options.ignore,
@@ -132,12 +134,12 @@ def check_files(paths, rootpath=None, skip=None, frmt="pep8", async=False,
132134
params = dict()
133135
if config:
134136
for key, section in config.sections.items():
135-
if key != 'main':
136-
params[op.abspath(key)] = prepare_params(section)
137+
if key != config.default_section:
138+
mask = re.compile(fnmatch.translate(key))
139+
params[mask] = prepare_params(section)
137140

138141
work_paths = []
139142
for path in paths:
140-
path = op.abspath(path)
141143
if skip and any(pattern.match(path) for pattern in skip):
142144
LOGGER.info('Skip path: %s', path)
143145
continue
@@ -164,9 +166,5 @@ def prepare_params(section):
164166
return params
165167

166168

167-
def __parse_options(args=None):
168-
pass
169-
170-
171169
if __name__ == '__main__':
172170
shell()

pylibs/pylama/tasks.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,16 @@ def check_path(path, rootpath='.', ignore=None, select=None, linters=None,
9191

9292
LOGGER.info("Parse file: %s", path)
9393
params = params or dict()
94+
config = dict()
95+
96+
for mask in params:
97+
if mask.match(path):
98+
config.update(params[mask])
9499

95100
errors = []
96-
for error in run(path, ignore=ignore, select=select, linters=linters,
97-
complexity=complexity, config=params.get(path)):
101+
for error in run(
102+
path, ignore=ignore, select=select, linters=linters,
103+
complexity=complexity, config=config):
98104
try:
99105
error['rel'] = op.relpath(
100106
error['filename'], op.dirname(rootpath))

0 commit comments

Comments
 (0)