Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit304a68e

Browse files
committed
Update pylama to version 4.0.1 Supports configuration from setup.cfg, tox.ini, pytest.ini files
1 parentd09e30d commit304a68e

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
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
""" Parse arguments from command line and configuration files. """
22
importfnmatch
33
importsys
4-
fromosimportgetcwd,path
4+
importos
55
fromreimportcompileasre
66

77
importlogging
@@ -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)forbasenamein
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="Errorformat.")
83+
help="Choose errorsformat (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_argument(
@@ -100,7 +103,7 @@ def parse_linters(linters):
100103
type=lambdas: [re(fnmatch.translate(p))forpins.split(',')ifp],
101104
help="Skip files by masks (comma-separated, Ex. */messages.py)")
102105

103-
PARSER.add_argument("--report","-r",help="Filename forreport.")
106+
PARSER.add_argument("--report","-r",help="Sendreport 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-
fork,sincfg.sections.items():
155-
ifk==cfg.default_section:
157+
forname,optsincfg.sections.items():
158+
159+
ifnotname.startswith('pylama'):
160+
continue
161+
162+
ifname==cfg.default_section:
156163
continue
157-
ifkinLINTERS:
158-
options.linter_params[k]=dict(s)
164+
165+
name=name[7:]
166+
167+
ifnameinLINTERS:
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
returnvalue
188196

189197

190-
defget_config(ini_path=DEFAULT_INI_PATH):
198+
defget_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+
ifnotini_path:
208+
forpathinCONFIG_FILES:
209+
ifos.path.isfile(path)andos.access(path,os.R_OK):
210+
config.read(path)
211+
else:
212+
config.read(ini_path)
199213

200214
returnconfig
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
importio
2020
importre
2121
importlogging
22-
fromcollectionsimportMutableMapping
2322
try:
2423
fromcollectionsimportOrderedDict
2524
exceptImportError:
@@ -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-
classSection(MutableMapping):
187+
classSection(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
ifvalue.isdigit():
198198
value=int(value)
199199

200-
self.__storage__[name]=value
201-
202-
def__getitem__(self,name):
203-
returnself.__storage__[name]
204-
205-
def__delitem__(self,name):
206-
delself.__storage__[name]
207-
208-
def__len__(self):
209-
returnlen(self.__storage__)
210-
211-
def__iter__(self):
212-
returniter(self.__storage__)
213-
214-
def__repr__(self):
215-
return"<{0} {1}>".format(self.__class__.__name__,str(dict(self)))
216-
217-
defiteritems(self):
218-
""" Impletment iteritems. """
219-
forkeyinself.__storage__.keys():
220-
yieldkey,self[key]
221-
222-
items=lambdas:list(s.iteritems())
200+
super(Section,self).__setitem__(name,value)
223201

224202

225203
classInterpolationSection(Section):
@@ -246,19 +224,28 @@ def __interpolate__(self, math):
246224
exceptKeyError:
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-
whilesample!=value:
253-
try:
254-
sample,value=value,self.var_re.sub(
255-
self.__interpolate__,value)
256-
exceptRuntimeError:
257-
message="Interpolation failed: {0}".format(name)
258-
NS_LOGGER.error(message)
259-
raiseValueError(message)
229+
ifnotraw:
230+
sample=undefined
231+
whilesample!=value:
232+
try:
233+
sample,value=value,self.var_re.sub(
234+
self.__interpolate__,value)
235+
exceptRuntimeError:
236+
message="Interpolation failed: {0}".format(name)
237+
NS_LOGGER.error(message)
238+
raiseValueError(message)
260239
returnvalue
261240

241+
defiteritems(self,raw=False):
242+
""" Iterate self items. """
243+
244+
forkeyinself:
245+
yieldkey,self.__getitem__(key,raw=raw)
246+
247+
items=iteritems
248+
262249

263250
classNamespace(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
fortokeninscanner.tokens:
361349
iftoken[0]=='KEY':
@@ -368,6 +356,13 @@ def parse(self, source, update=True, **params):
368356
eliftoken[0]=='SECTION':
369357
section=token[1].strip('[]')
370358

359+
eliftoken[0]=='CONTINUATION':
360+
ifnotname:
361+
raiseSyntaxError(
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)

[8]ページ先頭

©2009-2025 Movatter.jp