commit python3-autopep8 for openSUSE:Factory
Hello community, here is the log from the commit of package python3-autopep8 for openSUSE:Factory checked in at 2015-02-27 11:10:19 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python3-autopep8 (Old) and /work/SRC/openSUSE:Factory/.python3-autopep8.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "python3-autopep8" Changes: -------- --- /work/SRC/openSUSE:Factory/python3-autopep8/python3-autopep8.changes 2014-12-16 14:49:01.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.python3-autopep8.new/python3-autopep8.changes 2015-02-27 11:10:21.000000000 +0100 @@ -1,0 +2,83 @@ +Thu Feb 26 16:53:50 UTC 2015 - arun@gmx.de + +- update to version 1.1.1: + * fix fail test when use sdist files + * ignore coverage data + * Update due to change in "pep8" + * Suppress false positive + * Test against "LANG=" + * Fall back to "sys.getdefaultencoding()" + * Increment copyright date + +- changes from version 1.1: + * Add note + * Add for 5edb790ee5555e42992cb38885c9c72ad70a5918 + * Fix exclude in recursive mode + * fix fix_e265 comment + * Clean up + * Add suppressions for Python 2 + * Format + * Add future imports + * Remove untested code + * Remove broken and untested code + * Put "and" in the right place + * Format + * Add missing "r" + * Mention pep8 + * cln expand long test to multiline string + * Add note + * pep8 failure (E501 not picked up by autopep8?) + * fix multi-line docstrings over range + * cln remove comment indentation first + * TST additional range comment test for comment followed by new line + * FIX comments in line range are indented to match subsequent line + * Simplify + * Format + * Use parentheses uniformly + * Remove user-dependent test + * Read configuration after filename normalization + * Find configuration file correctly + * Clean up + * Clean up + * Make tests safer + * Clean up + * Undo home directory expansion in documentation + * Allowing leading "--" in configuration + * Clean up + * Add back Python 2.6 support + * Add missing usage of "GLOBAL_CONFIG" + * Set development version + * Handle more errors + * Use non-deprecated import + * Document new options + * Format + * Remove unnecessary method + * Revert 1f782659f13adf63969fb3d41bdbdf6cb56d148a + * CLN remove _main + * CLN remove pragma: no cover as not needed with coveralls cc @myint + * CLN parse args twice, no manual arguments checking + * FIX autocomplete for --global-config arg and with space sep + * Use lowercase + * Generalize + * Remove bad backslash + * Avoid getting into bad state due to E901 + * Remove flaky lib2to3 "import" fixer + * API use --global-config and --ignore-local-config arguments + * TST check passing arg overrides default/config + * ENH add --config argument + * Mention pep8 repository + * Remove bad-syntax inducing code + * Format + * Clean up + * Clean up + * Remove no-longer-working script + * include spaces in the 'class' or 'def' checks + * improve e302 fix code + * fix suite tests + * fix infinite loop in e501 experimental_decorator unit test + * extend E302 fix (comments before class definition) + * fix #145 + * fix #161 + + +------------------------------------------------------------------- Old: ---- autopep8-1.0.4.tar.gz New: ---- autopep8-1.1.1.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python3-autopep8.spec ++++++ --- /var/tmp/diff_new_pack.uNNMcF/_old 2015-02-27 11:10:22.000000000 +0100 +++ /var/tmp/diff_new_pack.uNNMcF/_new 2015-02-27 11:10:22.000000000 +0100 @@ -1,7 +1,7 @@ # # spec file for package python3-autopep8 # -# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,7 +17,7 @@ Name: python3-autopep8 -Version: 1.0.4 +Version: 1.1.1 Release: 0 Url: https://github.com/hhatto/autopep8 Summary: Automatic generated to pep8 checked code ++++++ autopep8-1.0.4.tar.gz -> autopep8-1.1.1.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.0.4/AUTHORS.rst new/autopep8-1.1.1/AUTHORS.rst --- old/autopep8-1.0.4/AUTHORS.rst 2014-07-30 18:41:37.000000000 +0200 +++ new/autopep8-1.1.1/AUTHORS.rst 2014-12-25 03:20:09.000000000 +0100 @@ -20,3 +20,5 @@ - 小明 (https://github.com/dongweiming) - Andy Hayden (https://github.com/hayd) - Fabio Zadrozny (https://github.com/fabioz) +- Alex Chernetz (https://github.com/achernet) +- Marc Schlaich (https://github.com/schlamar) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.0.4/LICENSE new/autopep8-1.1.1/LICENSE --- old/autopep8-1.0.4/LICENSE 2014-04-11 03:54:44.000000000 +0200 +++ new/autopep8-1.1.1/LICENSE 2015-02-26 06:48:37.000000000 +0100 @@ -1,6 +1,6 @@ Copyright (C) 2010-2011 Hideo Hattori Copyright (C) 2011-2013 Hideo Hattori, Steven Myint -Copyright (C) 2013-2014 Hideo Hattori, Steven Myint, Bill Wendling +Copyright (C) 2013-2015 Hideo Hattori, Steven Myint, Bill Wendling Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.0.4/MANIFEST.in new/autopep8-1.1.1/MANIFEST.in --- old/autopep8-1.0.4/MANIFEST.in 2014-05-08 16:31:05.000000000 +0200 +++ new/autopep8-1.1.1/MANIFEST.in 2015-02-26 06:35:07.000000000 +0100 @@ -10,6 +10,7 @@ include test/example_with_reduce.py include test/example.py include test/iso_8859_1.py +include test/fake_configuration/.pep8 recursive-exclude test/suite *.py recursive-exclude test/suite/out *.py exclude .travis.yml @@ -21,7 +22,6 @@ exclude install_hooks.bash exclude test/.gitignore exclude test/acid.py -exclude test/acid_github.py exclude test/acid_pypi.py exclude test/suite exclude test/suite/out diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.0.4/PKG-INFO new/autopep8-1.1.1/PKG-INFO --- old/autopep8-1.0.4/PKG-INFO 2014-09-09 19:07:39.000000000 +0200 +++ new/autopep8-1.1.1/PKG-INFO 2015-02-26 06:58:32.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: autopep8 -Version: 1.0.4 +Version: 1.1.1 Summary: A tool that automatically formats Python code to conform to the PEP 8 style guide Home-page: https://github.com/hhatto/autopep8 Author: Hideo Hattori @@ -132,7 +132,8 @@ Options:: - usage: autopep8 [-h] [--version] [-v] [-d] [-i] [-r] [-j n] [-p n] [-a] + usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename] + [--ignore-local-config] [-r] [-j n] [-p n] [-a] [--experimental] [--exclude globs] [--list-fixes] [--ignore errors] [--select errors] [--max-line-length n] [--range line line] [--indent-size n] @@ -150,6 +151,14 @@ verbose messages -d, --diff print the diff for the fixed source -i, --in-place make changes to files in place + --global-config filename + path to a global pep8 config file; if this file does + not exist then this is ignored (default: + ~/.config/pep8) + --ignore-local-config + don't look for and apply local config files; if not + passed, defaults are updated with any config files in + the project's root directory -r, --recursive run recursively over directories; must be used with --in-place or --diff -j n, --jobs n number of parallel jobs; match CPU count if value is @@ -319,8 +328,7 @@ autopep8 against Python code and checks for correctness and completeness of the code fixes. It can check that the bytecode remains identical. ``test/acid_pypi.py`` makes use of ``acid.py`` to test against the latest - released packages on PyPI. In a similar fashion, ``test/acid_github.py`` tests - against Python code in Github repositories. + released packages on PyPI. Troubleshooting diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.0.4/README.rst new/autopep8-1.1.1/README.rst --- old/autopep8-1.0.4/README.rst 2014-06-10 14:41:58.000000000 +0200 +++ new/autopep8-1.1.1/README.rst 2014-12-25 03:20:09.000000000 +0100 @@ -124,7 +124,8 @@ Options:: - usage: autopep8 [-h] [--version] [-v] [-d] [-i] [-r] [-j n] [-p n] [-a] + usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename] + [--ignore-local-config] [-r] [-j n] [-p n] [-a] [--experimental] [--exclude globs] [--list-fixes] [--ignore errors] [--select errors] [--max-line-length n] [--range line line] [--indent-size n] @@ -142,6 +143,14 @@ verbose messages -d, --diff print the diff for the fixed source -i, --in-place make changes to files in place + --global-config filename + path to a global pep8 config file; if this file does + not exist then this is ignored (default: + ~/.config/pep8) + --ignore-local-config + don't look for and apply local config files; if not + passed, defaults are updated with any config files in + the project's root directory -r, --recursive run recursively over directories; must be used with --in-place or --diff -j n, --jobs n number of parallel jobs; match CPU count if value is @@ -311,8 +320,7 @@ autopep8 against Python code and checks for correctness and completeness of the code fixes. It can check that the bytecode remains identical. ``test/acid_pypi.py`` makes use of ``acid.py`` to test against the latest -released packages on PyPI. In a similar fashion, ``test/acid_github.py`` tests -against Python code in Github repositories. +released packages on PyPI. Troubleshooting diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.0.4/autopep8.egg-info/PKG-INFO new/autopep8-1.1.1/autopep8.egg-info/PKG-INFO --- old/autopep8-1.0.4/autopep8.egg-info/PKG-INFO 2014-09-09 19:07:39.000000000 +0200 +++ new/autopep8-1.1.1/autopep8.egg-info/PKG-INFO 2015-02-26 06:58:32.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: autopep8 -Version: 1.0.4 +Version: 1.1.1 Summary: A tool that automatically formats Python code to conform to the PEP 8 style guide Home-page: https://github.com/hhatto/autopep8 Author: Hideo Hattori @@ -132,7 +132,8 @@ Options:: - usage: autopep8 [-h] [--version] [-v] [-d] [-i] [-r] [-j n] [-p n] [-a] + usage: autopep8 [-h] [--version] [-v] [-d] [-i] [--global-config filename] + [--ignore-local-config] [-r] [-j n] [-p n] [-a] [--experimental] [--exclude globs] [--list-fixes] [--ignore errors] [--select errors] [--max-line-length n] [--range line line] [--indent-size n] @@ -150,6 +151,14 @@ verbose messages -d, --diff print the diff for the fixed source -i, --in-place make changes to files in place + --global-config filename + path to a global pep8 config file; if this file does + not exist then this is ignored (default: + ~/.config/pep8) + --ignore-local-config + don't look for and apply local config files; if not + passed, defaults are updated with any config files in + the project's root directory -r, --recursive run recursively over directories; must be used with --in-place or --diff -j n, --jobs n number of parallel jobs; match CPU count if value is @@ -319,8 +328,7 @@ autopep8 against Python code and checks for correctness and completeness of the code fixes. It can check that the bytecode remains identical. ``test/acid_pypi.py`` makes use of ``acid.py`` to test against the latest - released packages on PyPI. In a similar fashion, ``test/acid_github.py`` tests - against Python code in Github repositories. + released packages on PyPI. Troubleshooting diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.0.4/autopep8.egg-info/SOURCES.txt new/autopep8-1.1.1/autopep8.egg-info/SOURCES.txt --- old/autopep8-1.0.4/autopep8.egg-info/SOURCES.txt 2014-09-09 19:07:39.000000000 +0200 +++ new/autopep8-1.1.1/autopep8.egg-info/SOURCES.txt 2015-02-26 06:58:32.000000000 +0100 @@ -3,6 +3,7 @@ MANIFEST.in README.rst autopep8.py +setup.cfg setup.py autopep8.egg-info/PKG-INFO autopep8.egg-info/SOURCES.txt @@ -19,4 +20,5 @@ test/example_with_reduce.py test/iso_8859_1.py test/test_autopep8.py -test/test_suite.py \ No newline at end of file +test/test_suite.py +test/fake_configuration/.pep8 \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.0.4/autopep8.py new/autopep8-1.1.1/autopep8.py --- old/autopep8-1.0.4/autopep8.py 2014-09-09 19:06:54.000000000 +0200 +++ new/autopep8-1.1.1/autopep8.py 2015-02-26 06:57:06.000000000 +0100 @@ -2,7 +2,7 @@ # # Copyright (C) 2010-2011 Hideo Hattori # Copyright (C) 2011-2013 Hideo Hattori, Steven Myint -# Copyright (C) 2013-2014 Hideo Hattori, Steven Myint, Bill Wendling +# Copyright (C) 2013-2015 Hideo Hattori, Steven Myint, Bill Wendling # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -67,7 +67,7 @@ unicode = str -__version__ = '1.0.4' +__version__ = '1.1.1' CR = '\r' @@ -103,7 +103,6 @@ 'W690': ['apply', 'except', 'exitfunc', - 'import', 'numliterals', 'operator', 'paren', @@ -116,6 +115,14 @@ 'xreadlines']} +if sys.platform == 'win32': # pragma: no cover + DEFAULT_CONFIG = os.path.expanduser(r'~\.pep8') +else: + DEFAULT_CONFIG = os.path.join(os.getenv('XDG_CONFIG_HOME') or + os.path.expanduser('~/.config'), 'pep8') +PROJECT_CONFIG = ('setup.cfg', 'tox.ini', '.pep8') + + def open_with_encoding(filename, encoding=None, mode='r'): """Return opened file with a specific encoding.""" if not encoding: @@ -288,8 +295,11 @@ yield (start, '{0} {1}'.format(*error)) # Look for visual indenting. - if (parens[row] and token_type not in (tokenize.NL, tokenize.COMMENT) - and not indent[depth]): + if ( + parens[row] and + token_type not in (tokenize.NL, tokenize.COMMENT) and + not indent[depth] + ): indent[depth] = start[1] indent_chances[start[1]] = True # Deal with implicit string concatenation. @@ -885,7 +895,15 @@ second = (_get_indentation(logical_lines[0]) + target[offset:].lstrip(';').lstrip()) - self.source[line_index] = first + '\n' + second + # find inline commnet + inline_comment = None + if '# ' == target[offset:].lstrip(';').lstrip()[:2]: + inline_comment = target[offset:].lstrip(';') + + if inline_comment: + self.source[line_index] = first + inline_comment + else: + self.source[line_index] = first + '\n' + second return [line_index + 1] def fix_e711(self, result): @@ -1159,11 +1177,13 @@ # Normalize beginning if not a shebang. if len(line) > 1: + pos = next((index for index, c in enumerate(line) + if c != '#')) if ( # Leave multiple spaces like '# ' alone. - (line.count('#') > 1 or line[1].isalnum()) + (line[:pos].count('#') > 1 or line[1].isalnum()) and # Leave stylistic outlined blocks alone. - and not line.rstrip().endswith('#') + not line.rstrip().endswith('#') ): line = '# ' + line.lstrip('# \t') @@ -1571,7 +1591,7 @@ (self._prev_prev_item.is_name or self._prev_prev_item.is_number or self._prev_prev_item.is_string)) and - prev_text in ('+', '-', '%', '*', '/', '//', '**'))))) + prev_text in ('+', '-', '%', '*', '/', '//', '**', 'in'))))) ): self._lines.append(self._Space()) @@ -2642,6 +2662,8 @@ commented_out_code_line_numbers = commented_out_code_lines(source) + has_e901 = any(result['id'].lower() == 'e901' for result in results) + for r in results: issue_id = r['id'].lower() @@ -2673,6 +2695,13 @@ if issue_id.startswith(('e26', 'e501')): continue + # Do not touch indentation if there is a token error caused by + # incomplete multi-line statement. Otherwise, we risk screwing up the + # indentation. + if has_e901: + if issue_id.startswith(('e1', 'e7')): + continue + yield r @@ -2807,17 +2836,17 @@ return True -def fix_code(source, options=None, encoding=None): +def fix_code(source, options=None, encoding=None, apply_config=False): """Return fixed source code. "encoding" will be used to decode "source" if it is a byte string. """ if not options: - options = parse_args(['']) + options = parse_args([''], apply_config=apply_config) if not isinstance(source, unicode): - source = source.decode(encoding or locale.getpreferredencoding()) + source = source.decode(encoding or get_encoding()) sio = io.StringIO(source) return fix_lines(sio.readlines(), options=options) @@ -2864,9 +2893,9 @@ return ''.join(normalize_line_endings(sio.readlines(), original_newline)) -def fix_file(filename, options=None, output=None): +def fix_file(filename, options=None, output=None, apply_config=False): if not options: - options = parse_args([filename]) + options = parse_args([filename], apply_config=apply_config) original_source = readlines_from_file(filename) @@ -2956,15 +2985,15 @@ """Find leftmost item greater than or equal to x.""" i = bisect.bisect_left(a, x) if i != len(a): - return i, a[i] - return len(a) - 1, a[-1] + return (i, a[i]) + return (len(a) - 1, a[-1]) def find_le(a, x): """Find rightmost value less than or equal to x.""" i = bisect.bisect_right(a, x) if i: - return i - 1, a[i - 1] - return 0, a[0] + return (i - 1, a[i - 1]) + return (0, a[0]) def local_fix(source, start_log, end_log, start_lines, end_lines, indents, last_line): @@ -2988,12 +3017,20 @@ sl = slice(start_lines[start_log], end_lines[end_log] + 1) subsource = source[sl] + msl = multiline_string_lines(''.join(subsource), + include_docstrings=False) # Remove indent from subsource. if ind: for line_no in start_lines[start_log:end_log + 1]: pos = line_no - start_lines[start_log] subsource[pos] = subsource[pos][ind:] + # Remove indent from comments. + for (i, line) in enumerate(subsource): + if i + 1 not in msl and re.match(r'\s*#', line): + if line.index('#') >= ind: + subsource[i] = line[ind:] + # Fix indentation of subsource. fixed_subsource = apply_global_fixes(''.join(subsource), options, @@ -3003,7 +3040,7 @@ # Add back indent for non multi-line strings lines. msl = multiline_string_lines(''.join(fixed_subsource), include_docstrings=False) - for i, line in enumerate(fixed_subsource): + for (i, line) in enumerate(fixed_subsource): if not i + 1 in msl: fixed_subsource[i] = indent + line if line != '\n' else line @@ -3012,8 +3049,10 @@ # subset up until last_line, this assumes that the number of lines # does not change in this multiline line. changed_lines = len(fixed_subsource) - if (start_lines[end_log] != end_lines[end_log] - and end_lines[end_log] > last_line): + if ( + start_lines[end_log] != end_lines[end_log] and + end_lines[end_log] > last_line + ): after_end = end_lines[end_log] - last_line fixed_subsource = (fixed_subsource[:-after_end] + source[sl][-after_end:]) @@ -3032,7 +3071,7 @@ return re.split('[ :]', line.strip(), 1)[0] in continued_stmts assert options.line_range - start, end = options.line_range + (start, end) = options.line_range start -= 1 end -= 1 last_line = end # We shouldn't modify lines after this cut-off. @@ -3046,20 +3085,22 @@ # Just blank lines, this should imply that it will become '\n' ? return apply_global_fixes(source, options) - start_lines, indents = zip(*logical[0]) - end_lines, _ = zip(*logical[1]) + (start_lines, indents) = zip(*logical[0]) + (end_lines, _) = zip(*logical[1]) source = source.splitlines(True) - start_log, start = find_ge(start_lines, start) - end_log, end = find_le(start_lines, end) + (start_log, start) = find_ge(start_lines, start) + (end_log, end) = find_le(start_lines, end) # Look behind one line, if it's indented less than current indent # then we can move to this previous line knowing that its # indentation level will not be changed. - if (start_log > 0 - and indents[start_log - 1] < indents[start_log] - and not is_continued_stmt(source[start_log - 1])): + if ( + start_log > 0 and + indents[start_log - 1] < indents[start_log] and + not is_continued_stmt(source[start_log - 1]) + ): start_log -= 1 start = start_lines[start_log] @@ -3073,7 +3114,7 @@ ind = indents[start_log] for t in itertools.takewhile(lambda t: t[1][1] >= ind, enumerate(logical[0][start_log:])): - n_log, n = start_log + t[0], t[1][0] + (n_log, n) = start_log + t[0], t[1][0] # Start shares indent up to n. if n <= end: @@ -3086,14 +3127,16 @@ else: # Look at the line after end and see if allows us to reindent. - after_end_log, after_end = find_ge(start_lines, end + 1) + (after_end_log, after_end) = find_ge(start_lines, end + 1) if indents[after_end_log] > indents[start_log]: - start_log, start = find_ge(start_lines, start + 1) + (start_log, start) = find_ge(start_lines, start + 1) continue - if (indents[after_end_log] == indents[start_log] - and is_continued_stmt(source[after_end])): + if ( + indents[after_end_log] == indents[start_log] and + is_continued_stmt(source[after_end]) + ): # Find n, the beginning of the last continued statement. # Apply fix to previous block if there is one. only_block = True @@ -3108,7 +3151,7 @@ only_block = False break if only_block: - end_log, end = find_le(start_lines, end - 1) + (end_log, end) = find_le(start_lines, end - 1) continue source = local_fix(source, start_log, end_log, @@ -3149,45 +3192,54 @@ parser.add_argument('-v', '--verbose', action='count', dest='verbose', default=0, help='print verbose messages; ' - 'multiple -v result in more verbose messages') + 'multiple -v result in more verbose messages') parser.add_argument('-d', '--diff', action='store_true', dest='diff', help='print the diff for the fixed source') parser.add_argument('-i', '--in-place', action='store_true', help='make changes to files in place') + parser.add_argument('--global-config', metavar='filename', + default=DEFAULT_CONFIG, + help='path to a global pep8 config file; if this file ' + 'does not exist then this is ignored ' + '(default: {0})'.format(DEFAULT_CONFIG)) + parser.add_argument('--ignore-local-config', action='store_true', + help="don't look for and apply local config files; " + 'if not passed, defaults are updated with any ' + "config files in the project's root directory") parser.add_argument('-r', '--recursive', action='store_true', help='run recursively over directories; ' - 'must be used with --in-place or --diff') + 'must be used with --in-place or --diff') parser.add_argument('-j', '--jobs', type=int, metavar='n', default=1, help='number of parallel jobs; ' - 'match CPU count if value is less than 1') + 'match CPU count if value is less than 1') parser.add_argument('-p', '--pep8-passes', metavar='n', default=-1, type=int, help='maximum number of additional pep8 passes ' - '(default: infinite)') + '(default: infinite)') parser.add_argument('-a', '--aggressive', action='count', default=0, help='enable non-whitespace changes; ' - 'multiple -a result in more aggressive changes') + 'multiple -a result in more aggressive changes') parser.add_argument('--experimental', action='store_true', help='enable experimental fixes') parser.add_argument('--exclude', metavar='globs', help='exclude file/directory names that match these ' - 'comma-separated globs') + 'comma-separated globs') parser.add_argument('--list-fixes', action='store_true', help='list codes for fixes; ' 'used by --ignore and --select') parser.add_argument('--ignore', metavar='errors', default='', help='do not fix these errors/warnings ' - '(default: {0})'.format(DEFAULT_IGNORE)) + '(default: {0})'.format(DEFAULT_IGNORE)) parser.add_argument('--select', metavar='errors', default='', help='fix only these errors/warnings (e.g. E4,W)') parser.add_argument('--max-line-length', metavar='n', default=79, type=int, help='set maximum allowed line length ' - '(default: %(default)s)') + '(default: %(default)s)') parser.add_argument('--range', metavar='line', dest='line_range', default=None, type=int, nargs=2, help='only fix errors found within this inclusive ' - 'range of line numbers (e.g. 1 99); ' - 'line numbers are indexed at 1') + 'range of line numbers (e.g. 1 99); ' + 'line numbers are indexed at 1') parser.add_argument('--indent-size', default=DEFAULT_INDENT_SIZE, type=int, metavar='n', help='number of spaces per indent level ' @@ -3198,7 +3250,7 @@ return parser -def parse_args(arguments): +def parse_args(arguments, apply_config=False): """Parse command-line options.""" parser = create_parser() args = parser.parse_args(arguments) @@ -3208,6 +3260,11 @@ args.files = [decode_filename(name) for name in args.files] + if apply_config: + parser = read_config(args, parser) + args = parser.parse_args(arguments) + args.files = [decode_filename(name) for name in args.files] + if '-' in args.files: if len(args.files) > 1: parser.error('cannot mix stdin and regular files') @@ -3274,6 +3331,39 @@ return args +def read_config(args, parser): + """Read both user configuration and local configuration.""" + try: + from configparser import ConfigParser as SafeConfigParser + from configparser import Error + except ImportError: + from ConfigParser import SafeConfigParser + from ConfigParser import Error + + config = SafeConfigParser() + + try: + config.read(args.global_config) + + if not args.ignore_local_config: + parent = tail = args.files and os.path.abspath( + os.path.commonprefix(args.files)) + while tail: + if config.read([os.path.join(parent, fn) + for fn in PROJECT_CONFIG]): + break + (parent, tail) = os.path.split(parent) + + defaults = dict((k.lstrip('-').replace('-', '_'), v) + for k, v in config.items('pep8')) + parser.set_defaults(**defaults) + except Error: + # Ignore for now. + pass + + return parser + + def _split_comma_separated(string): """Return a set of strings.""" return set(filter(None, string.split(','))) @@ -3520,6 +3610,8 @@ for pattern in exclude: if fnmatch.fnmatch(base_name, pattern): return False + if fnmatch.fnmatch(filename, pattern): + return False if not os.path.isdir(filename) and not is_python_file(filename): return False @@ -3608,7 +3700,12 @@ else output) -def main(): +def get_encoding(): + """Return preferred encoding.""" + return locale.getpreferredencoding() or sys.getdefaultencoding() + + +def main(apply_config=True): """Tool main.""" try: # Exit on broken pipe. @@ -3618,7 +3715,7 @@ pass try: - args = parse_args(sys.argv[1:]) + args = parse_args(sys.argv[1:], apply_config=apply_config) if args.list_fixes: for code, description in sorted(supported_fixes()): @@ -3629,7 +3726,7 @@ if args.files == ['-']: assert not args.in_place - encoding = sys.stdin.encoding or locale.getpreferredencoding() + encoding = sys.stdin.encoding or get_encoding() # LineEndingWrapper is unnecessary here due to the symmetry between # standard in and standard out. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.0.4/setup.cfg new/autopep8-1.1.1/setup.cfg --- old/autopep8-1.0.4/setup.cfg 2014-09-09 19:07:39.000000000 +0200 +++ new/autopep8-1.1.1/setup.cfg 2015-02-26 06:58:32.000000000 +0100 @@ -1,3 +1,6 @@ +[bdist_wheel] +universal = 1 + [egg_info] tag_build = tag_date = 0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.0.4/test/fake_configuration/.pep8 new/autopep8-1.1.1/test/fake_configuration/.pep8 --- old/autopep8-1.0.4/test/fake_configuration/.pep8 1970-01-01 01:00:00.000000000 +0100 +++ new/autopep8-1.1.1/test/fake_configuration/.pep8 2014-12-25 03:20:09.000000000 +0100 @@ -0,0 +1,2 @@ +[pep8] +indent-size=2 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.0.4/test/test_autopep8.py new/autopep8-1.1.1/test/test_autopep8.py --- old/autopep8-1.0.4/test/test_autopep8.py 2014-09-09 19:03:42.000000000 +0200 +++ new/autopep8-1.1.1/test/test_autopep8.py 2015-02-26 06:38:55.000000000 +0100 @@ -7,6 +7,9 @@ """ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function from __future__ import unicode_literals import os @@ -38,6 +41,9 @@ import autopep8 +FAKE_CONFIGURATION = os.path.join(ROOT_DIR, 'test', 'fake_configuration') + + if 'AUTOPEP8_COVERAGE' in os.environ and int(os.environ['AUTOPEP8_COVERAGE']): AUTOPEP8_CMD_TUPLE = ('coverage', 'run', '--branch', '--parallel', '--omit=*/site-packages/*', @@ -207,6 +213,10 @@ '# abc', autopep8.fix_e265('## # ##abc')) + self.assertEqual( + '# abc "# noqa"', + autopep8.fix_e265('# abc "# noqa"')) + def test_format_block_comments_should_leave_outline_alone(self): line = """\ ################################################################### @@ -418,6 +428,41 @@ self.assertTrue(autopep8.match_file(filename, exclude=[]), msg=filename) + def test_find_files(self): + temp_directory = tempfile.mkdtemp() + try: + target = os.path.join(temp_directory, 'dir') + os.mkdir(target) + with open(os.path.join(target, 'a.py'), 'w'): + pass + + exclude = os.path.join(target, 'ex') + os.mkdir(exclude) + with open(os.path.join(exclude, 'b.py'), 'w'): + pass + + sub = os.path.join(exclude, 'sub') + os.mkdir(sub) + with open(os.path.join(sub, 'c.py'), 'w'): + pass + + # FIXME: Avoid changing directory. This may interfere with parallel + # test runs. + cwd = os.getcwd() + os.chdir(temp_directory) + try: + files = list(autopep8.find_files( + ['dir'], True, [os.path.join('dir', 'ex')])) + finally: + os.chdir(cwd) + + file_names = [os.path.basename(f) for f in files] + self.assertIn('a.py', file_names) + self.assertNotIn('b.py', file_names) + self.assertNotIn('c.py', file_names) + finally: + shutil.rmtree(temp_directory) + def test_line_shortening_rank(self): self.assertGreater( autopep8.line_shortening_rank('(1\n+1)\n', @@ -970,6 +1015,7 @@ # report properly, the below command will take a long time. p = Popen(list(AUTOPEP8_CMD_TUPLE) + ['-vvv', '--select=E101', '--diff', + '--global-config={0}'.format(os.devnull), os.path.join(ROOT_DIR, 'test', 'e101_example.py')], stdout=PIPE, stderr=PIPE) output = [x.decode('utf-8') for x in p.communicate()][0] @@ -2064,6 +2110,17 @@ with autopep8_context(line) as result: self.assertEqual(fixed, result) + def test_e302_bug(self): + """Avoid creating bad syntax.""" + line = r"""def repeatable_expr(): return [bracketed_choice, simple_match, rule_ref],\ + Optional(repeat_operator) +# def match(): return [simple_match , mixin_rule_match] TODO +def simple_match(): return [str_match, re_match] +""" + self.assertTrue(autopep8.check_syntax(line)) + with autopep8_context(line) as result: + self.assertTrue(autopep8.check_syntax(result)) + def test_e303(self): line = '\n\n\n# alpha\n\n1\n' fixed = '\n\n# alpha\n\n1\n' @@ -2169,6 +2226,34 @@ with autopep8_context(line) as result: self.assertEqual(fixed, result) + def test_e501_with_in(self): + line = """\ +if True: + if True: + if True: + if True: + if True: + if True: + if True: + if True: + if k_left in ('any', k_curr) and k_right in ('any', k_curr): + pass +""" + fixed = """\ +if True: + if True: + if True: + if True: + if True: + if True: + if True: + if True: + if k_left in ('any', k_curr) and k_right in ('any', k_curr): + pass +""" + with autopep8_context(line) as result: + self.assertEqual(fixed, result) + def test_e501_with_commas_and_colons(self): line = """\ foobar = {'aaaaaaaaaaaa': 'bbbbbbbbbbbbbbbb', 'dddddd': 'eeeeeeeeeeeeeeee', 'ffffffffffff': 'gggggggg'} @@ -3488,6 +3573,12 @@ with autopep8_context(line) as result: self.assertEqual(fixed, result) + def test_e703_with_inline_comment(self): + line = 'a = 5; # inline comment\n' + fixed = 'a = 5 # inline comment\n' + with autopep8_context(line) as result: + self.assertEqual(fixed, result) + def test_e711(self): line = 'foo == None\n' fixed = 'foo is None\n' @@ -3583,6 +3674,19 @@ with autopep8_context(line, options=['--aggressive']) as result: self.assertEqual(fixed, result) + def test_e901_should_cause_indentation_screw_up(self): + line = """\ +def tmp(g): + g(4))) + + if not True: + pass + pass +""" + + with autopep8_context(line) as result: + self.assertEqual(line, result) + def test_should_preserve_vertical_tab(self): line = """\ #Memory Bu\vffer Register: @@ -3955,6 +4059,7 @@ with autopep8_context(line, options=['--aggressive']) as result: self.assertEqual(line, result) + # FIXME: These tests should use multiline strings for readability. def test_range(self): line = 'print( 1 )\nprint( 2 )\n print( 3 )\n' fixed = 'print( 1 )\nprint(2)\n print( 3 )\n' @@ -4081,6 +4186,44 @@ with autopep8_context(line, options=['--range', '2', '7']) as result: self.assertEqual(fixed_2_7, result) + def test_range_indent_multiline_strings_and_docstring(self): + code_ = ''' +def f(): + """docstring + continued""" + a = """multi +line +string""" + #comment + a=1 +a=2 +''' + fixed_2_7 = ''' +def f(): + """docstring + continued""" + a = """multi +line +string""" + # comment + a = 1 +a=2 +''' + with autopep8_context(code_, options=['--range', '2', '9']) as result: + self.assertEqual(fixed_2_7, result) + + def test_range_with_indented_comments(self): + code_ = 'if True:\n if True:\n if True:\n # bah\n pass\n' + fixed = 'if True:\n if True:\n if True:\n # bah\n pass\n' + with autopep8_context(code_, options=['--range', '4', '5']) as result: + self.assertEqual(fixed, result) + + def test_range_with_indented_comments_spaced(self): + code_ = 'if True:\n if True:\n if True:\n # bah\n\n pass\n' + fixed = 'if True:\n if True:\n if True:\n # bah\n\n pass\n' + with autopep8_context(code_, options=['--range', '4', '6']) as result: + self.assertEqual(fixed, result) + def test_range_with_broken_syntax(self): line = """\ if True: @@ -4377,6 +4520,77 @@ process.communicate(line.encode('utf-8'))[0].decode('utf-8')) +class ConfigurationTests(unittest.TestCase): + + def test_local_config(self): + args = autopep8.parse_args( + [os.path.join(FAKE_CONFIGURATION, 'foo.py'), + '--global-config={0}'.format(os.devnull)], + apply_config=True) + self.assertEqual(args.indent_size, 2) + + def test_config_override(self): + args = autopep8.parse_args( + [os.path.join(FAKE_CONFIGURATION, 'foo.py'), + '--indent-size=7'], + apply_config=True) + self.assertEqual(args.indent_size, 7) + + def test_config_false_with_local(self): + args = autopep8.parse_args( + [os.path.join(FAKE_CONFIGURATION, 'foo.py'), + '--global-config=False'], + apply_config=True) + self.assertEqual(args.global_config, 'False') + self.assertEqual(args.indent_size, 2) + + def test_config_false_with_local_space(self): + args = autopep8.parse_args( + [os.path.join(FAKE_CONFIGURATION, 'foo.py'), + '--global-config', 'False'], + apply_config=True) + self.assertEqual(args.global_config, 'False') + self.assertEqual(args.indent_size, 2) + + def test_config_false_with_local_autocomplete(self): + args = autopep8.parse_args( + [os.path.join(FAKE_CONFIGURATION, 'foo.py'), + '--g', 'False'], + apply_config=True) + self.assertEqual(args.global_config, 'False') + self.assertEqual(args.indent_size, 2) + + def test_config_false_without_local(self): + args = autopep8.parse_args(['/nowhere/foo.py', + '--global-config={0}'.format(os.devnull)], + apply_config=True) + self.assertEqual(args.indent_size, 4) + + def test_global_config_with_locals(self): + with temporary_file_context('[pep8]\nindent-size=3\n') as filename: + args = autopep8.parse_args( + [os.path.join(FAKE_CONFIGURATION, 'foo.py'), + '--global-config={0}'.format(filename)], + apply_config=True) + self.assertEqual(args.indent_size, 2) + + def test_global_config_ignore_locals(self): + with temporary_file_context('[pep8]\nindent-size=3\n') as filename: + args = autopep8.parse_args( + [os.path.join(FAKE_CONFIGURATION, 'foo.py'), + '--global-config={0}'.format(filename), + '--ignore-local-config'], + apply_config=True) + self.assertEqual(args.indent_size, 3) + + def test_global_config_without_locals(self): + with temporary_file_context('[pep8]\nindent-size=3\n') as filename: + args = autopep8.parse_args( + ['/nowhere/foo.py', '--global-config={0}'.format(filename)], + apply_config=True) + self.assertEqual(args.indent_size, 3) + + class ExperimentalSystemTests(unittest.TestCase): maxDiff = None @@ -4421,7 +4635,8 @@ with autopep8_context(line, options=['--experimental']) as result: self.assertEqual(fixed, result) - def test_e501_experimental_with_inline_comments_should_skip_multiline(self): + def test_e501_experimental_with_inline_comments_should_skip_multiline( + self): line = """\ '''This should be left alone. ----------------------------------------------------- @@ -4465,7 +4680,8 @@ with autopep8_context(line, options=['--experimental']) as result: self.assertEqual(line, result) - def test_e501_experimental_with_inline_comments_should_skip_edge_cases(self): + def test_e501_experimental_with_inline_comments_should_skip_edge_cases( + self): line = """\ if True: x = \\ @@ -4580,7 +4796,8 @@ '--experimental']) as result: self.assertEqual(fixed, result) - def test_e501_experimental_should_not_try_to_break_at_every_paren_in_arithmetic(self): + def test_e501_experimental_should_not_try_to_break_at_every_paren_in_arithmetic( + self): line = """\ term3 = w6 * c5 * (8.0 * psi4 * (11.0 - 24.0 * t2) - 28 * psi3 * (1 - 6.0 * t2) + psi2 * (1 - 32 * t2) - psi * (2.0 * t2) + t4) / 720.0 this_should_be_shortened = (' ', ' ') @@ -5218,7 +5435,8 @@ with autopep8_context(line, options=['--experimental']) as result: self.assertEqual(fixed, result) - def test_e501_experimental_avoid_breaking_at_empty_parentheses_if_possible(self): + def test_e501_experimental_avoid_breaking_at_empty_parentheses_if_possible( + self): line = """\ someverylongindenttionwhatnot().foo().bar().baz("and here is a long string 123456789012345678901234567890") """ @@ -5642,6 +5860,36 @@ """ with autopep8_context(line, options=['--experimental']) as result: self.assertEqual(fixed, result) + + def test_e501_experimental_with_in(self): + line = """\ +if True: + if True: + if True: + if True: + if True: + if True: + if True: + if True: + if k_left in ('any', k_curr) and k_right in ('any', k_curr): + pass +""" + fixed = """\ +if True: + if True: + if True: + if True: + if True: + if True: + if True: + if True: + if k_left in ( + 'any', k_curr) and k_right in ( + 'any', k_curr): + pass +""" + with autopep8_context(line, options=['--experimental']) as result: + self.assertEqual(fixed, result) @contextlib.contextmanager -- To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org For additional commands, e-mail: opensuse-commit+help@opensuse.org
participants (1)
-
root@hilbert.suse.de