Hello community,
here is the log from the commit of package python-autoflake for
openSUSE:Factory checked in at 2019-05-16 22:10:26
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/python-autoflake (Old)
and /work/SRC/openSUSE:Factory/.python-autoflake.new.5148 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-autoflake"
Thu May 16 22:10:26 2019 rev:4 rq:703507 version:1.3
Changes:
--------
--- /work/SRC/openSUSE:Factory/python-autoflake/python-autoflake.changes
2019-02-11 21:28:07.594991826 +0100
+++
/work/SRC/openSUSE:Factory/.python-autoflake.new.5148/python-autoflake.changes
2019-05-16 22:11:09.542225209 +0200
@@ -1,0 +2,6 @@
+Thu May 16 17:27:05 UTC 2019 - Meera Belur <[email protected]>
+
+- Update to v1.3
+ + No changes were provided
+
+-------------------------------------------------------------------
Old:
----
autoflake-1.2.tar.gz
New:
----
autoflake-1.3.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-autoflake.spec ++++++
--- /var/tmp/diff_new_pack.J2EWi7/_old 2019-05-16 22:11:10.974223981 +0200
+++ /var/tmp/diff_new_pack.J2EWi7/_new 2019-05-16 22:11:11.010223950 +0200
@@ -19,7 +19,7 @@
%{?!python_module:%define python_module() python-%{**} python3-%{**}}
%bcond_without test
Name: python-autoflake
-Version: 1.2
+Version: 1.3
Release: 0
# for license file
%define tag 44b07bb9dab60a74cb5da0b67cc78b734763785c
++++++ autoflake-1.2.tar.gz -> autoflake-1.3.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/autoflake-1.2/AUTHORS.rst
new/autoflake-1.3/AUTHORS.rst
--- old/autoflake-1.2/AUTHORS.rst 2018-02-15 03:01:06.000000000 +0100
+++ new/autoflake-1.3/AUTHORS.rst 2019-04-21 18:25:39.000000000 +0200
@@ -8,3 +8,4 @@
- Adhika Setya Pramudita (https://github.com/adhikasp)
- Andrew Dassonville (https://github.com/andrewda)
- toddrme2178 (https://github.com/toddrme2178)
+- James Curtin (https://github.com/jamescurtin)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/autoflake-1.2/PKG-INFO new/autoflake-1.3/PKG-INFO
--- old/autoflake-1.2/PKG-INFO 2018-05-09 16:09:31.000000000 +0200
+++ new/autoflake-1.3/PKG-INFO 2019-04-21 18:27:29.000000000 +0200
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: autoflake
-Version: 1.2
+Version: 1.3
Summary: Removes unused imports and unused variables
Home-page: https://github.com/myint/autoflake
Author: Steven Myint
@@ -111,6 +111,7 @@
optional arguments:
-h, --help show this help message and exit
+ -c, --check return error code if changes are needed
-i, --in-place make changes to files instead of printing
diffs
-r, --recursive drill down directories recursively
--exclude globs exclude file/directory names that match
these comma-
@@ -148,6 +149,35 @@
$ ./test_fuzz.py --verbose
+
+ Excluding specific lines
+ ========================
+
+ It might be the case that you have some imports for their side
effects, even
+ if you are not using them directly in that file.
+
+ That is common, for example, in Flask based applications. In where you
import
+ Python modules (files) that imported a main ``app``, to have them
included in
+ the routes.
+
+ For example:
+
+ .. code-block:: python
+
+ from .endpoints import role, token, user, utils
+
+ As those imports are not being used directly, if you are using the
option
+ ``--remove-all-unused-imports``, they would be removed.
+
+ To prevent that, without having to exclude the entire file, you can
add a
+ ``# noqa`` comment at the end of the line, like:
+
+ .. code-block:: python
+
+ from .endpoints import role, token, user, utils # noqa
+
+ That line will instruct ``autoflake`` to let that specific line as is.
+
Keywords: clean,fix,automatic,unused,import
Platform: UNKNOWN
Classifier: Environment :: Console
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/autoflake-1.2/README.rst new/autoflake-1.3/README.rst
--- old/autoflake-1.2/README.rst 2018-01-07 21:10:36.000000000 +0100
+++ new/autoflake-1.3/README.rst 2019-04-21 18:25:39.000000000 +0200
@@ -103,6 +103,7 @@
optional arguments:
-h, --help show this help message and exit
+ -c, --check return error code if changes are needed
-i, --in-place make changes to files instead of printing diffs
-r, --recursive drill down directories recursively
--exclude globs exclude file/directory names that match these
comma-
@@ -139,3 +140,32 @@
left untouched.)::
$ ./test_fuzz.py --verbose
+
+
+Excluding specific lines
+========================
+
+It might be the case that you have some imports for their side effects, even
+if you are not using them directly in that file.
+
+That is common, for example, in Flask based applications. In where you import
+Python modules (files) that imported a main ``app``, to have them included in
+the routes.
+
+For example:
+
+.. code-block:: python
+
+ from .endpoints import role, token, user, utils
+
+As those imports are not being used directly, if you are using the option
+``--remove-all-unused-imports``, they would be removed.
+
+To prevent that, without having to exclude the entire file, you can add a
+``# noqa`` comment at the end of the line, like:
+
+.. code-block:: python
+
+ from .endpoints import role, token, user, utils # noqa
+
+That line will instruct ``autoflake`` to let that specific line as is.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/autoflake-1.2/autoflake.egg-info/PKG-INFO
new/autoflake-1.3/autoflake.egg-info/PKG-INFO
--- old/autoflake-1.2/autoflake.egg-info/PKG-INFO 2018-05-09
16:09:30.000000000 +0200
+++ new/autoflake-1.3/autoflake.egg-info/PKG-INFO 2019-04-21
18:27:28.000000000 +0200
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: autoflake
-Version: 1.2
+Version: 1.3
Summary: Removes unused imports and unused variables
Home-page: https://github.com/myint/autoflake
Author: Steven Myint
@@ -111,6 +111,7 @@
optional arguments:
-h, --help show this help message and exit
+ -c, --check return error code if changes are needed
-i, --in-place make changes to files instead of printing
diffs
-r, --recursive drill down directories recursively
--exclude globs exclude file/directory names that match
these comma-
@@ -148,6 +149,35 @@
$ ./test_fuzz.py --verbose
+
+ Excluding specific lines
+ ========================
+
+ It might be the case that you have some imports for their side
effects, even
+ if you are not using them directly in that file.
+
+ That is common, for example, in Flask based applications. In where you
import
+ Python modules (files) that imported a main ``app``, to have them
included in
+ the routes.
+
+ For example:
+
+ .. code-block:: python
+
+ from .endpoints import role, token, user, utils
+
+ As those imports are not being used directly, if you are using the
option
+ ``--remove-all-unused-imports``, they would be removed.
+
+ To prevent that, without having to exclude the entire file, you can
add a
+ ``# noqa`` comment at the end of the line, like:
+
+ .. code-block:: python
+
+ from .endpoints import role, token, user, utils # noqa
+
+ That line will instruct ``autoflake`` to let that specific line as is.
+
Keywords: clean,fix,automatic,unused,import
Platform: UNKNOWN
Classifier: Environment :: Console
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/autoflake-1.2/autoflake.py
new/autoflake-1.3/autoflake.py
--- old/autoflake-1.2/autoflake.py 2018-05-09 16:08:59.000000000 +0200
+++ new/autoflake-1.3/autoflake.py 2019-04-21 18:26:12.000000000 +0200
@@ -43,7 +43,7 @@
import pyflakes.reporter
-__version__ = '1.2'
+__version__ = '1.3'
ATOMS = frozenset([tokenize.NAME, tokenize.NUMBER, tokenize.STRING])
@@ -331,7 +331,9 @@
expand_star_imports=False,
remove_all_unused_imports=False,
remove_duplicate_keys=False,
- remove_unused_variables=False):
+ remove_unused_variables=False,
+ ignore_init_module_imports=False,
+ ):
"""Yield code with unused imports removed."""
imports = SAFE_IMPORTS
if additional_imports:
@@ -340,8 +342,11 @@
messages = check(source)
- marked_import_line_numbers = frozenset(
- unused_import_line_numbers(messages))
+ if ignore_init_module_imports:
+ marked_import_line_numbers = frozenset()
+ else:
+ marked_import_line_numbers = frozenset(
+ unused_import_line_numbers(messages))
marked_unused_module = collections.defaultdict(lambda: [])
for line_number, module_name in unused_import_module_name(messages):
marked_unused_module[line_number].append(module_name)
@@ -589,7 +594,7 @@
def fix_code(source, additional_imports=None, expand_star_imports=False,
remove_all_unused_imports=False, remove_duplicate_keys=False,
- remove_unused_variables=False):
+ remove_unused_variables=False, ignore_init_module_imports=False):
"""Return code with all filtering run on it."""
if not source:
return source
@@ -608,7 +613,9 @@
expand_star_imports=expand_star_imports,
remove_all_unused_imports=remove_all_unused_imports,
remove_duplicate_keys=remove_duplicate_keys,
- remove_unused_variables=remove_unused_variables))))
+ remove_unused_variables=remove_unused_variables,
+ ignore_init_module_imports=ignore_init_module_imports,
+ ))))
if filtered_source == source:
break
@@ -625,15 +632,27 @@
original_source = source
+ isInitFile = os.path.basename(filename) == '__init__.py'
+
+ if args.ignore_init_module_imports and isInitFile:
+ ignore_init_module_imports = True
+ else:
+ ignore_init_module_imports = False
+
filtered_source = fix_code(
source,
additional_imports=args.imports.split(',') if args.imports else None,
expand_star_imports=args.expand_star_imports,
remove_all_unused_imports=args.remove_all_unused_imports,
remove_duplicate_keys=args.remove_duplicate_keys,
- remove_unused_variables=args.remove_unused_variables)
+ remove_unused_variables=args.remove_unused_variables,
+ ignore_init_module_imports=ignore_init_module_imports,
+ )
if original_source != filtered_source:
+ if args.check:
+ standard_out.write('Unused imports/variables detected.')
+ sys.exit(1)
if args.in_place:
with open_with_encoding(filename, mode='w',
encoding=encoding) as output_file:
@@ -644,6 +663,9 @@
io.StringIO(filtered_source).readlines(),
filename)
standard_out.write(''.join(diff))
+ else:
+ if args.check:
+ standard_out.write('No issues detected!')
def open_with_encoding(filename, encoding, mode='r',
@@ -729,18 +751,25 @@
return True
-def match_file(filename, exclude):
- """Return True if file is okay for modifying/recursing."""
+def is_exclude_file(filename, exclude):
+ """Return True if file matches exclude pattern."""
base_name = os.path.basename(filename)
if base_name.startswith('.'):
- return False
+ return True
for pattern in exclude:
if fnmatch.fnmatch(base_name, pattern):
- return False
+ return True
if fnmatch.fnmatch(filename, pattern):
- return False
+ return True
+ return False
+
+
+def match_file(filename, exclude):
+ """Return True if file is okay for modifying/recursing."""
+ if is_exclude_file(filename, exclude):
+ return False
if not os.path.isdir(filename) and not is_python_file(filename):
return False
@@ -761,7 +790,8 @@
if match_file(os.path.join(root, d),
exclude)]
else:
- yield name
+ if not is_exclude_file(name, exclude):
+ yield name
def _main(argv, standard_out, standard_error):
@@ -771,6 +801,8 @@
"""
import argparse
parser = argparse.ArgumentParser(description=__doc__, prog='autoflake')
+ parser.add_argument('-c', '--check', action='store_true',
+ help='return error code if changes are needed')
parser.add_argument('-i', '--in-place', action='store_true',
help='make changes to files instead of printing diffs')
parser.add_argument('-r', '--recursive', action='store_true',
@@ -791,6 +823,9 @@
parser.add_argument('--remove-all-unused-imports', action='store_true',
help='remove all unused imports (not just those from '
'the standard library)')
+ parser.add_argument('--ignore-init-module-imports', action='store_true',
+ help='exclude __init__.py when removing unused '
+ 'imports')
parser.add_argument('--remove-duplicate-keys', action='store_true',
help='remove all duplicate keys in objects')
parser.add_argument('--remove-unused-variables', action='store_true',
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/autoflake-1.2/setup.cfg new/autoflake-1.3/setup.cfg
--- old/autoflake-1.2/setup.cfg 2018-05-09 16:09:31.000000000 +0200
+++ new/autoflake-1.3/setup.cfg 2019-04-21 18:27:29.000000000 +0200
@@ -1,5 +1,4 @@
[egg_info]
tag_build =
tag_date = 0
-tag_svn_revision = 0
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/autoflake-1.2/test_autoflake.py
new/autoflake-1.3/test_autoflake.py
--- old/autoflake-1.2/test_autoflake.py 2018-01-12 19:52:46.000000000 +0100
+++ new/autoflake-1.3/test_autoflake.py 2019-04-21 18:25:39.000000000 +0200
@@ -501,6 +501,41 @@
"""
self.assertEqual(line, ''.join(autoflake.filter_code(line)))
+ def test_with_ignore_init_module_imports_flag(self):
+ # Need a temp directory in order to specify file name as __init__.py
+ temp_directory = tempfile.mkdtemp(dir='.')
+ temp_file = os.path.join(temp_directory, '__init__.py')
+ try:
+ with open(temp_file, 'w') as output:
+ output.write('import re\n')
+
+ p = subprocess.Popen(
+ list(AUTOFLAKE_COMMAND) +
+ ['--ignore-init-module-imports', temp_file],
+ stdout=subprocess.PIPE)
+ result = p.communicate()[0].decode('utf-8')
+
+ self.assertNotIn('import re', result)
+ finally:
+ shutil.rmtree(temp_directory)
+
+ def test_without_ignore_init_module_imports_flag(self):
+ # Need a temp directory in order to specify file name as __init__.py
+ temp_directory = tempfile.mkdtemp(dir='.')
+ temp_file = os.path.join(temp_directory, '__init__.py')
+ try:
+ with open(temp_file, 'w') as output:
+ output.write('import re\n')
+
+ p = subprocess.Popen(
+ list(AUTOFLAKE_COMMAND) + [temp_file],
+ stdout=subprocess.PIPE)
+ result = p.communicate()[0].decode('utf-8')
+
+ self.assertIn('import re', result)
+ finally:
+ shutil.rmtree(temp_directory)
+
def test_fix_code(self):
self.assertEqual(
"""\
@@ -1156,6 +1191,23 @@
self.assertFalse(autoflake.is_python_file(os.devnull))
self.assertFalse(autoflake.is_python_file('/bin/bash'))
+ def test_is_exclude_file(self):
+ self.assertTrue(autoflake.is_exclude_file(
+ "1.py", ["test*", "1*"]))
+
+ self.assertFalse(autoflake.is_exclude_file(
+ "2.py", ["test*", "1*"]))
+
+ # folder glob
+ self.assertTrue(autoflake.is_exclude_file(
+ "test/test.py", ["test/**.py"]))
+
+ self.assertTrue(autoflake.is_exclude_file(
+ "test/auto_test.py", ["test/*_test.py"]))
+
+ self.assertFalse(autoflake.is_exclude_file(
+ "test/auto_auto.py", ["test/*_test.py"]))
+
def test_match_file(self):
with temporary_file('', suffix='.py', prefix='.') as filename:
self.assertFalse(autoflake.match_file(filename, exclude=[]),
@@ -1302,6 +1354,52 @@
pass
""", f.read())
+ def test_check_with_empty_file(self):
+ line = ''
+
+ with temporary_file(line) as filename:
+ output_file = io.StringIO()
+ autoflake._main(argv=['my_fake_program', '--check', filename],
+ standard_out=output_file,
+ standard_error=None)
+ self.assertEqual('No issues detected!', output_file.getvalue())
+
+ def test_check_correct_file(self):
+ with temporary_file("""\
+import foo
+x = foo.bar
+print(x)
+""") as filename:
+ output_file = io.StringIO()
+ autoflake._main(argv=['my_fake_program', '--check', filename],
+ standard_out=output_file,
+ standard_error=None)
+ self.assertEqual('No issues detected!', output_file.getvalue())
+
+ def test_check_useless_pass(self):
+ with temporary_file("""\
+import foo
+x = foo
+import subprocess
+x()
+
+try:
+ pass
+ import os
+except ImportError:
+ pass
+ import os
+ import sys
+""") as filename:
+ output_file = io.StringIO()
+ with self.assertRaises(SystemExit) as cm:
+ autoflake._main(argv=['my_fake_program', '--check', filename],
+ standard_out=output_file,
+ standard_error=None)
+ self.assertEqual(cm.exception.code, 1)
+ self.assertEqual('Unused imports/variables detected.',
+ output_file.getvalue())
+
def test_in_place_with_empty_file(self):
line = ''