Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check(expected_filename, input_filename, aggressive):
"""Test and compare output.
Return True on success.
"""
got = autopep8.fix_file(
input_filename,
options=autopep8.parse_args([''] + aggressive * ['--aggressive']))
try:
with autopep8.open_with_encoding(expected_filename) as expected_file:
expected = expected_file.read()
except IOError:
expected = None
if expected == got:
return True
else:
got_filename = expected_filename + '.err'
encoding = autopep8.detect_encoding(input_filename)
with autopep8.open_with_encoding(got_filename,
encoding=encoding,
mode='w') as got_file:
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', ''])
)
connection, client_address = sock.accept()
try:
buf = b''
while len(buf) < 4:
buf += connection.recv(4 - len(buf))
(size,) = unpack('>i', buf)
if size == -1:
#print('Format server exiting.', file=sys.stderr)
sys.exit(0)
src = b''
while len(src) < size:
src += connection.recv(4096)
src = src.decode('utf-8')
reformatted = autopep8.fix_code(
src,
options=autopep8.parse_args(['--ignore', 'E302', '']))
encoded = reformatted.encode('utf-8')
connection.sendall(pack('>i', len(encoded)))
connection.sendall(encoded)
finally:
connection.close()
def run_autopep(filename):
cmd_args = ['dummy', '-d']
args = autopep8.parse_args(cmd_args)
args.aggressive = 2
args.in_place = True
args.diff = False
args.max_line_length = 66
autopep8.fix_file(filename, args)
if not any(x in filename for x in import_fixed) or "internal" in filename:
isort.SortImports(filename)
run_autoflake(filename)
if icon is None:
plugin_code += action_noicon.format()
else:
plugin_code += action_icon.format(icon)
if menu:
plugin_code += menu_def.format(category)
if toolbar:
plugin_code += toolbar_def.format(category)
# Indent code by two levels
code = indent(code, 2 * 4)
plugin_code += default.format(code)
try:
import autopep8
plugin_code = autopep8.fix_code(plugin_code,
options=autopep8.parse_args(
['--aggressive', '--aggressive', '']))
except ImportError:
pass
return plugin_code
# -*- coding: utf-8 -*-
"""
"""
import glob
import os
from os import path
import autopep8 as ap
# See options at:
# https://pypi.python.org/pypi/autopep8/#usage
#-i : in place editing
options = ap.parse_args(['-i', ''])
try:
cur_path = path.dirname(path.realpath(__file__))
except NameError:
# ASSUMES IN ROOT PATH - i.e. that wormpy package is in this folder
cur_path = os.getcwd()
wormpy_path = path.join(cur_path, 'wormpy')
stats_path = path.join(wormpy_path,'stats')
print(wormpy_path)
wormpy_files = glob.glob(path.join(wormpy_path, '*.py'))
root_files = glob.glob(path.join(cur_path, '*.py'))
stats_files = glob.glob(path.join(stats_path, '*.py'))
def autopep8(self, arglist=[]):
"""Enables autopep8 integration."""
import autopep8
args = autopep8.parse_args([""]+arglist)
def pep8_fixer(code, **kwargs):
"""Automatic PEP8 fixer."""
return autopep8.fix_code(code, options=args)
self.postprocs.append(pep8_fixer)
def reformat_white_space():
try:
import autopep8
except ImportError:
print(WARNING + "Could not find 'autopep8', exceeding whitespace will not be removed!" + TERMINATOR)
return
merchant_dir_path = os.path.abspath("./{{ cookiecutter.app_name }}")
args = autopep8.parse_args(['--max-line-length 119', '--in-place', '--recursive'])
if os.path.exists(merchant_dir_path):
autopep8.fix_multiple_files([merchant_dir_path], args)