Skip to content

Commit

Permalink
Apply the rest of the linters in CI (#6208)
Browse files Browse the repository at this point in the history
Added a bunch of exclusions to get it green. We should to back at some
point and try to remove them
Updated grep_linter (undoes
https://togithub.com/pytorch/pytorch/pull/144589)
Updated exec_linter
  • Loading branch information
clee2000 authored Jan 23, 2025
1 parent d1c921e commit e83685f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
- name: Run lintrunner on all files - Linux
run: |
set +e
if ! lintrunner -v --force-color --all-files --tee-json=lint.json --skip TYPEIGNORE,NOQA,PYPIDEP,EXEC; then
if ! lintrunner -v --force-color --all-files --tee-json=lint.json; then
echo ""
echo -e "\e[1m\e[36mYou can reproduce these results locally by using \`lintrunner -m main\`.\e[0m"
exit 1
Expand Down
14 changes: 14 additions & 0 deletions .lintrunner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ init_command = [
code = 'TYPEIGNORE'
include_patterns = ['**/*.py', '**/*.pyi']
exclude_patterns = [
# Putting these exclusions just to get the linter running.
"tools/stronghold/src/api/types.py",
"tools/stronghold/tests/api/test_ast_param_types.py",
]
command = [
'python3',
Expand Down Expand Up @@ -192,6 +195,15 @@ exclude_patterns = [
'**/*.py',
'**/*.md',
'**/*.diff',
# Putting these exclusions just to get the linter running.
".github/scripts/validate_binaries.sh",
".github/scripts/validate_pipy.sh",
".github/scripts/validate_test_ops.sh",
".github/workflows/build_wheels_macos.yml",
".github/workflows/github-status-test-lambda.yml",
".github/workflows/log-classifier-lambda.yml",
".github/workflows/validate-linux-binaries.yml",
".github/workflows/validate-repackaged-binary-sizes.yml",
]
command = [
'python3',
Expand Down Expand Up @@ -225,6 +237,8 @@ exclude_patterns = [
'**/gradlew',
'**/fixtures/**',
'**/snapshots/**',
# Putting this exclusion just to get the linter running.
"tools/stronghold/bin/build-check-api-compatibility",
]
command = [
'python3',
Expand Down
18 changes: 10 additions & 8 deletions tools/linter/adapters/exec_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
EXEC: Ensure that source files are not executable.
"""

from __future__ import annotations

import argparse
import json
import logging
import os
import sys
from enum import Enum
from typing import NamedTuple, Optional
from typing import NamedTuple


LINTER_CODE = "EXEC"
Expand All @@ -22,18 +24,18 @@ class LintSeverity(str, Enum):


class LintMessage(NamedTuple):
path: Optional[str]
line: Optional[int]
char: Optional[int]
path: str | None
line: int | None
char: int | None
code: str
severity: LintSeverity
name: str
original: Optional[str]
replacement: Optional[str]
description: Optional[str]
original: str | None
replacement: str | None
description: str | None


def check_file(filename: str) -> Optional[LintMessage]:
def check_file(filename: str) -> LintMessage | None:
is_executable = os.access(filename, os.X_OK)
if is_executable:
return LintMessage(
Expand Down
18 changes: 10 additions & 8 deletions tools/linter/adapters/grep_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,18 @@ def run_command(


def lint_file(
filename: str,
matching_line: str,
allowlist_pattern: str,
replace_pattern: str,
linter_name: str,
error_name: str,
error_description: str,
) -> LintMessage | None:
# matching_line looks like:
# tools/linter/clangtidy_linter.py:13:import foo.bar.baz
split = matching_line.split(":")
filename = split[0]

if allowlist_pattern:
try:
proc = run_command(["grep", "-nEHI", allowlist_pattern, filename])
Expand Down Expand Up @@ -139,8 +144,8 @@ def lint_file(
)

return LintMessage(
path=filename,
line=None,
path=split[0],
line=int(split[1]) if len(split) > 1 else None,
char=None,
code=linter_name,
severity=LintSeverity.ERROR,
Expand Down Expand Up @@ -252,12 +257,9 @@ def main() -> None:
sys.exit(0)

lines = proc.stdout.decode().splitlines()
# matching_line looks like:
# tools/linter/clangtidy_linter.py:13:import foo.bar.baz
files = {line.split(":")[0] for line in lines}
for file in files:
for line in lines:
lint_message = lint_file(
file,
line,
args.allowlist_pattern,
args.replace_pattern,
args.linter_name,
Expand Down
2 changes: 1 addition & 1 deletion tools/torchci/td/get_merge_base_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path
from typing import List

import boto3 # type: ignore
import boto3 # type: ignore[import]
from torchci.clickhouse import query_clickhouse
from torchci.td.utils import list_past_year_shas, run_command

Expand Down

0 comments on commit e83685f

Please sign in to comment.