Ajust scripts for new python and pylint

This commit is contained in:
Blaise
2024-03-30 13:33:03 -05:00
parent 75654057f1
commit 88fc9a108b
18 changed files with 290 additions and 282 deletions

View File

@@ -55,8 +55,8 @@ def main():
args = parser.parse_args()
if check_downloads_ini(args.downloads_ini):
exit(1)
exit(0)
sys.exit(1)
sys.exit(0)
if __name__ == '__main__':

View File

@@ -30,7 +30,7 @@ def main():
print('ERROR: Path "{}" from file "{}" does not exist.'.format(
file_name, input_name),
file=sys.stderr)
exit(1)
sys.exit(1)
if __name__ == "__main__":

View File

@@ -71,8 +71,8 @@ def main():
args = parser.parse_args()
if check_gn_flags(args.flags_gn):
exit(1)
exit(0)
sys.exit(1)
sys.exit(0)
if __name__ == '__main__':

View File

@@ -23,7 +23,7 @@ from pathlib import Path
from third_party import unidiff
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / 'utils'))
from _common import ENCODING, get_logger, parse_series
from _common import ENCODING, get_logger, parse_series # pylint: disable=wrong-import-order
sys.path.pop(0)
# File suffixes to ignore for checking unused patches
@@ -131,8 +131,8 @@ def main():
warnings |= check_unused_patches(args.patches)
if warnings:
exit(1)
exit(0)
sys.exit(1)
sys.exit(0)
if __name__ == '__main__':

View File

@@ -24,6 +24,7 @@ def main():
disables = [
'wrong-import-position',
'bad-continuation',
'duplicate-code',
]
if args.hide_fixme:
@@ -53,8 +54,8 @@ def main():
sys.path.pop(2)
sys.path.pop(1)
if not result:
exit(1)
exit(0)
sys.exit(1)
sys.exit(0)
if __name__ == '__main__':

View File

@@ -8,6 +8,7 @@
import argparse
import os
import shutil
import sys
from pathlib import Path
from pylint import lint
@@ -38,7 +39,7 @@ def run_pylint(module_path, pylint_options, ignore_prefixes=tuple()):
input_paths = list()
if not module_path.exists():
print('ERROR: Cannot find', module_path)
exit(1)
sys.exit(1)
if module_path.is_dir():
for path in module_path.rglob('*.py'):
ignore_matched = False
@@ -75,7 +76,7 @@ def main():
if not args.module_path.exists():
print('ERROR: Module path "{}" does not exist'.format(args.module_path))
exit(1)
sys.exit(1)
disables = [
'wrong-import-position',
@@ -95,8 +96,8 @@ def main():
]
if not run_pylint(args.module_path, pylint_options):
exit(1)
exit(0)
sys.exit(1)
sys.exit(0)
if __name__ == '__main__':

View File

@@ -41,6 +41,7 @@ def main():
]
sys.path.insert(1, str(Path(__file__).resolve().parent.parent / 'utils' / 'third_party'))
sys.path.append(Path(__file__).resolve().parent.parent / 'utils')
with ChangeDir(Path(__file__).resolve().parent.parent / 'utils'):
result = run_pylint(
Path(),
@@ -49,8 +50,8 @@ def main():
)
sys.path.pop(1)
if not result:
exit(1)
exit(0)
sys.exit(1)
sys.exit(0)
if __name__ == '__main__':

View File

@@ -5,19 +5,30 @@
# found in the LICENSE file.
"""Test check_patch_files.py"""
import logging
import tempfile
import sys
from pathlib import Path
from ..check_patch_files import check_series_duplicates
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent / 'utils'))
from _common import get_logger, set_logging_level
sys.path.pop(0)
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from check_patch_files import check_series_duplicates
sys.path.pop(0)
def test_check_series_duplicates():
"""Test check_series_duplicates"""
set_logging_level(logging.DEBUG)
with tempfile.TemporaryDirectory() as tmpdirname:
patches_dir = Path(tmpdirname)
series_path = Path(tmpdirname, 'series')
# Check no duplicates
get_logger().info('Check no duplicates')
series_path.write_text('\n'.join([
'a.patch',
'b.patch',
@@ -25,7 +36,7 @@ def test_check_series_duplicates():
]))
assert not check_series_duplicates(patches_dir)
# Check duplicates
get_logger().info('Check duplicates')
series_path.write_text('\n'.join([
'a.patch',
'b.patch',
@@ -33,3 +44,7 @@ def test_check_series_duplicates():
'a.patch',
]))
assert check_series_duplicates(patches_dir)
if __name__ == '__main__':
test_check_series_duplicates()

View File

@@ -11,18 +11,19 @@ import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent / 'utils'))
from _common import LOGGER_NAME
from _common import get_logger, set_logging_level
sys.path.pop(0)
from .. import validate_patches
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
import validate_patches
sys.path.pop(0)
def test_test_patches(caplog):
def test_test_patches():
"""Test _dry_check_patched_file"""
#pylint: disable=protected-access
caplog.set_level(logging.DEBUG, logger=LOGGER_NAME)
#set_logging_level(logging.DEBUG)
set_logging_level(logging.DEBUG)
orig_file_content = """bye world"""
series_iter = ['test.patch']
@@ -37,7 +38,7 @@ def test_test_patches(caplog):
Path(tmpdirname))
return validate_patches._test_patches(series_iter, patch_cache, files_under_test)
# Check valid modification
get_logger().info('Check valid modification')
patch_content = """--- a/foobar.txt
+++ b/foobar.txt
@@ -1 +1 @@
@@ -46,7 +47,7 @@ def test_test_patches(caplog):
"""
assert not _run_test_patches(patch_content)
# Check invalid modification
get_logger().info('Check invalid modification')
patch_content = """--- a/foobar.txt
+++ b/foobar.txt
@@ -1 +1 @@
@@ -55,7 +56,7 @@ def test_test_patches(caplog):
"""
assert _run_test_patches(patch_content)
# Check correct removal
get_logger().info('Check correct removal')
patch_content = """--- a/foobar.txt
+++ /dev/null
@@ -1 +0,0 @@
@@ -63,10 +64,14 @@ def test_test_patches(caplog):
"""
assert not _run_test_patches(patch_content)
# Check incorrect removal
get_logger().info('Check incorrect removal')
patch_content = """--- a/foobar.txt
+++ /dev/null
@@ -1 +0,0 @@
-this line does not exist in foobar
"""
assert _run_test_patches(patch_content)
if __name__ == '__main__':
test_test_patches()

View File

@@ -276,7 +276,7 @@ def compute_lists_proc(path, source_tree, search_regex):
domain_substitution_set, symlink_set)
def compute_lists(source_tree, search_regex, processes):
def compute_lists(source_tree, search_regex, processes): # pylint: disable=too-many-locals
"""
Compute the binary pruning and domain substitution lists of the source tree.
Returns a tuple of three items in the following order:
@@ -303,10 +303,12 @@ def compute_lists(source_tree, search_regex, processes):
# Handle the returned data
for (used_pep_set, used_pip_set, used_dep_set, used_dip_set, returned_pruning_set,
returned_domain_sub_set, returned_symlink_set) in returned_data:
# pragma pylint: disable=no-member
unused_patterns.pruning_exclude_patterns.difference_update(used_pep_set)
unused_patterns.pruning_include_patterns.difference_update(used_pip_set)
unused_patterns.domain_exclude_prefixes.difference_update(used_dep_set)
unused_patterns.domain_include_patterns.difference_update(used_dip_set)
# pragma pylint: enable=no-member
pruning_set.update(returned_pruning_set)
domain_substitution_set.update(returned_domain_sub_set)
symlink_set.update(returned_symlink_set)
@@ -366,7 +368,7 @@ def main(args_list=None):
get_logger().info('Using existing source tree at %s', args.tree)
else:
get_logger().error('No source tree found. Aborting.')
exit(1)
sys.exit(1)
get_logger().info('Computing lists...')
pruning_set, domain_substitution_set, unused_patterns = compute_lists(
args.tree,
@@ -378,7 +380,7 @@ def main(args_list=None):
if unused_patterns.log_unused(args.error_unused) and args.error_unused:
get_logger().error('Please update or remove unused patterns and/or prefixes. '
'The lists have still been updated with the remaining valid entries.')
exit(1)
sys.exit(1)
if __name__ == "__main__":

View File

@@ -50,8 +50,8 @@ def main():
warnings |= check_downloads_ini([root_dir / 'downloads.ini'])
if warnings:
exit(1)
exit(0)
sys.exit(1)
sys.exit(0)
if __name__ == '__main__':