mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
This changes our lint workflows to use lintrunner for the linters that are currently supported + some random fixes to make things lint clean on master + changes to Makefile to use lintrunner Pull Request resolved: https://github.com/pytorch/pytorch/pull/68460 Approved by: https://github.com/t10-13rocket, https://github.com/seemethere, https://github.com/janeyx99
64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
import json
|
|
import subprocess
|
|
import sys
|
|
|
|
from enum import Enum
|
|
from pathlib import Path
|
|
from typing import NamedTuple, Optional
|
|
|
|
# From: https://docs.github.com/en/rest/reference/checks
|
|
class GitHubAnnotationLevel(str, Enum):
|
|
NOTICE = "notice"
|
|
WARNING = "warning"
|
|
FAILURE = "failure"
|
|
|
|
|
|
class GitHubAnnotation(NamedTuple):
|
|
path: str
|
|
start_line: int
|
|
end_line: int
|
|
start_column: Optional[int]
|
|
end_column: Optional[int]
|
|
annotation_level: GitHubAnnotationLevel
|
|
message: str
|
|
title: Optional[str]
|
|
raw_details: Optional[str]
|
|
|
|
PYTORCH_ROOT = Path(subprocess.check_output(['git', 'rev-parse', '--show-toplevel']).decode('ascii').strip())
|
|
|
|
annotations = []
|
|
for line in sys.stdin:
|
|
lint_message = json.loads(line)
|
|
|
|
path = lint_message.get("path")
|
|
line = lint_message.get("line")
|
|
|
|
|
|
code = lint_message["code"]
|
|
severity = lint_message["severity"]
|
|
name = lint_message["name"]
|
|
description = lint_message.get("description")
|
|
|
|
# These fields are required by the GitHub API, but optional in lintrunner.
|
|
# If they don't exist, just skip.
|
|
if path is None or line is None:
|
|
print(f"No path/line for lint: ({code}) {name}", file=sys.stderr)
|
|
continue
|
|
|
|
# normalize path relative to git root
|
|
path = Path(path).relative_to(PYTORCH_ROOT)
|
|
|
|
annotations.append(GitHubAnnotation(
|
|
path=str(path),
|
|
start_line=int(line),
|
|
end_line=int(line),
|
|
start_column=None,
|
|
end_column=None,
|
|
annotation_level=GitHubAnnotationLevel.FAILURE,
|
|
message=description,
|
|
title=f"({code}) {name}",
|
|
raw_details=None,
|
|
)._asdict())
|
|
|
|
print(json.dumps(annotations), flush=True)
|