Skip to content

Commit 74e4057

Browse files
committed
tc
1 parent 456e399 commit 74e4057

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

.lintrunner.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,20 @@ include_patterns = [
298298
]
299299
command = [
300300
'python3',
301-
'tools/linter/adapters/pyfmt_linter.py',
301+
'tools/linter/adapters/run_from_link_linter.py',
302+
'--lint-name=pyfmt_linter.py',
302303
'--',
303304
'@{{PATHSFILE}}'
304305
]
305306
init_command = [
306307
'python3',
307-
'tools/linter/adapters/pip_init.py',
308+
'tools/linter/adapters/run_from_link_linter.py',
309+
'--run-init',
310+
'--init-name=pip_init.py',
311+
'--init-link=https://raw.githubusercontent.com/pytorch/test-infra/main/tools/linter/adapters/pip_init.py',
312+
'--lint-name=pyfmt_linter.py',
313+
'--lint-link=https://raw.githubusercontent.com/pytorch/test-infra/main/tools/linter/adapters/pyfmt_linter.py',
314+
'--',
308315
'--dry-run={{DRYRUN}}',
309316
'--no-black-binary',
310317
'black==23.12.1',
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import argparse
2+
from pathlib import Path
3+
import subprocess
4+
import urllib.request
5+
6+
REPO_ROOT = Path(__file__).absolute().parents[3]
7+
8+
def parse_args() -> argparse.Namespace:
9+
parser = argparse.ArgumentParser(
10+
description="Use a formatter in a different repository.",
11+
)
12+
parser.add_argument(
13+
"--run-init",
14+
action="store_true",
15+
)
16+
parser.add_argument(
17+
"--init-name",
18+
)
19+
parser.add_argument(
20+
"--init-link",
21+
)
22+
parser.add_argument(
23+
"--lint-name",
24+
required=True,
25+
)
26+
parser.add_argument(
27+
"--lint-link",
28+
required=True,
29+
)
30+
parser.add_argument('args_for_file', nargs=argparse.REMAINDER)
31+
args = parser.parse_args()
32+
# Skip the first -- if present
33+
if args.args_for_file and args.args_for_file[0] == '--':
34+
args.args_for_file = args.args_for_file[1:]
35+
return args
36+
37+
38+
def download_file(url: str, location: Path) -> bytes:
39+
response = urllib.request.urlopen(url)
40+
content = response.read()
41+
location.write_bytes(content)
42+
return content
43+
44+
45+
def main() -> None:
46+
args = parse_args()
47+
48+
location = REPO_ROOT / ".lintbin" / "from_link" / "adapters"
49+
50+
if args.run_init:
51+
location.mkdir(parents=True, exist_ok=True)
52+
# Save the content to a file named after the name argument
53+
download_file(args.lint_link, location / args.lint_name)
54+
download_file(args.init_link, location / args.init_name)
55+
subprocess.run(["python3", location / args.init_name] + args.args_for_file, check=True)
56+
else:
57+
subprocess.run(
58+
["python3", location / args.lint_name] + args.args_for_file,
59+
check=True,
60+
)
61+
62+
63+
if __name__ == "__main__":
64+
main()

0 commit comments

Comments
 (0)