Skip to content

Update pylint_check.py to check individual files #1685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.developers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <your_python_file>`, 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 <path_to_file1> <path_to_file2> ...`.

# Running Tests

Expand Down
19 changes: 15 additions & 4 deletions dev/pylint_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down