本文整理汇总了Python中autopep8.parse_args方法的典型用法代码示例。如果您正苦于以下问题:Python autopep8.parse_args方法的具体用法?Python autopep8.parse_args怎么用?Python autopep8.parse_args使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autopep8
的用法示例。
在下文中一共展示了autopep8.parse_args方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prg2py_after_preproc
# 需要导入模块: import autopep8 [as 别名]
# 或者: from autopep8 import parse_args [as 别名]
def prg2py_after_preproc(data, parser_start, input_filename):
input_stream = antlr4.InputStream(data)
lexer = VisualFoxpro9Lexer(input_stream)
stream = antlr4.CommonTokenStream(lexer)
parser = VisualFoxpro9Parser(stream)
tree = run_parser(stream, parser, parser_start)
TreeCleanVisitor().visit(tree)
output_tree = PythonConvertVisitor(input_filename).visit(tree)
if not isinstance(output_tree, list):
return output_tree
output = add_indents(output_tree, 0)
options = autopep8.parse_args(['--max-line-length', '100000', '-'])
output = autopep8.fix_code(output, options)
tokens = list(tokenize.generate_tokens(io.StringIO(output).readline))
for i, token in enumerate(tokens):
token = list(token)
if token[0] == tokenize.STRING and token[1].startswith('u'):
token[1] = token[1][1:]
tokens[i] = tuple(token)
return tokenize.untokenize(tokens)
示例2: autopep8
# 需要导入模块: import autopep8 [as 别名]
# 或者: from autopep8 import parse_args [as 别名]
def autopep8(args):
"""Format code according to PEP8
"""
try:
import autopep8
except:
error('autopep8 not found! Run "paver install_devtools".')
sys.exit(1)
if any(x not in args for x in ['-i', '--in-place']):
args.append('-i')
args.append('--ignore=E261,E265,E402,E501')
args.insert(0, 'dummy')
cmd_args = autopep8.parse_args(args)
excludes = ('ext-lib', 'ext-src')
for p in options.plugin.source_dir.walk():
if any(exclude in p for exclude in excludes):
continue
if p.fnmatch('*.py'):
autopep8.fix_file(p, options=cmd_args)
示例3: test_autopep8_args
# 需要导入模块: import autopep8 [as 别名]
# 或者: from autopep8 import parse_args [as 别名]
def test_autopep8_args(self):
import autopep8
args = ['hello.py']
us = parse_args(args)
them = autopep8.parse_args(args)
self.assertEqual(us.select, them.select)
self.assertEqual(us.ignore, them.ignore)
args = ['hello.py', '--select=E1,W1', '--ignore=W601',
'--max-line-length', '120']
us = parse_args(args)
them = autopep8.parse_args(args)
self.assertEqual(us.select, them.select)
self.assertEqual(us.ignore, them.ignore)
self.assertEqual(us.max_line_length, them.max_line_length)
args = ['hello.py', '--aggressive', '-v']
us = parse_args(args)
them = autopep8.parse_args(args)
self.assertEqual(us.aggressive, them.aggressive)
示例4: gen
# 需要导入模块: import autopep8 [as 别名]
# 或者: from autopep8 import parse_args [as 别名]
def gen(path,
method=None,
query_params=None,
data=None,
content_type=None):
# generates python code representing a call via django client.
# useful for use in testing
method = method.lower()
t = jinja2.Template(template)
if method == 'get':
r = t.render(path=path,
data=query_params,
lower_case_method=method,
content_type=content_type)
else:
if query_params:
query_params = _encode_query_params(query_params)
path += query_params
if is_str_typ(data):
data = "'%s'" % data
r = t.render(path=path,
data=data,
lower_case_method=method,
query_params=query_params,
content_type=content_type)
return autopep8.fix_code(
r, options=autopep8.parse_args(['--aggressive', ''])
)
示例5: test_no_config
# 需要导入模块: import autopep8 [as 别名]
# 或者: from autopep8 import parse_args [as 别名]
def test_no_config(self):
args_before = parse_args(apply_config=False, root=TEMP_DIR)
self.assertNotIn('E999', args_before.ignore)
示例6: test_global_config
# 需要导入模块: import autopep8 [as 别名]
# 或者: from autopep8 import parse_args [as 别名]
def test_global_config(self):
with open(GLOBAL_CONFIG, mode='w') as f:
f.write("[pep8]\nignore=E999")
args_after = parse_args(['--global-config=%s' % GLOBAL_CONFIG],
apply_config=True, root=TEMP_DIR)
self.assertIn('E999', args_after.ignore)
args_after = parse_args(['--global-config=False'],
apply_config=True, root=TEMP_DIR)
self.assertNotIn('E999', args_after.ignore)
示例7: test_local_config
# 需要导入模块: import autopep8 [as 别名]
# 或者: from autopep8 import parse_args [as 别名]
def test_local_config(self):
with open(LOCAL_CONFIG, mode='w') as f:
f.write("[pep8]\nignore=E999")
args_after = parse_args([''],
apply_config=True, root=TEMP_DIR)
self.assertIn('E999', args_after.ignore)
args_after = parse_args(['--ignore-local-config'],
apply_config=True, root=TEMP_DIR)
self.assertNotIn('E999', args_after.ignore)
示例8: test_local_and_global_config
# 需要导入模块: import autopep8 [as 别名]
# 或者: from autopep8 import parse_args [as 别名]
def test_local_and_global_config(self):
with open(GLOBAL_CONFIG, mode='w') as f:
f.write("[pep8]\nindent-size=2")
with open(LOCAL_CONFIG, mode='w') as f:
f.write("[pep8]\nindent-size=3")
args_after = parse_args(['--global-config=%s' % GLOBAL_CONFIG],
apply_config=True, root=TEMP_DIR)
self.assertEqual(3, args_after.indent_size)
args_after = parse_args(['--global-config=%s' % GLOBAL_CONFIG,
'--ignore-local-config'],
apply_config=True, root=TEMP_DIR)
self.assertEqual(2, args_after.indent_size)
示例9: test_pep8
# 需要导入模块: import autopep8 [as 别名]
# 或者: from autopep8 import parse_args [as 别名]
def test_pep8(self):
# verify all files are nicely styled
python_filepaths = get_python_filepaths()
style_guide = get_style_guide()
fake_stdout = io.StringIO()
with patch('sys.stdout', fake_stdout):
report = style_guide.check_files(python_filepaths)
# if flake8 didnt' report anything, we're done
if report.total_errors == 0:
return
# grab on which files we have issues
flake8_issues = fake_stdout.getvalue().split('\n')
broken_filepaths = {item.split(':')[0] for item in flake8_issues if item}
# give hints to the developer on how files' style could be improved
options = autopep8.parse_args([''])
options.aggressive = 1
options.diff = True
options.max_line_length = 99
issues = []
for filepath in broken_filepaths:
diff = autopep8.fix_file(filepath, options=options)
if diff:
issues.append(diff)
report = ["Please fix files as suggested by autopep8:"] + issues
report += ["\n-- Original flake8 reports:"] + flake8_issues
self.fail("\n".join(report))