Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-autoflake for openSUSE:Factory checked in at 2022-09-12 19:08:23 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-autoflake (Old) and /work/SRC/openSUSE:Factory/.python-autoflake.new.2083 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-autoflake" Mon Sep 12 19:08:23 2022 rev:9 rq:1002737 version:1.5.3 Changes: -------- --- /work/SRC/openSUSE:Factory/python-autoflake/python-autoflake.changes 2022-08-29 15:16:33.997989786 +0200 +++ /work/SRC/openSUSE:Factory/.python-autoflake.new.2083/python-autoflake.changes 2022-09-12 19:08:25.322565645 +0200 @@ -1,0 +2,22 @@ +Mon Sep 12 08:00:46 UTC 2022 - Dirk M??ller <dmuel...@suse.com> + +- reenable build for python38, issue got fixed in current release + +------------------------------------------------------------------- +Fri Sep 9 16:07:50 UTC 2022 - Yogalakshmi Arunachalam <yarunacha...@suse.com> + +- Update to v1.5.3 + * test_autoflake: use os.linesep in assertion + * Make sure messages use os.linesep + * test_autoflake: add a test for #129 + * autoflake: propagate the exit status instead of calling sys.exit + * Renamed the head branch + * Remove Makefile and reference to travis.yml + +- Update to v1.5.2 + * Remove usage of deprecated distutils module + * Also add support for removing RHS of unused variables. + * Use the new sysconfig module instead of distutils + * added option to remove RHS also when removing unused variables (#92) + +------------------------------------------------------------------- Old: ---- autoflake-1.5.1.tar.gz New: ---- autoflake-1.5.3.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-autoflake.spec ++++++ --- /var/tmp/diff_new_pack.s5ckzd/_old 2022-09-12 19:08:25.898567265 +0200 +++ /var/tmp/diff_new_pack.s5ckzd/_new 2022-09-12 19:08:25.906567287 +0200 @@ -16,10 +16,8 @@ # -# gh#PyCQA/autoflake#100 -%define skip_python38 1 Name: python-autoflake -Version: 1.5.1 +Version: 1.5.3 Release: 0 Summary: Program to removes unused Python imports and variables License: MIT ++++++ autoflake-1.5.1.tar.gz -> autoflake-1.5.3.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoflake-1.5.1/AUTHORS.rst new/autoflake-1.5.3/AUTHORS.rst --- old/autoflake-1.5.1/AUTHORS.rst 2022-08-28 05:35:19.000000000 +0200 +++ new/autoflake-1.5.3/AUTHORS.rst 2022-09-01 07:07:41.000000000 +0200 @@ -14,3 +14,4 @@ - James Curtin (https://github.com/jamescurtin) - Sargun Dhillon (https://github.com/sargun) - Anton Ogorodnikov (https://github.com/arxell) +- das-intensity (https://github.com/das-intensity) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoflake-1.5.1/MANIFEST.in new/autoflake-1.5.3/MANIFEST.in --- old/autoflake-1.5.1/MANIFEST.in 2022-08-28 05:35:19.000000000 +0200 +++ new/autoflake-1.5.3/MANIFEST.in 2022-09-01 07:07:41.000000000 +0200 @@ -3,7 +3,5 @@ include README.md include test_autoflake.py -exclude .travis.yml -exclude Makefile exclude test_fuzz.py exclude test_fuzz_pypi.py diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoflake-1.5.1/PKG-INFO new/autoflake-1.5.3/PKG-INFO --- old/autoflake-1.5.1/PKG-INFO 2022-08-28 05:35:29.277668500 +0200 +++ new/autoflake-1.5.3/PKG-INFO 2022-09-01 07:07:53.159021600 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: autoflake -Version: 1.5.1 +Version: 1.5.3 Summary: Removes unused imports and unused variables Home-page: https://www.github.com/PyCQA/autoflake License: MIT @@ -16,7 +16,7 @@ # autoflake -[](https://github.com/PyCQA/autoflake/actions/workflows/main.yaml) +[](https://github.com/PyCQA/autoflake/actions/workflows/main.yaml) ## Introduction @@ -126,6 +126,8 @@ remove all duplicate keys in objects --remove-unused-variables remove unused variables + --remove-rhs-for-unused-variables + remove RHS of statements when removing unused variables (unsafe) --version show program's version number and exit --quiet Suppress output if there are no issues -v, --verbose print more verbose logs (you can repeat `-v` to make it more verbose) @@ -209,7 +211,7 @@ ```yaml - repo: https://github.com/PyCQA/autoflake - rev: v1.5.1 + rev: v1.5.3 hooks: - id: autoflake ``` diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoflake-1.5.1/README.md new/autoflake-1.5.3/README.md --- old/autoflake-1.5.1/README.md 2022-08-28 05:35:19.000000000 +0200 +++ new/autoflake-1.5.3/README.md 2022-09-01 07:07:41.000000000 +0200 @@ -1,6 +1,6 @@ # autoflake -[](https://github.com/PyCQA/autoflake/actions/workflows/main.yaml) +[](https://github.com/PyCQA/autoflake/actions/workflows/main.yaml) ## Introduction @@ -110,6 +110,8 @@ remove all duplicate keys in objects --remove-unused-variables remove unused variables + --remove-rhs-for-unused-variables + remove RHS of statements when removing unused variables (unsafe) --version show program's version number and exit --quiet Suppress output if there are no issues -v, --verbose print more verbose logs (you can repeat `-v` to make it more verbose) @@ -193,7 +195,7 @@ ```yaml - repo: https://github.com/PyCQA/autoflake - rev: v1.5.1 + rev: v1.5.3 hooks: - id: autoflake ``` diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoflake-1.5.1/autoflake.egg-info/PKG-INFO new/autoflake-1.5.3/autoflake.egg-info/PKG-INFO --- old/autoflake-1.5.1/autoflake.egg-info/PKG-INFO 2022-08-28 05:35:29.000000000 +0200 +++ new/autoflake-1.5.3/autoflake.egg-info/PKG-INFO 2022-09-01 07:07:53.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: autoflake -Version: 1.5.1 +Version: 1.5.3 Summary: Removes unused imports and unused variables Home-page: https://www.github.com/PyCQA/autoflake License: MIT @@ -16,7 +16,7 @@ # autoflake -[](https://github.com/PyCQA/autoflake/actions/workflows/main.yaml) +[](https://github.com/PyCQA/autoflake/actions/workflows/main.yaml) ## Introduction @@ -126,6 +126,8 @@ remove all duplicate keys in objects --remove-unused-variables remove unused variables + --remove-rhs-for-unused-variables + remove RHS of statements when removing unused variables (unsafe) --version show program's version number and exit --quiet Suppress output if there are no issues -v, --verbose print more verbose logs (you can repeat `-v` to make it more verbose) @@ -209,7 +211,7 @@ ```yaml - repo: https://github.com/PyCQA/autoflake - rev: v1.5.1 + rev: v1.5.3 hooks: - id: autoflake ``` diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoflake-1.5.1/autoflake.py new/autoflake-1.5.3/autoflake.py --- old/autoflake-1.5.1/autoflake.py 2022-08-28 05:35:19.000000000 +0200 +++ new/autoflake-1.5.3/autoflake.py 2022-09-01 07:07:41.000000000 +0200 @@ -31,15 +31,15 @@ import signal import string import sys +import sysconfig import tokenize -import distutils.sysconfig import pyflakes.api import pyflakes.messages import pyflakes.reporter -__version__ = '1.5.1' +__version__ = '1.5.3' _LOGGER = logging.getLogger('autoflake') @@ -55,19 +55,18 @@ def standard_paths(): """Yield paths to standard modules.""" - for is_plat_spec in [True, False]: - + paths = sysconfig.get_paths() + path_names = ['stdlib', 'platstdlib'] + for path_name in path_names: # Yield lib paths. - path = distutils.sysconfig.get_python_lib( - standard_lib=True, - plat_specific=is_plat_spec, - ) - yield from os.listdir(path) - - # Yield lib-dynload paths. - dynload_path = os.path.join(path, 'lib-dynload') - if os.path.isdir(dynload_path): - yield from os.listdir(dynload_path) + if path_name in paths: + path = paths[path_name] + yield from os.listdir(path) + + # Yield lib-dynload paths. + dynload_path = os.path.join(path, 'lib-dynload') + if os.path.isdir(dynload_path): + yield from os.listdir(dynload_path) def standard_package_names(): @@ -494,6 +493,7 @@ remove_all_unused_imports=False, remove_duplicate_keys=False, remove_unused_variables=False, + remove_rhs_for_unused_variables=False, ignore_init_module_imports=False, ): """Yield code with unused imports removed.""" @@ -568,7 +568,9 @@ previous_line=previous_line, ) elif line_number in marked_variable_line_numbers: - result = filter_unused_variable(line) + result = filter_unused_variable( + line, drop_rhs=remove_rhs_for_unused_variables, + ) elif line_number in marked_key_line_numbers: result = filter_duplicate_key( line, line_messages[line_number], @@ -641,7 +643,7 @@ ) -def filter_unused_variable(line, previous_line=''): +def filter_unused_variable(line, previous_line='', drop_rhs=False): """Return line if used, otherwise return None.""" if re.match(EXCEPT_REGEX, line): return re.sub(r' as \w+:$', ':', line, count=1) @@ -658,7 +660,11 @@ # Rather than removing the line, replace with it "pass" to avoid # a possible hanging block with no body. value = 'pass' + get_line_ending(line) + if drop_rhs: + return get_indentation(line) + value + if drop_rhs: + return '' return get_indentation(line) + value else: return line @@ -789,7 +795,8 @@ def fix_code( source, additional_imports=None, expand_star_imports=False, remove_all_unused_imports=False, remove_duplicate_keys=False, - remove_unused_variables=False, ignore_init_module_imports=False, + remove_unused_variables=False, remove_rhs_for_unused_variables=False, + ignore_init_module_imports=False, ): """Return code with all filtering run on it.""" if not source: @@ -811,6 +818,9 @@ remove_all_unused_imports=remove_all_unused_imports, remove_duplicate_keys=remove_duplicate_keys, remove_unused_variables=remove_unused_variables, + remove_rhs_for_unused_variables=( + remove_rhs_for_unused_variables + ), ignore_init_module_imports=ignore_init_module_imports, ), ), @@ -824,7 +834,7 @@ return filtered_source -def fix_file(filename, args, standard_out=None): +def fix_file(filename, args, standard_out=None) -> int: """Run fix_code() on a file.""" if standard_out is None: standard_out = sys.stdout @@ -839,7 +849,7 @@ def _fix_file( input_file, filename, args, write_to_stdout, standard_out, encoding=None, -): +) -> int: source = input_file.read() original_source = source @@ -859,15 +869,18 @@ remove_all_unused_imports=args['remove_all_unused_imports'], remove_duplicate_keys=args['remove_duplicate_keys'], remove_unused_variables=args['remove_unused_variables'], + remove_rhs_for_unused_variables=( + args['remove_rhs_for_unused_variables'] + ), ignore_init_module_imports=ignore_init_module_imports, ) if original_source != filtered_source: if args['check']: standard_out.write( - f'{filename}: Unused imports/variables detected\n', + f'{filename}: Unused imports/variables detected{os.linesep}', ) - sys.exit(1) + return 1 if write_to_stdout: standard_out.write(filtered_source) elif args['in_place']: @@ -888,10 +901,12 @@ standard_out.write(filtered_source) else: if args['check'] and not args['quiet']: - standard_out.write('No issues detected!\n') + standard_out.write(f'No issues detected!{os.linesep}') else: _LOGGER.debug('Clean %s: nothing to fix', filename) + return 0 + def open_with_encoding( filename, encoding, mode='r', @@ -1117,6 +1132,7 @@ 'check', 'expand-star-imports', 'ignore-init-module-imports', 'in-place', 'recursive', 'remove-all-unused-imports', 'remove-duplicate-keys', 'remove-unused-variables', + 'remove-rhs-for-unused-variables', }: # boolean properties if isinstance(value, str): @@ -1135,7 +1151,7 @@ return True -def _main(argv, standard_out, standard_error, standard_input=None): +def _main(argv, standard_out, standard_error, standard_input=None) -> int: """Return exit status. 0 means no error. @@ -1193,6 +1209,11 @@ help='remove unused variables', ) parser.add_argument( + '--remove-rhs-for-unused-variables', action='store_true', + help='remove RHS of statements when removing unused ' + 'variables (unsafe)', + ) + parser.add_argument( '--version', action='version', version='%(prog)s ' + __version__, ) @@ -1246,6 +1267,15 @@ _LOGGER.error('Using both --remove-all and --imports is redundant') return 1 + if args.remove_rhs_for_unused_variables and not ( + args.remove_unused_variables + ): + _LOGGER.error( + 'Using --remove-rhs-for-unused-variables only makes sense when ' + 'used with --remove-unused-variables', + ) + return 1 + if args.exclude: args.exclude = _split_comma_separated(args.exclude) else: @@ -1255,27 +1285,31 @@ args.jobs = os.cpu_count() or 1 filenames = list(set(args.files)) - failure = False # convert argparse namespace to a dict so that it can be serialized # by multiprocessing args = vars(args) + exit_status = 0 files = list(find_files(filenames, args['recursive'], args['exclude'])) if args['jobs'] == 1 or len(files) == 1 or args['jobs'] == 1 or \ '-' in files or standard_out is not None: for name in files: if name == '-': - _fix_file( + exit_status |= _fix_file( standard_input, args['stdin_display_name'], args=args, write_to_stdout=True, standard_out=standard_out or sys.stdout, ) else: try: - fix_file(name, args=args, standard_out=standard_out) + exit_status |= fix_file( + name, + args=args, + standard_out=standard_out, + ) except OSError as exception: _LOGGER.error(str(exception)) - failure = True + exit_status |= 1 else: import multiprocessing @@ -1286,12 +1320,12 @@ futs.append(fut) for fut in futs: try: - fut.get() + exit_status |= fut.get() except OSError as exception: _LOGGER.error(str(exception)) - failure = True + exit_status |= 1 - return 1 if failure else 0 + return exit_status def main(): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/autoflake-1.5.1/test_autoflake.py new/autoflake-1.5.3/test_autoflake.py --- old/autoflake-1.5.1/test_autoflake.py 2022-08-28 05:35:19.000000000 +0200 +++ new/autoflake-1.5.3/test_autoflake.py 2022-09-01 07:07:41.000000000 +0200 @@ -18,25 +18,13 @@ ROOT_DIRECTORY = os.path.abspath(os.path.dirname(__file__)) -if ( - 'AUTOFLAKE_COVERAGE' in os.environ and - int(os.environ['AUTOFLAKE_COVERAGE']) -): - AUTOFLAKE_COMMAND = [ - 'coverage', 'run', '--branch', '--parallel', - '--omit=*/distutils/*,*/site-packages/*', - os.path.join(ROOT_DIRECTORY, 'autoflake.py'), - ] -else: - # We need to specify the executable to make sure the correct Python - # interpreter gets used. - AUTOFLAKE_COMMAND = [ - sys.executable, - os.path.join( - ROOT_DIRECTORY, - 'autoflake.py', - ), - ] # pragma: no cover +AUTOFLAKE_COMMAND = [ + sys.executable, + os.path.join( + ROOT_DIRECTORY, + 'autoflake.py', + ), +] class UnitTests(unittest.TestCase): @@ -197,6 +185,80 @@ ), ) + def test_filter_unused_variable_drop_rhs(self): + self.assertEqual( + '', autoflake.filter_unused_variable( + 'x = foo()', drop_rhs=True, + ), + ) + + self.assertEqual( + '', autoflake.filter_unused_variable( + ' x = foo()', drop_rhs=True, + ), + ) + + def test_filter_unused_variable_with_literal_or_name_drop_rhs(self): + self.assertEqual( + 'pass', + autoflake.filter_unused_variable('x = 1', drop_rhs=True), + ) + + self.assertEqual( + 'pass', + autoflake.filter_unused_variable('x = y', drop_rhs=True), + ) + + self.assertEqual( + 'pass', + autoflake.filter_unused_variable('x = {}', drop_rhs=True), + ) + + def test_filter_unused_variable_with_basic_data_structures_drop_rhs(self): + self.assertEqual( + 'pass', + autoflake.filter_unused_variable('x = dict()', drop_rhs=True), + ) + + self.assertEqual( + 'pass', + autoflake.filter_unused_variable('x = list()', drop_rhs=True), + ) + + self.assertEqual( + 'pass', + autoflake.filter_unused_variable('x = set()', drop_rhs=True), + ) + + def test_filter_unused_variable_should_ignore_multiline_drop_rhs(self): + self.assertEqual( + 'x = foo()\\', + autoflake.filter_unused_variable('x = foo()\\', drop_rhs=True), + ) + + def test_filter_unused_variable_should_multiple_assignments_drop_rhs(self): + self.assertEqual( + 'x = y = foo()', + autoflake.filter_unused_variable('x = y = foo()', drop_rhs=True), + ) + + def test_filter_unused_variable_with_exception_drop_rhs(self): + self.assertEqual( + 'except Exception:', + autoflake.filter_unused_variable( + 'except Exception as exception:', + drop_rhs=True, + ), + ) + + self.assertEqual( + 'except (ImportError, ValueError):', + autoflake.filter_unused_variable( + 'except (ImportError, ValueError) as foo:', + drop_rhs=True, + ), + ) + def test_filter_code(self): self.assertEqual( """\ @@ -895,6 +957,25 @@ ), ) + def test_fix_code_with_unused_variables_drop_rhs(self): + self.assertEqual( + """\ +def main(): + y = 11 + print(y) +""", + autoflake.fix_code( + """\ +def main(): + x = 10 + y = 11 + print(y) +""", + remove_unused_variables=True, + remove_rhs_for_unused_variables=True, + ), + ) + def test_fix_code_with_unused_variables_should_skip_nonlocal(self): """pyflakes does not handle nonlocal correctly.""" code = """\ @@ -913,6 +994,27 @@ ), ) + def test_fix_code_with_unused_variables_should_skip_nonlocal_drop_rhs( + self, + ): + """pyflakes does not handle nonlocal correctly.""" + code = """\ +def bar(): + x = 1 + + def foo(): + nonlocal x + x = 2 +""" + self.assertEqual( + code, + autoflake.fix_code( + code, + remove_unused_variables=True, + remove_rhs_for_unused_variables=True, + ), + ) + def test_detect_encoding_with_bad_encoding(self): with temporary_file('# -*- coding: blah -*-\n') as filename: self.assertEqual( @@ -936,6 +1038,23 @@ ), ) + def test_fix_code_with_comma_on_right_drop_rhs(self): + """pyflakes does not handle nonlocal correctly.""" + self.assertEqual( + """\ +def main(): + pass +""", + autoflake.fix_code( + """\ +def main(): + x = (1, 2, 3) +""", + remove_unused_variables=True, + remove_rhs_for_unused_variables=True, + ), + ) + def test_fix_code_with_unused_variables_should_skip_multiple(self): code = """\ def main(): @@ -950,6 +1069,23 @@ ), ) + def test_fix_code_with_unused_variables_should_skip_multiple_drop_rhs( + self, + ): + code = """\ +def main(): + (x, y, z) = (1, 2, 3) + print(z) +""" + self.assertEqual( + code, + autoflake.fix_code( + code, + remove_unused_variables=True, + remove_rhs_for_unused_variables=True, + ), + ) + def test_fix_code_should_handle_pyflakes_recursion_error_gracefully(self): code = 'x = [{}]'.format('+'.join(['abc' for _ in range(2000)])) self.assertEqual( @@ -1728,7 +1864,10 @@ standard_out=output_file, standard_error=None, ) - self.assertEqual('No issues detected!\n', output_file.getvalue()) + self.assertEqual( + f'No issues detected!{os.linesep}', + output_file.getvalue(), + ) def test_check_correct_file(self): with temporary_file("""\ @@ -1742,7 +1881,10 @@ standard_out=output_file, standard_error=None, ) - self.assertEqual('No issues detected!\n', output_file.getvalue()) + self.assertEqual( + f'No issues detected!{os.linesep}', + output_file.getvalue(), + ) def test_check_correct_file_with_quiet(self): with temporary_file("""\ @@ -1777,16 +1919,33 @@ import sys """) as filename: output_file = io.StringIO() - with self.assertRaises(SystemExit) as cm: - autoflake._main( - argv=['my_fake_program', '--check', filename], + exit_status = autoflake._main( + argv=['my_fake_program', '--check', filename], + standard_out=output_file, + standard_error=None, + ) + self.assertEqual(exit_status, 1) + self.assertEqual( + f'{filename}: Unused imports/variables detected{os.linesep}', + output_file.getvalue(), + ) + + def test_check_with_multiple_files(self): + with temporary_file('import sys') as file1: + with temporary_file('import sys') as file2: + output_file = io.StringIO() + exit_status = autoflake._main( + argv=['my_fake_program', '--check', file1, file2], standard_out=output_file, standard_error=None, ) - self.assertEqual(cm.exception.code, 1) + self.assertEqual(exit_status, 1) self.assertEqual( - 'Unused imports/variables detected.', - output_file.getvalue(), + { + f'{file1}: Unused imports/variables detected', + f'{file2}: Unused imports/variables detected', + }, + set(output_file.getvalue().strip().split(os.linesep)), ) def test_in_place_with_empty_file(self):