Skip to content

Commit 5f75e7b

Browse files
committed
tc
1 parent 755434d commit 5f75e7b

File tree

4 files changed

+361
-0
lines changed

4 files changed

+361
-0
lines changed

.github/workflows/lintrunner.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Lintrunner
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
lintrunner:
15+
name: lintrunner
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout tutorials
19+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
20+
21+
- name: Setup Python
22+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
23+
with:
24+
python-version: '3.12'
25+
26+
- name: Install Lintrunner
27+
run: |
28+
pip install lintrunner==0.12.5
29+
lintrunner init
30+
31+
- name: Run lintrunner on all files - Linux
32+
run: |
33+
set +e
34+
if ! lintrunner -v --force-color --all-files --tee-json=lint.json; then
35+
echo ""
36+
echo -e "\e[1m\e[36mYou can reproduce these results locally by using \`lintrunner -m main\`.\e[0m"
37+
exit 1
38+
fi

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,6 @@ cleanup.sh
127127

128128
# pyspelling
129129
dictionary.dic
130+
131+
# linters
132+
/.lintbin

.lintrunner.toml

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
merge_base_with = "origin/main"
2+
3+
4+
[[linter]]
5+
code = 'SPACES'
6+
include_patterns = ['**']
7+
exclude_patterns = [
8+
"_static/**/*", # Contains some files that should usually not be linted
9+
# All files below this should be checked and either removed from the
10+
# exclusion list by fixing them or have a reason to be excluded.
11+
".github/ISSUE_TEMPLATE/bug-report.yml",
12+
".github/ISSUE_TEMPLATE/feature-request.yml",
13+
".github/scripts/docathon-label-sync.py",
14+
".github/workflows/MonthlyLinkCheck.yml",
15+
".github/workflows/StalePRs.yml",
16+
".github/workflows/link_checkPR.yml",
17+
".github/workflows/spelling.yml",
18+
".jenkins/post_process_notebooks.py",
19+
".lycheeignore",
20+
"CONTRIBUTING.md",
21+
"advanced_source/coding_ddpg.py",
22+
"advanced_source/cpp_autograd.rst",
23+
"advanced_source/cpp_custom_ops.rst",
24+
"advanced_source/generic_join.rst",
25+
"advanced_source/neural_style_tutorial.py",
26+
"advanced_source/pendulum.py",
27+
"advanced_source/privateuseone.rst",
28+
"advanced_source/semi_structured_sparse.py",
29+
"advanced_source/sharding.rst",
30+
"advanced_source/static_quantization_tutorial.rst",
31+
"advanced_source/torch_script_custom_classes/custom_class_project/custom_test.py",
32+
"advanced_source/transformer__timeseries_cpp_tutorial/transformer_timeseries.cpp",
33+
"advanced_source/usb_semisup_learn.py",
34+
"beginner_source/blitz/README.txt",
35+
"beginner_source/blitz/neural_networks_tutorial.py",
36+
"beginner_source/dcgan_faces_tutorial.py",
37+
"beginner_source/ddp_series_fault_tolerance.rst",
38+
"beginner_source/ddp_series_theory.rst",
39+
"beginner_source/examples_nn/polynomial_module.py",
40+
"beginner_source/examples_nn/polynomial_nn.py",
41+
"beginner_source/hta_intro_tutorial.rst",
42+
"beginner_source/hta_trace_diff_tutorial.rst",
43+
"beginner_source/hybrid_frontend/README.txt",
44+
"beginner_source/hybrid_frontend_tutorial.rst",
45+
"beginner_source/hyperparameter_tuning_tutorial.py",
46+
"beginner_source/introyt/README.txt",
47+
"beginner_source/introyt/autogradyt_tutorial.py",
48+
"beginner_source/introyt/captumyt.py",
49+
"beginner_source/introyt/introyt1_tutorial.py",
50+
"beginner_source/introyt/modelsyt_tutorial.py",
51+
"beginner_source/introyt/tensorboardyt_tutorial.py",
52+
"beginner_source/introyt/tensors_deeper_tutorial.py",
53+
"beginner_source/introyt/trainingyt.py",
54+
"beginner_source/knowledge_distillation_tutorial.py",
55+
"beginner_source/nlp/sequence_models_tutorial.py",
56+
"beginner_source/onnx/export_control_flow_model_to_onnx_tutorial.py",
57+
"beginner_source/onnx/onnx_registry_tutorial.py",
58+
"beginner_source/pytorch_with_examples.rst",
59+
"beginner_source/saving_loading_models.py",
60+
"beginner_source/template_tutorial.py",
61+
"beginner_source/transfer_learning_tutorial.py",
62+
"docathon-leaderboard.md",
63+
"intermediate_source/TCPStore_libuv_backend.rst",
64+
"intermediate_source/ax_multiobjective_nas_tutorial.py",
65+
"intermediate_source/compiled_autograd_tutorial.rst",
66+
"intermediate_source/ddp_series_multinode.rst",
67+
"intermediate_source/dqn_with_rnn_tutorial.py",
68+
"intermediate_source/fx_profiling_tutorial.py",
69+
"intermediate_source/inductor_debug_cpu.py",
70+
"intermediate_source/jacobians_hessians.py",
71+
"intermediate_source/optimizer_step_in_backward_tutorial.py",
72+
"intermediate_source/per_sample_grads.py",
73+
"intermediate_source/pruning_tutorial.py",
74+
"intermediate_source/reinforcement_q_learning.py",
75+
"intermediate_source/tensorboard_profiler_tutorial.py",
76+
"intermediate_source/tiatoolbox_tutorial.rst",
77+
"intermediate_source/torch_compile_tutorial.py",
78+
"intermediate_source/transformer_building_blocks.py",
79+
"prototype_source/README.md",
80+
"prototype_source/README.txt",
81+
"prototype_source/backend_config_tutorial.rst",
82+
"prototype_source/gpu_direct_storage.py",
83+
"prototype_source/inductor_cpp_wrapper_tutorial.rst",
84+
"prototype_source/inductor_windows.rst",
85+
"prototype_source/maskedtensor_advanced_semantics.py",
86+
"prototype_source/max_autotune_on_CPU_tutorial.rst",
87+
"prototype_source/vmap_recipe.py",
88+
"recipes_source/README.txt",
89+
"recipes_source/amx.rst",
90+
"recipes_source/compiling_optimizer.rst",
91+
"recipes_source/compiling_optimizer_lr_scheduler.py",
92+
"recipes_source/distributed_optim_torchscript.rst",
93+
"recipes_source/foreach_map.py",
94+
"recipes_source/profile_with_itt.rst",
95+
"recipes_source/recipes/Captum_Recipe.py",
96+
"recipes_source/recipes/benchmark.py",
97+
"recipes_source/recipes/changing_default_device.py",
98+
"recipes_source/recipes/defining_a_neural_network.py",
99+
"recipes_source/recipes/tensorboard_with_pytorch.py",
100+
"recipes_source/recipes/timer_quick_start.py",
101+
"recipes_source/recipes/tuning_guide.py",
102+
"recipes_source/recipes/warmstarting_model_using_parameters_from_a_different_model.py",
103+
"recipes_source/recipes/what_is_state_dict.py",
104+
"recipes_source/torch_compile_caching_tutorial.rst",
105+
"recipes_source/torch_compile_torch_function_modes.py",
106+
"recipes_source/torch_compile_user_defined_triton_kernel_tutorial.py",
107+
"recipes_source/torch_compiler_set_stance_tutorial.py",
108+
"recipes_source/torch_export_aoti_python.py",
109+
"recipes_source/xeon_run_cpu.rst",
110+
"redirects.py",
111+
"tutorial_submission_policy.md",
112+
]
113+
init_command = [
114+
'python3',
115+
'tools/linter/adapters/run_from_link.py',
116+
'--lint-name=grep_linter.py',
117+
'--lint-link=https://raw.githubusercontent.com/pytorch/pytorch/4805a6ead6f1e7f32351056e2602be4e908f69b7/tools/linter/adapters/grep_linter.py',
118+
'--',
119+
'--dry-run={{DRYRUN}}',
120+
]
121+
command = [
122+
'python3',
123+
'tools/linter/adapters/run_from_link.py',
124+
'--run-lint',
125+
'--lint-name=grep_linter.py',
126+
'--',
127+
'--pattern=[[:blank:]]$',
128+
'--linter-name=SPACES',
129+
'--error-name=trailing spaces',
130+
'--replace-pattern=s/[[:blank:]]+$//',
131+
"""--error-description=\
132+
This line has trailing spaces; please remove them.\
133+
""",
134+
'--',
135+
'@{{PATHSFILE}}'
136+
]
137+
138+
[[linter]]
139+
code = 'TABS'
140+
include_patterns = ['**']
141+
exclude_patterns = [
142+
"_static/**/*", # Contains some files that should usually not be linted
143+
".lintrunner.toml", # Ironically needs to contain the tab character to find in other files
144+
# All files below this should be checked and either removed from the
145+
# exclusion list by fixing them or have a reason to be excluded.
146+
"Makefile",
147+
"advanced_source/README.txt",
148+
"advanced_source/cpp_frontend.rst",
149+
"advanced_source/torch_script_custom_ops.rst",
150+
"beginner_source/README.txt",
151+
"beginner_source/basics/tensorqs_tutorial.py",
152+
"beginner_source/blitz/README.txt",
153+
"beginner_source/blitz/tensor_tutorial.py",
154+
"beginner_source/hybrid_frontend/README.txt",
155+
"beginner_source/nlp/README.txt",
156+
"beginner_source/nlp/pytorch_tutorial.py",
157+
"intermediate_source/README.txt",
158+
"intermediate_source/TP_tutorial.rst",
159+
"intermediate_source/inductor_debug_cpu.py",
160+
"prototype_source/README.txt",
161+
"recipes_source/README.txt",
162+
"recipes_source/recipes/README.txt",
163+
"recipes_source/xeon_run_cpu.rst",
164+
]
165+
init_command = [
166+
'python3',
167+
'tools/linter/adapters/run_from_link.py',
168+
'--lint-name=grep_linter.py',
169+
'--lint-link=https://raw.githubusercontent.com/pytorch/pytorch/4805a6ead6f1e7f32351056e2602be4e908f69b7/tools/linter/adapters/grep_linter.py',
170+
'--',
171+
'--dry-run={{DRYRUN}}',
172+
]
173+
command = [
174+
'python3',
175+
'tools/linter/adapters/run_from_link.py',
176+
'--run-lint',
177+
'--lint-name=grep_linter.py',
178+
'--',
179+
# @lint-ignore TXT2
180+
'--pattern= ',
181+
'--linter-name=TABS',
182+
'--error-name=saw some tabs',
183+
'--replace-pattern=s/\t/ /',
184+
"""--error-description=\
185+
This line has tabs; please replace them with spaces.\
186+
""",
187+
'--',
188+
'@{{PATHSFILE}}'
189+
]
190+
191+
[[linter]]
192+
code = 'NEWLINE'
193+
include_patterns=['**']
194+
exclude_patterns=[
195+
"_static/**/*", # Contains some files that should usually not be linted
196+
# All files below this should be checked and either removed from the
197+
# exclusion list by fixing them or have a reason to be excluded.
198+
".github/workflows/StalePRs.yml",
199+
"CONTRIBUTING.md",
200+
"advanced_source/extend_dispatcher.rst",
201+
"advanced_source/neural_style_tutorial.py",
202+
"advanced_source/sharding.rst",
203+
"advanced_source/torch_script_custom_classes/custom_class_project/custom_test.py",
204+
"advanced_source/transformer__timeseries_cpp_tutorial/transformer_timeseries.cpp",
205+
"beginner_source/blitz/README.txt",
206+
"beginner_source/dcgan_faces_tutorial.py",
207+
"beginner_source/hta_trace_diff_tutorial.rst",
208+
"beginner_source/hybrid_frontend/README.txt",
209+
"beginner_source/nlp/pytorch_tutorial.py",
210+
"beginner_source/template_tutorial.py",
211+
"beginner_source/transfer_learning_tutorial.py",
212+
"intermediate_source/custom_function_conv_bn_tutorial.py",
213+
"intermediate_source/custom_function_double_backward_tutorial.rst",
214+
"intermediate_source/forced_alignment_with_torchaudio_tutorial.rst",
215+
"intermediate_source/nlp_from_scratch_index.rst",
216+
"intermediate_source/pipeline_tutorial.rst",
217+
"intermediate_source/tiatoolbox_tutorial.rst",
218+
"recipes_source/README.txt",
219+
"recipes_source/script_optimized.rst",
220+
"recipes_source/torch_compile_caching_configuration_tutorial.rst",
221+
"recipes_source/torch_compile_caching_tutorial.rst",
222+
]
223+
init_command = [
224+
'python3',
225+
'tools/linter/adapters/run_from_link.py',
226+
'--lint-name=newlines_linter.py',
227+
'--lint-link=https://raw.githubusercontent.com/pytorch/pytorch/4805a6ead6f1e7f32351056e2602be4e908f69b7/tools/linter/adapters/newlines_linter.py',
228+
'--',
229+
'--dry-run={{DRYRUN}}',
230+
]
231+
command = [
232+
'python3',
233+
'tools/linter/adapters/run_from_link.py',
234+
'--run-lint',
235+
'--lint-name=newlines_linter.py',
236+
'--',
237+
'@{{PATHSFILE}}',
238+
]
239+
is_formatter = true
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import argparse
2+
import subprocess
3+
import urllib.request
4+
from pathlib import Path
5+
6+
7+
REPO_ROOT = Path(__file__).absolute().parents[3]
8+
9+
10+
def parse_args() -> argparse.Namespace:
11+
parser = argparse.ArgumentParser(
12+
description="Use a formatter in a different repository.",
13+
)
14+
parser.add_argument(
15+
"--run-init",
16+
action="store_true",
17+
help="Run the initialization script specified by --init-name.",
18+
)
19+
parser.add_argument(
20+
"--run-lint",
21+
action="store_true",
22+
help="Run the linting script specified by --lint-name.",
23+
)
24+
parser.add_argument(
25+
"--init-name",
26+
help="Name of the initialization script. This also serves as the filename.",
27+
)
28+
parser.add_argument(
29+
"--init-link",
30+
help="URL to download the initialization script from.",
31+
)
32+
parser.add_argument(
33+
"--lint-name",
34+
help="Name of the linting script. This also serves as the filename.",
35+
)
36+
parser.add_argument(
37+
"--lint-link",
38+
help="URL to download the linting script from.",
39+
)
40+
41+
parser.add_argument("args_for_file", nargs=argparse.REMAINDER)
42+
args = parser.parse_args()
43+
# Skip the first -- if present
44+
if args.args_for_file and args.args_for_file[0] == "--":
45+
args.args_for_file = args.args_for_file[1:]
46+
return args
47+
48+
49+
def download_file(url: str, location: Path) -> bytes:
50+
response = urllib.request.urlopen(url)
51+
content = response.read()
52+
location.write_bytes(content)
53+
return content
54+
55+
56+
def main() -> None:
57+
args = parse_args()
58+
59+
location = REPO_ROOT / ".lintbin" / "from_link" / "adapters"
60+
location.mkdir(parents=True, exist_ok=True)
61+
62+
if args.lint_link:
63+
download_file(args.lint_link, location / args.lint_name)
64+
65+
if args.init_link:
66+
download_file(args.init_link, location / args.init_name)
67+
68+
if args.run_init:
69+
# Save the content to a file named after the name argument
70+
subprocess_args = ["python3", location / args.init_name] + args.args_for_file
71+
subprocess.run(subprocess_args, check=True)
72+
if args.run_lint:
73+
subprocess_args = ["python3", location / args.lint_name] + args.args_for_file
74+
subprocess.run(
75+
subprocess_args,
76+
check=True,
77+
)
78+
79+
80+
if __name__ == "__main__":
81+
main()

0 commit comments

Comments
 (0)