diff --git a/asclib/checkers/typific/__init__.py b/asclib/checkers/typific/__init__.py index 8bcf46c..161c554 100644 --- a/asclib/checkers/typific/__init__.py +++ b/asclib/checkers/typific/__init__.py @@ -30,11 +30,9 @@ def __init__(self, filename, config): # The purpose of this change is to make sure child class # insn't missing an entry for one of the checkers. for rulific_checker in ALL_RULIFIC_CHECKERS: - assert ( - rulific_checker.RULE_CONFIG_NAME in self.rulific_decision_map - ), "%s checker missing config about %s rule" % ( - self.file_type, - rulific_checker.RULE_CONFIG_NAME, + assert rulific_checker.RULE_CONFIG_NAME in self.rulific_decision_map, ( + "%s checker missing config about %s rule" + % (self.file_type, rulific_checker.RULE_CONFIG_NAME,) ) # Build the list of checkers we actually want to run @@ -206,10 +204,9 @@ def dump_checks(self, cvs_check_file_type, print_header=False, print_footer=Fals for checker in ALL_RULIFIC_CHECKERS if checker not in [c for _, c in RULES_LIST] ] - assert ( - not missed_checkers - ), "The following rules are missing from the dump above: " + ", ".join( - missed_checkers + assert not missed_checkers, ( + "The following rules are missing from the dump above: " + + ", ".join(missed_checkers) ) ###################################################################### diff --git a/asclib/checkers/typific/python.py b/asclib/checkers/typific/python.py index 1035140..e351b81 100644 --- a/asclib/checkers/typific/python.py +++ b/asclib/checkers/typific/python.py @@ -40,7 +40,6 @@ # For more details, see: # https://github.com/PyCQA/pycodestyle/issues/373 "E203", - # flake8: E402: module level import not at top of file # # Rationale: See Q721-011: We sometimes need to import sys, diff --git a/setup.py b/setup.py index 208437e..d94927f 100644 --- a/setup.py +++ b/setup.py @@ -20,14 +20,7 @@ long_description_content_type="text/markdown", packages=find_packages(where="."), package_dir={"": "."}, - package_data={ - "asclib.checkers.typific": ["*.xml"], - "etc": ["*"], - }, + package_data={"asclib.checkers.typific": ["*.xml"], "etc": ["*"]}, install_requires=install_requires, - entry_points={ - "console_scripts": [ - "style_checker = asclib.main:main" - ], - }, + entry_points={"console_scripts": ["style_checker = asclib.main:main"]}, ) diff --git a/style_checker b/style_checker index 09dd62e..2da6d67 100755 --- a/style_checker +++ b/style_checker @@ -3,5 +3,5 @@ from asclib.main import main -if __name__ == '__main__': +if __name__ == "__main__": main() diff --git a/testsuite/conftest.py b/testsuite/conftest.py index f6c5df7..dad8cf6 100644 --- a/testsuite/conftest.py +++ b/testsuite/conftest.py @@ -30,9 +30,9 @@ def env_setup(request): # file or directory it might be creating, by verifying at the end # of the test that this temporary directory is empty. style_checker_tmp_dir = tempfile.mkdtemp("", "style_checker-") - style_checker_tmp_dir = os.path.join(tmp_dir, 'tmp') + style_checker_tmp_dir = os.path.join(tmp_dir, "tmp") os.mkdir(style_checker_tmp_dir) - for var_name in ('TMPDIR', 'TEMP', 'TMP'): + for var_name in ("TMPDIR", "TEMP", "TMP"): os.environ[var_name] = style_checker_tmp_dir def env_teardown(): @@ -40,8 +40,7 @@ def env_teardown(): os.environ.update(saved_environ) style_checker_tmp_dir_contents = os.listdir(style_checker_tmp_dir) - assert not style_checker_tmp_dir_contents, \ - style_checker_tmp_dir_contents + assert not style_checker_tmp_dir_contents, style_checker_tmp_dir_contents os.chdir(saved_cwd) shutil.rmtree(tmp_dir) @@ -63,6 +62,7 @@ class StyleCheckerFixture: to be performed as if this was the current year (an int). See the set_year method for additional information. """ + def __init__(self, src_prefix_dir, testcase_src_dir, testcase_work_dir): """Initialize self. @@ -74,8 +74,7 @@ def __init__(self, src_prefix_dir, testcase_src_dir, testcase_work_dir): self.src_prefix_dir = src_prefix_dir self.src_dir = testcase_src_dir self.work_dir = testcase_work_dir - self.style_checker_exe = os.path.join(self.src_prefix_dir, - 'style_checker') + self.style_checker_exe = os.path.join(self.src_prefix_dir, "style_checker") self.forced_year = None # Set the testcase up, by copying everything from the testcase's @@ -139,18 +138,17 @@ def run_style_checker(self, *args, **kwargs): """ use_sys_executable = False # The named parameters to use when calling subprocess.run - run_kwargs = {'cwd': self.work_dir, - 'timeout': 60} + run_kwargs = {"cwd": self.work_dir, "timeout": 60} for arg_name, arg_val in kwargs.items(): - if arg_name in ('input', ): + if arg_name in ("input",): run_kwargs[arg_name] = arg_val - elif arg_name == 'use_sys_executable' and arg_val: + elif arg_name == "use_sys_executable" and arg_val: use_sys_executable = True else: raise ValueError( - 'Invalid argument in call to run_style_checker: {}' - .format(arg_name)) + "Invalid argument in call to run_style_checker: {}".format(arg_name) + ) cmd = [] @@ -159,7 +157,7 @@ def run_style_checker(self, *args, **kwargs): cmd.append(self.style_checker_exe) if self.forced_year is not None: - cmd.append('--forced-year=%d' % self.forced_year) + cmd.append("--forced-year=%d" % self.forced_year) cmd.extend(list(args)) @@ -169,9 +167,7 @@ def enable_unit_test(self): """Set the environment up to allow us to perform unit tests.""" sys.path.insert(0, self.src_prefix_dir) - def make_minimal_copy_of_python_install( - self, target_dir, exclude_modules=None - ): + def make_minimal_copy_of_python_install(self, target_dir, exclude_modules=None): """Create a minimal copy of Python in target_dir. The goal of this method is to provide a minimal install that @@ -209,9 +205,7 @@ def make_minimal_copy_of_python_install( ignore = None else: ignore = [] - site_pkg_dir = os.path.join( - src_root_dir, "lib", "python*", "site-packages" - ) + site_pkg_dir = os.path.join(src_root_dir, "lib", "python*", "site-packages") for module_name in exclude_modules: ignore.extend( os.path.relpath(p, src_root_dir) @@ -219,10 +213,7 @@ def make_minimal_copy_of_python_install( ) sync_tree( - source=src_root_dir, - target=target_dir, - ignore=ignore, - file_list=file_list, + source=src_root_dir, target=target_dir, ignore=ignore, file_list=file_list, ) def assertEqual(self, lhs, rhs, msg_if_fails): @@ -302,7 +293,7 @@ def assertRunOutputEmpty(self, r): PARAMETERS r: A Run object. """ - self.assertRunOutputEqual(r, '') + self.assertRunOutputEqual(r, "") @pytest.fixture(scope="function") @@ -310,13 +301,16 @@ def style_checker(pytestconfig, request): """Return a StyleCheckerFixture.""" testcase_script_filename = request.fspath.strpath testcase_src_dir = os.path.dirname(testcase_script_filename) - return StyleCheckerFixture(src_prefix_dir=pytestconfig.rootdir.strpath, - testcase_src_dir=testcase_src_dir, - testcase_work_dir=os.getcwd()) + return StyleCheckerFixture( + src_prefix_dir=pytestconfig.rootdir.strpath, + testcase_src_dir=testcase_src_dir, + testcase_work_dir=os.getcwd(), + ) class Run(e3.os.process.Run): """An e3.os.process.Run subclass with a few extra bells and whistles...""" + @property def cmd_out(self): """Same as self.out, except that the output is sanitized. @@ -334,6 +328,8 @@ def image(self): REMARKS This assumes that this command has run to completion. """ - return '%% %s -> %s\n%s' % (self.command_line_image(), - self.status, - self.cmd_out) + return "%% %s -> %s\n%s" % ( + self.command_line_image(), + self.status, + self.cmd_out, + ) diff --git a/testsuite/run-validation-tests b/testsuite/run-validation-tests index c8a92f5..cb52668 100755 --- a/testsuite/run-validation-tests +++ b/testsuite/run-validation-tests @@ -9,12 +9,11 @@ import shutil import sys # The minimum version of Python we need to run the validation testing. -MINIMUM_PYTHON_VERSION = '3.8' +MINIMUM_PYTHON_VERSION = "3.8" # The root directory of this repository. By construction, it is # the parent directory of the directory containing this script. -REPOSITORY_ROOT_DIR = \ - os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +REPOSITORY_ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) def run(cmds, **kwargs): @@ -67,14 +66,15 @@ def check_dependencies(args): required_packages.append("flake8") # First, check that the Python being used is recent enough. - python_version = StrictVersion( - "{v.major}.{v.minor}".format(v=sys.version_info)) + python_version = StrictVersion("{v.major}.{v.minor}".format(v=sys.version_info)) if python_version < MINIMUM_PYTHON_VERSION: - print("ERROR: Your version of Python is too old: " - "({v.major}.{v.minor}.{v.micro}-{v.releaselevel})" - .format(v=sys.version_info)) - print(" Minimum version required: {}" - .format(MINIMUM_PYTHON_VERSION)) + print( + "ERROR: Your version of Python is too old: " + "({v.major}.{v.minor}.{v.micro}-{v.releaselevel})".format( + v=sys.version_info + ) + ) + print(" Minimum version required: {}".format(MINIMUM_PYTHON_VERSION)) print("Aborting.") sys.exit(1) @@ -133,8 +133,7 @@ def run_testsuite(args): # activated. testsuite_cmd.extend(["-n", args.jobs]) if args.include_coverage: - testsuite_cmd.extend(["--cov", REPOSITORY_ROOT_DIR, - "--cov-report=html"]) + testsuite_cmd.extend(["--cov", REPOSITORY_ROOT_DIR, "--cov-report=html"]) if args.testsuite_filter is not None: testsuite_cmd.extend(["-k", args.testsuite_filter]) @@ -154,25 +153,46 @@ def run_style_conformance_checks(args): def main(): """Implement the main subprogram for this script.""" parser = ArgumentParser(description="Run the style_checker testsuite") - parser.add_argument("--jobs", "-j", metavar="N", default="auto", - help="Run the testsuite with N jobs in parallel." - " If not provided, the system determines the number" - " of jobs based on the number of CPU cores available.") - parser.add_argument("--no-testsuite", dest="run_testsuite", - default=True, action="store_false", - help="Skip running the testsuite (useful when" - " only trying to perform coding style conformance" - " checks") - parser.add_argument("--no-coverage", dest="include_coverage", - default=True, action="store_false", - help="Run the testsuite with coverage analysis") - parser.add_argument("--no-style-checking", dest="verify_style_conformance", - default=True, action="store_false", - help="Skip the coding style conformance checks") - parser.add_argument("testsuite_filter", metavar="EXPRESSION", nargs="?", - help="Ask pytest to restring the testing to the tests" - " matching the given substring expression (passed" - " to pytest -via -k)") + parser.add_argument( + "--jobs", + "-j", + metavar="N", + default="auto", + help="Run the testsuite with N jobs in parallel." + " If not provided, the system determines the number" + " of jobs based on the number of CPU cores available.", + ) + parser.add_argument( + "--no-testsuite", + dest="run_testsuite", + default=True, + action="store_false", + help="Skip running the testsuite (useful when" + " only trying to perform coding style conformance" + " checks", + ) + parser.add_argument( + "--no-coverage", + dest="include_coverage", + default=True, + action="store_false", + help="Run the testsuite with coverage analysis", + ) + parser.add_argument( + "--no-style-checking", + dest="verify_style_conformance", + default=True, + action="store_false", + help="Skip the coding style conformance checks", + ) + parser.add_argument( + "testsuite_filter", + metavar="EXPRESSION", + nargs="?", + help="Ask pytest to restring the testing to the tests" + " matching the given substring expression (passed" + " to pytest -via -k)", + ) args = parser.parse_args() check_dependencies(args)