def run(self, edit): fd, tmp_path = tempfile.mkstemp() open(tmp_path, 'w').write(self.view.substr(sublime.Region(0, self.view.size()))) params = [tmp_path, "-i", "-v"] settings = sublime.load_settings('AutoPep8.sublime-settings') if settings.get("ignore"): params.append("--ignore=" + settings.get("ignore")) if settings.get("select"): params.append("--select=" + settings.get("select")) autopep8.main(params) self.view.replace(edit, sublime.Region(0, self.view.size()), open(tmp_path, 'r').read())
def run_autopep8(args): import autopep8 if autopep8.__version__ < '1.2': print('upgrade to autopep8 >= 1.2 (installed: {:})'.format(str(autopep8.__version__))) exit(1) autopep8mode = '--in-place' if args.autopep8 == 'fix' else '--diff' argv = ['autopep8', '-r', 'postpic', '--ignore-local-config', autopep8mode, \ '--ignore=W391,E123,E226,E24' ,'--max-line-length=99'] print('===== running autopep8 =====') print('autopep8 version: ' + autopep8.__version__) print('$ ' + ' '.join(argv)) autopep8.main(argv)
def main(): # wrap autopep8.main for f in get_files(): msg = 'Discovered changes in {}'.format(f) for range in get_changed_lines(f): sys.stderr.write(msg) msg = '' sys.stderr.write(' {}..{}'.format(*range)) sys.stderr.flush() autopep8.main(sys.argv + ['--line-range', *range, f]) if not msg: sys.stderr.write('\n')
def run(self, edit): output = StringIO.StringIO() params = [sublime.active_window().active_view().file_name(), "-d", "-v"] settings = sublime.load_settings('AutoPep8.sublime-settings') if settings.get("ignore"): params.append("--ignore=" + settings.get("ignore")) if settings.get("select"): params.append("--select=" + settings.get("select")) output.write(params) autopep8.main(params, output) output.read() sublime.active_window().new_file() sublime.active_window().active_view().insert(edit, 0, output.buf)
def autopep8(line, cell): try: (_, tmp_path) = tempfile.mkstemp() with open(tmp_path, 'w') as fd: fd.write(cell) old_sys_argv = sys.argv.copy() sys.argv = [''] if line: sys.argv += line.split() sys.argv.append(tmp_path) main() finally: sys.argv = old_sys_argv.copy() os.remove(tmp_path)
def main(argv=None): """ :param argv: name of file for firmatinf :type: list :return: redut code """ try: import autopep8 except Exception: print("Error: can't import autopep8") return 1 if argv is None: argv = sys.argv autopep8.main(["autopep8", "--in-place", "--aggressive", "--aggressive"] + argv[1:]) return 0
def main(): return autopep8.main()
{lines_columns} is a list of lines, columns with invokes to {old_class_name}. :return: Return list of integer with value of # line modified ''' regex_old_new = r'\"(?P<old>\w*)(\" to \")(?P<new>\w*)\"' match_old_new = re.search(regex_old_new, result['info']) regex_lc = r"(?P<lines_columns>\[[\(\d, \)]*\])" match_lc = re.search(regex_lc, result['info']) if not match_lc or not match_old_new: return [] str_old = match_old_new.group('old') str_new = match_old_new.group('new') lines_columns = ast.literal_eval( match_lc.group('lines_columns')) lines_modified = [] for line, column in lines_columns: target = self.source[line - 1] offset = column - 1 fixed = target[:offset] + target[offset:].replace( str_old, str_new, 1) self.source[line - 1] = fixed lines_modified.append(line) return lines_modified autopep8.FixPEP8 = FixPEP8 if __name__ == '__main__': sys.exit(autopep8.main())
except IndentationError: pass for (old, new), count in replacements.items(): tmp = source.replace(old, new, count) # check to make sure number of replacements is correct if tmp.replace(old, new) == tmp: source = tmp return source def fix_l99902(source): """ Force utf-8 encoding """ lines = StringIO(source).readlines() if len(lines) > 2: if ('coding' not in lines[0].lower() and 'coding' not in lines[1].lower()): pos = 1 if lines[0][:2] == "#!" else 0 lines.insert(pos, '# coding: utf-8\n') return ''.join(lines) autopep8.fix_l99901 = fix_l99901 autopep8.fix_l99902 = fix_l99902 autopep8.DEFAULT_INDENT_SIZE = 2 if __name__ == '__main__': sys.exit(autopep8.main())