Hello community,
here is the log from the commit of package python-autopep8 for openSUSE:Factory checked in at 2019-04-23 14:39:06
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-autopep8 (Old)
and /work/SRC/openSUSE:Factory/.python-autopep8.new.5536 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-autopep8"
Tue Apr 23 14:39:06 2019 rev:16 rq:697026 version:1.4.4
Changes:
--------
--- /work/SRC/openSUSE:Factory/python-autopep8/python-autopep8.changes 2018-11-26 10:29:56.849053228 +0100
+++ /work/SRC/openSUSE:Factory/.python-autopep8.new.5536/python-autopep8.changes 2019-04-23 14:39:06.941580714 +0200
@@ -1,0 +2,25 @@
+Sun Apr 21 22:03:00 UTC 2019 - Arun Persaud
+
+- specfile:
+ * update copyright year
+
+- update to version 1.4.4:
+ * add github issue template
+ * Clarify global config file documentation
+ * fix e117
+ * add py37 in tox envlist
+ * fix import statement moved above the module doc by E402
+ * Don't allow setting --ignore to enable conflicting fixes
+ * Fix issue with W504 that causes a syntax error if there are
+ comment
+ * fix import moved above a future import
+ * fix invalid exit code (for #455)
+ * add unit test for exit code
+ * fix to pointed out by pylint
+ * noqa
+ * check pycodestyle to test/test_autopep8.py
+ * better match the signature of io.open
+ * Fix invalid escape sequences in tests
+ * Don't write the file unless there are changes
+
+-------------------------------------------------------------------
Old:
----
autopep8-1.4.3.tar.gz
New:
----
autopep8-1.4.4.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-autopep8.spec ++++++
--- /var/tmp/diff_new_pack.sfSXyO/_old 2019-04-23 14:39:08.301581414 +0200
+++ /var/tmp/diff_new_pack.sfSXyO/_new 2019-04-23 14:39:08.337581433 +0200
@@ -1,7 +1,7 @@
#
# spec file for package python-autopep8
#
-# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany.
+# Copyright (c) 2019 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
@@ -18,7 +18,7 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
Name: python-autopep8
-Version: 1.4.3
+Version: 1.4.4
Release: 0
Summary: Automatic generated to pep8 checked code
License: MIT
++++++ autopep8-1.4.3.tar.gz -> autopep8-1.4.4.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.4.3/PKG-INFO new/autopep8-1.4.4/PKG-INFO
--- old/autopep8-1.4.3/PKG-INFO 2018-11-12 14:55:55.000000000 +0100
+++ new/autopep8-1.4.4/PKG-INFO 2019-04-14 10:29:35.000000000 +0200
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: autopep8
-Version: 1.4.3
+Version: 1.4.4
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
@@ -344,9 +344,10 @@
Configuration
=============
- By default, if ``$HOME/.config/.pycodestyle`` (``~\.pycodestyle`` in Windows
- environment) exists, it will be used as global configuration file. It can
- specify the configuration file with the ``--global-config`` option.
+ By default, if ``$HOME/.config/pycodestyle`` (``~\.pycodestyle`` in Windows
+ environment) exists, it will be used as global configuration file.
+ Alternatively, you can specify the global configuration file with the
+ ``--global-config`` option.
Also, if ``setup.cfg``, ``tox.ini``, ``.pep8`` and ``.flake8`` files exist
in the directory where the target file exists, it will be used as the
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.4.3/README.rst new/autopep8-1.4.4/README.rst
--- old/autopep8-1.4.3/README.rst 2018-10-15 15:05:07.000000000 +0200
+++ new/autopep8-1.4.4/README.rst 2019-04-14 10:29:22.000000000 +0200
@@ -336,9 +336,10 @@
Configuration
=============
-By default, if ``$HOME/.config/.pycodestyle`` (``~\.pycodestyle`` in Windows
-environment) exists, it will be used as global configuration file. It can
-specify the configuration file with the ``--global-config`` option.
+By default, if ``$HOME/.config/pycodestyle`` (``~\.pycodestyle`` in Windows
+environment) exists, it will be used as global configuration file.
+Alternatively, you can specify the global configuration file with the
+``--global-config`` option.
Also, if ``setup.cfg``, ``tox.ini``, ``.pep8`` and ``.flake8`` files exist
in the directory where the target file exists, it will be used as the
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.4.3/autopep8.egg-info/PKG-INFO new/autopep8-1.4.4/autopep8.egg-info/PKG-INFO
--- old/autopep8-1.4.3/autopep8.egg-info/PKG-INFO 2018-11-12 14:55:54.000000000 +0100
+++ new/autopep8-1.4.4/autopep8.egg-info/PKG-INFO 2019-04-14 10:29:35.000000000 +0200
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: autopep8
-Version: 1.4.3
+Version: 1.4.4
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
@@ -344,9 +344,10 @@
Configuration
=============
- By default, if ``$HOME/.config/.pycodestyle`` (``~\.pycodestyle`` in Windows
- environment) exists, it will be used as global configuration file. It can
- specify the configuration file with the ``--global-config`` option.
+ By default, if ``$HOME/.config/pycodestyle`` (``~\.pycodestyle`` in Windows
+ environment) exists, it will be used as global configuration file.
+ Alternatively, you can specify the global configuration file with the
+ ``--global-config`` option.
Also, if ``setup.cfg``, ``tox.ini``, ``.pep8`` and ``.flake8`` files exist
in the directory where the target file exists, it will be used as the
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.4.3/autopep8.py new/autopep8-1.4.4/autopep8.py
--- old/autopep8-1.4.3/autopep8.py 2018-11-12 14:54:44.000000000 +0100
+++ new/autopep8-1.4.4/autopep8.py 2019-04-14 10:29:22.000000000 +0200
@@ -57,6 +57,7 @@
import textwrap
import token
import tokenize
+import ast
import pycodestyle
@@ -67,7 +68,7 @@
unicode = str
-__version__ = '1.4.3'
+__version__ = '1.4.4'
CR = '\r'
@@ -81,6 +82,7 @@
COMPARE_NEGATIVE_REGEX_THROUGH = re.compile(r'\b(not\s+in|is\s+not)\s')
BARE_EXCEPT_REGEX = re.compile(r'except\s*:')
STARTSWITH_DEF_REGEX = re.compile(r'^(async\s+def|def)\s.*\):')
+DOCSTRING_START_REGEX = re.compile(r'^u?r?(?P<kind>["\']{3})')
EXIT_CODE_OK = 0
EXIT_CODE_ERROR = 1
@@ -99,6 +101,9 @@
DEFAULT_IGNORE = 'E226,E24,W50,W690' # TODO: use pycodestyle.DEFAULT_IGNORE
DEFAULT_INDENT_SIZE = 4
+# these fixes conflict with each other, if the `--ignore` setting causes both
+# to be enabled, disable both of them
+CONFLICTING_CODES = ('W503', 'W504')
SELECTED_GLOBAL_FIXED_METHOD_CODES = ['W602', ]
@@ -142,8 +147,7 @@
MAX_PYTHON_FILE_DETECTION_BYTES = 1024
-def open_with_encoding(filename,
- encoding=None, mode='r', limit_byte_check=-1):
+def open_with_encoding(filename, mode='r', encoding=None, limit_byte_check=-1):
"""Return opened file with a specific encoding."""
if not encoding:
encoding = detect_encoding(filename, limit_byte_check=limit_byte_check)
@@ -159,7 +163,7 @@
from lib2to3.pgen2 import tokenize as lib2to3_tokenize
encoding = lib2to3_tokenize.detect_encoding(input_file.readline)[0]
- with open_with_encoding(filename, encoding) as test_file:
+ with open_with_encoding(filename, encoding=encoding) as test_file:
test_file.read(limit_byte_check)
return encoding
@@ -1257,7 +1261,7 @@
tts = ts[newline_index[-3]:]
else:
tts = ts
- old = None
+ old = []
for t in tts:
if t[0] in (tokenize.NEWLINE, tokenize.NL):
newline_count -= 1
@@ -1314,14 +1318,15 @@
old = []
for t in tts:
if tokenize.COMMENT == t[0] and old:
- comment_index = old[3][1]
+ comment_row, comment_index = old[3]
break
old = t
break
if not operator_position:
return
target_operator = target[operator_position[0]:operator_position[1]]
- if comment_index:
+
+ if comment_index and comment_row == 1:
self.source[line_index] = '{}{}'.format(
target[:operator_position[0]].rstrip(),
target[comment_index:])
@@ -1330,6 +1335,7 @@
target[:operator_position[0]].rstrip(),
target[operator_position[1]:].lstrip(),
target[operator_position[1]:])
+
next_line = self.source[line_index + 1]
next_line_indent = 0
m = re.match(r'\s*', next_line)
@@ -1363,7 +1369,7 @@
'N', 'u', 'U',
]
- for token_type, text, start_pos, end_pos, line in tokens:
+ for token_type, text, start_pos, _end_pos, _line in tokens:
if token_type == tokenize.STRING:
quote = text[-3:] if text[-3:] in ('"""', "'''") else text[-1]
# Extract string modifiers (e.g. u or r)
@@ -1401,14 +1407,39 @@
if line and line[0] in 'rR':
line = line[1:]
return line and (line[0] == '"' or line[0] == "'")
+
+ def is_future_import(line):
+ nodes = ast.parse(line)
+ for n in nodes.body:
+ if isinstance(n, ast.ImportFrom) and n.module == '__future__':
+ return True
+ return False
+
allowed_try_keywords = ('try', 'except', 'else', 'finally')
+ in_docstring = False
+ docstring_kind = '"""'
for cnt, line in enumerate(source):
+ if not in_docstring:
+ m = DOCSTRING_START_REGEX.match(line.lstrip())
+ if m is not None:
+ in_docstring = True
+ docstring_kind = m.group('kind')
+ remain = line[m.end(): m.endpos].rstrip()
+ if remain[-3:] == docstring_kind: # one line doc
+ in_docstring = False
+ continue
+ if in_docstring:
+ if line.rstrip()[-3:] == docstring_kind:
+ in_docstring = False
+ continue
+
if not line.rstrip():
continue
elif line.startswith('#'):
continue
+
if line.startswith('import ') or line.startswith('from '):
- if cnt == import_line_index:
+ if cnt == import_line_index or is_future_import(line):
continue
return cnt
elif pycodestyle.DUNDER_REGEX.match(line):
@@ -2991,8 +3022,8 @@
if have == _leading_space_count(lines[jline]):
want = jlevel * indent_size
break
- if want < 0: # Maybe it's a hanging
- # comment like this one,
+ # Maybe it's a hanging comment like this one,
+ if want < 0:
# in which case we should shift it like its base
# line got shifted.
for j in range(i - 1, -1, -1):
@@ -3431,15 +3462,13 @@
output.flush()
return diff
elif options.in_place:
- fp = open_with_encoding(filename, encoding=encoding, mode='w')
- fp.write(fixed_source)
- fp.close()
original = "".join(original_source).splitlines()
fixed = fixed_source.splitlines()
if original != fixed:
+ with open_with_encoding(filename, 'w', encoding=encoding) as fp:
+ fp.write(fixed_source)
return fixed_source
- else:
- return ''
+ return None
else:
if output:
output.write(fixed_source)
@@ -3654,6 +3683,14 @@
if args.ignore:
args.ignore = _split_comma_separated(args.ignore)
+ if not all(
+ any(
+ conflicting_code.startswith(ignore_code)
+ for ignore_code in args.ignore
+ )
+ for conflicting_code in CONFLICTING_CODES
+ ):
+ args.ignore.update(CONFLICTING_CODES)
elif not args.select:
if args.aggressive:
# Enable everything by default if aggressive.
@@ -4057,15 +4094,17 @@
import multiprocessing
pool = multiprocessing.Pool(options.jobs)
ret = pool.map(_fix_file, [(name, options) for name in filenames])
- results.extend(filter(lambda x: x is not None, ret))
+ results.extend([x for x in ret if x is not None])
else:
for name in filenames:
ret = _fix_file((name, options, output))
if ret is None:
continue
- if options.diff or options.in_place:
+ if options.diff:
if ret != '':
results.append(ret)
+ elif options.in_place:
+ results.append(ret)
else:
original_source = readlines_from_file(name)
if "".join(original_source).splitlines() != ret.splitlines():
@@ -4159,7 +4198,7 @@
assert not args.recursive
ret = fix_multiple_files(args.files, args, sys.stdout)
- if args.exit_code and len(ret) > 0:
+ if args.exit_code and ret:
return EXIT_CODE_EXISTS_DIFF
except KeyboardInterrupt:
return EXIT_CODE_ERROR # pragma: no cover
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autopep8-1.4.3/test/test_autopep8.py new/autopep8-1.4.4/test/test_autopep8.py
--- old/autopep8-1.4.3/test/test_autopep8.py 2018-11-12 14:53:41.000000000 +0100
+++ new/autopep8-1.4.4/test/test_autopep8.py 2019-04-14 10:29:22.000000000 +0200
@@ -34,8 +34,8 @@
ROOT_DIR = os.path.split(os.path.abspath(os.path.dirname(__file__)))[0]
sys.path.insert(0, ROOT_DIR)
-import autopep8
-from autopep8 import get_module_imports_on_top_of_file
+import autopep8 # NOQA: E402
+from autopep8 import get_module_imports_on_top_of_file # NOQA: E402
FAKE_CONFIGURATION = os.path.join(ROOT_DIR, 'test', 'fake_configuration')
FAKE_PYCODESTYLE_CONFIGURATION = os.path.join(
@@ -124,7 +124,7 @@
def test_multiline_string_lines(self):
self.assertEqual(
- set([2]),
+ {2},
autopep8.multiline_string_lines(
"""\
'''
@@ -133,7 +133,7 @@
def test_multiline_string_lines_with_many(self):
self.assertEqual(
- set([2, 7, 10, 11, 12]),
+ {2, 7, 10, 11, 12},
autopep8.multiline_string_lines(
"""\
'''
@@ -160,7 +160,7 @@
def test_multiline_string_should_not_report_docstrings(self):
self.assertEqual(
- set([5]),
+ {5},
autopep8.multiline_string_lines(
"""\
def foo():
@@ -2416,6 +2416,26 @@
with autopep8_context(line) as result:
self.assertEqual(fixed, result)
+ def test_e402_with_future_import(self):
+ line = 'from __future__ import print_function\na = 1\nimport os\n'
+ fixed = 'from __future__ import print_function\nimport os\na = 1\n'
+ with autopep8_context(line) as result:
+ self.assertEqual(fixed, result)
+
+ def test_e402_with_module_doc(self):
+ line1 = '"""\nmodule doc\n"""\na = 1\nimport os\n'
+ fixed1 = '"""\nmodule doc\n"""\nimport os\na = 1\n'
+ line2 = '# comment\nr"""\nmodule doc\n"""\na = 1\nimport os\n'
+ fixed2 = '# comment\nr"""\nmodule doc\n"""\nimport os\na = 1\n'
+ line3 = "u'''one line module doc'''\na = 1\nimport os\n"
+ fixed3 = "u'''one line module doc'''\nimport os\na = 1\n"
+ line4 = "'''\n\"\"\"\ndoc'''\na = 1\nimport os\n"
+ fixed4 = "'''\n\"\"\"\ndoc'''\nimport os\na = 1\n"
+ for line, fixed in [(line1, fixed1), (line2, fixed2),
+ (line3, fixed3), (line4, fixed4)]:
+ with autopep8_context(line) as result:
+ self.assertEqual(fixed, result)
+
def test_e402_import_some_modules(self):
line = """\
a = 1
@@ -4425,6 +4445,24 @@
with autopep8_context(line, options=['--select=W504', '--ignore=E']) as result:
self.assertEqual(fixed, result)
+ def test_w504_comment_on_first_line(self):
+ line = 'x = (1 | # test\n2)\n'
+ fixed = 'x = (1 # test\n| 2)\n'
+ with autopep8_context(line, options=['--select=W504', '--ignore=E']) as result:
+ self.assertEqual(fixed, result)
+
+ def test_w504_comment_on_second_line(self):
+ line = 'x = (1 |\n2) # test\n'
+ fixed = 'x = (1\n| 2) # test\n'
+ with autopep8_context(line, options=['--select=W504', '--ignore=E']) as result:
+ self.assertEqual(fixed, result)
+
+ def test_w504_comment_on_each_lines(self):
+ line = 'x = (1 |# test\n2 |# test\n3) # test\n'
+ fixed = 'x = (1# test\n| 2# test\n| 3) # test\n'
+ with autopep8_context(line, options=['--select=W504', '--ignore=E']) as result:
+ self.assertEqual(fixed, result)
+
def test_w504_with_e265_ignore_option(self):
line = '(width == 0 +\n height == 0)\n'
with autopep8_context(line, options=['--ignore=E265']) as result:
@@ -4451,6 +4489,24 @@
with autopep8_context(line, options=['--select=W504', '--ignore=E']) as result:
self.assertEqual(fixed, result)
+ def test_w504_not_applied_by_default_when_modifying_with_ignore(self):
+ line = """\
+q = 1
+
+
+
+
+def x(y, z):
+ if (
+ y and
+ z
+ ):
+ pass
+"""
+ fixed = line.replace('\n\n\n\n', '\n\n')
+ with autopep8_context(line, options=['--ignore=E265']) as result:
+ self.assertEqual(fixed, result)
+
def test_w601(self):
line = 'a = {0: 1}\na.has_key(0)\n'
fixed = 'a = {0: 1}\n0 in a\n'
@@ -4729,27 +4785,27 @@
self.assertEqual(fixed, result)
def test_w605_simple(self):
- line = "escape = '\.jpg'\n"
- fixed = "escape = r'\.jpg'\n"
+ line = "escape = '\\.jpg'\n"
+ fixed = "escape = r'\\.jpg'\n"
with autopep8_context(line, options=['--aggressive']) as result:
self.assertEqual(fixed, result)
def test_w605_identical_token(self):
# ***NOTE***: The --pep8-passes option is requred to prevent an infinite loop in
# the old, failing code. DO NOT REMOVE.
- line = "escape = foo('\.bar', '\.kilroy')\n"
- fixed = "escape = foo(r'\.bar', r'\.kilroy')\n"
+ line = "escape = foo('\\.bar', '\\.kilroy')\n"
+ fixed = "escape = foo(r'\\.bar', r'\\.kilroy')\n"
with autopep8_context(line, options=['--aggressive', '--pep8-passes', '5']) as result:
self.assertEqual(fixed, result, "Two tokens get r added")
- line = "escape = foo('\.bar', r'\.kilroy')\n"
- fixed = "escape = foo(r'\.bar', r'\.kilroy')\n"
+ line = "escape = foo('\\.bar', r'\\.kilroy')\n"
+ fixed = "escape = foo(r'\\.bar', r'\\.kilroy')\n"
with autopep8_context(line, options=['--aggressive', '--pep8-passes', '5']) as result:
self.assertEqual(fixed, result, "r not added if already there")
# Test Case to catch bad behavior reported in Issue #449
- line = "escape = foo('\.bar', '\.bar')\n"
- fixed = "escape = foo(r'\.bar', r'\.bar')\n"
+ line = "escape = foo('\\.bar', '\\.bar')\n"
+ fixed = "escape = foo(r'\\.bar', r'\\.bar')\n"
with autopep8_context(line, options=['--aggressive', '--pep8-passes', '5']) as result:
self.assertEqual(fixed, result)
@@ -4858,7 +4914,7 @@
target_line_index = 11
result = get_module_imports_on_top_of_file(line.splitlines(),
target_line_index)
- self.assertEqual(result, 5)
+ self.assertEqual(result, 10)
class CommandLineTests(unittest.TestCase):
@@ -4956,12 +5012,37 @@
self.assertEqual(fixed, f.read())
self.assertEqual(p.returncode, autopep8.EXIT_CODE_OK)
+ def test_in_place_no_modifications_no_writes(self):
+ with temporary_file_context('import os\n') as filename:
+ # ensure that noops do not do writes by making writing an error
+ os.chmod(filename, 0o444)
+ p = Popen(
+ list(AUTOPEP8_CMD_TUPLE) + [filename, '--in-place'],
+ stderr=PIPE,
+ )
+ _, err = p.communicate()
+ self.assertEqual(err, b'')
+ self.assertEqual(p.returncode, autopep8.EXIT_CODE_OK)
+
def test_in_place_with_exit_code_option(self):
line = "'abc' \n"
fixed = "'abc'\n"
with temporary_file_context(line) as filename:
p = Popen(list(AUTOPEP8_CMD_TUPLE) + [filename,
+ '--in-place',
+ '--exit-code'])
+ p.wait()
+ with open(filename) as f:
+ self.assertEqual(fixed, f.read())
+ self.assertEqual(p.returncode, autopep8.EXIT_CODE_EXISTS_DIFF)
+
+ def test_in_place_with_exit_code_option_with_w391(self):
+ line = "\n\n\n"
+ fixed = ""
+
+ with temporary_file_context(line) as filename:
+ p = Popen(list(AUTOPEP8_CMD_TUPLE) + [filename,
'--in-place',
'--exit-code'])
p.wait()