From 88ede156ec324b1e6028026c5964d66078a00e19 Mon Sep 17 00:00:00 2001 From: Jeff Goeders Date: Sun, 7 Mar 2021 11:05:08 -0700 Subject: [PATCH] Update pylint_check.py to check individual files --- README.developers.md | 2 +- dev/pylint_check.py | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.developers.md b/README.developers.md index f9a4bdd61a2..6273d026f8d 100644 --- a/README.developers.md +++ b/README.developers.md @@ -177,7 +177,7 @@ For large scale reformatting (should only be performed by VTR maintainers) the s ## Python Linting -Python files are automatically checked using `pylint` to ensure they follow established Python conventions. You can check an individual Python file by running `pylint `, or check the entire repository by running `./dev/pylint_check.py`. +Python files are automatically checked using `pylint` to ensure they follow established Python conventions. You can run `pylint` on the entire repository by running `./dev/pylint_check.py`. Certain files which were created before we adopted Python lint checking are grandfathered and are not checked. To check *all* files, provide the `--check_grandfathered` argument. You can also manually check individual files using `./dev/pylint_check.py ...`. # Running Tests diff --git a/dev/pylint_check.py b/dev/pylint_check.py index bef12b6ae78..6f97859e060 100755 --- a/dev/pylint_check.py +++ b/dev/pylint_check.py @@ -121,7 +121,7 @@ def expand_paths(): if path.suffix.lower() != ".py": print(path, "does note have extension '.py'") sys.exit(-1) - paths.append(path) + paths.append(path.resolve()) # If path is a directory, search for .py files elif path.is_dir(): @@ -151,11 +151,22 @@ def main(): action="store_true", help="Also check grandfathered files for lint errors.", ) + parser.add_argument("files", nargs="*", help="List of files to check using pylint.") args = parser.parse_args() - # Expand all paths - paths = expand_paths() - print(TermColor.BLUE + "Linting", len(paths), "python files.", TermColor.END) + # Check if we are doing all files, or user-provided list + if args.files: + # Check that all files exist, and build pathlib objects + paths = [] + for file in args.files: + f_path = pathlib.Path(file).resolve() + if not f_path.is_file(): + error(f_path, "does not exist") + paths.append(f_path) + else: + # Expand all paths + paths = expand_paths() + print(TermColor.BLUE + "Linting", len(paths), "python file(s).", TermColor.END) # Lint files num_error_files = 0