已合并
Add rawthrow_linter and Disable TESTOWNERS check. #35029
Jingwei Huang创建于 5月8日
Add rawthrow_linter and Disable TESTOWNERS check. #35029
已合并
共 3 个文件变更+551-270
| @@ -15,10 +15,10 @@ exclude_patterns = [ | |||
| 15 | 'functorch/docs/**', | 15 | 'functorch/docs/**', |
| 16 | 'functorch/examples/**', | 16 | 'functorch/examples/**', |
| 17 | 'functorch/docs/source/tutorials/**', | 17 | 'functorch/docs/source/tutorials/**', |
| 18 | - 'torch/_inductor/fx_passes/serialized_patterns/**', | 18 | + 'torch_npu/_inductor/fx_passes/serialized_patterns/**', |
| 19 | - 'torch/_inductor/autoheuristic/artifacts/**', | 19 | + 'torch_npu/_inductor/autoheuristic/artifacts/**', |
| 20 | - 'torch/_inductor/kernel/vendored_templates/cutedsl/kernels/**', | 20 | + 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/kernels/**', |
| 21 | - 'torch/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py', | 21 | + 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py', |
| 22 | 'scripts/**', | 22 | 'scripts/**', |
| 23 | 'test/generated_type_hints_smoketest.py', | 23 | 'test/generated_type_hints_smoketest.py', |
| 24 | 'test/test_torchfuzz_repros.py', | 24 | 'test/test_torchfuzz_repros.py', |
| @@ -28,6 +28,8 @@ exclude_patterns = [ | |||
| 28 | 'test/torch_np/numpy_test/**/*.py', | 28 | 'test/torch_np/numpy_test/**/*.py', |
| 29 | # Skip all tests for NPUGraph | 29 | # Skip all tests for NPUGraph |
| 30 | 'third_party/**', | 30 | 'third_party/**', |
| 31 | + 'torch_npu/include/**', | ||
| 32 | + 'torch_npu/lib/**', | ||
| 31 | # NPUGraph logs files | 33 | # NPUGraph logs files |
| 32 | 'torch_npu/_logging/_internal.py', | 34 | 'torch_npu/_logging/_internal.py', |
| 33 | 'torch_npu/csrc/core/npu/NPUGraph.cpp', | 35 | 'torch_npu/csrc/core/npu/NPUGraph.cpp', |
| @@ -84,12 +86,12 @@ include_patterns = [ | |||
| 84 | 'aten/src/ATen/native/Tensor*.cpp', | 86 | 'aten/src/ATen/native/Tensor*.cpp', |
| 85 | 'c10/**/*.h', | 87 | 'c10/**/*.h', |
| 86 | 'c10/**/*.cpp', | 88 | 'c10/**/*.cpp', |
| 87 | - 'torch/csrc/**/*.h', | 89 | + 'torch_npu/csrc/**/*.h', |
| 88 | - 'torch/csrc/**/*.hpp', | 90 | + 'torch_npu/csrc/**/*.hpp', |
| 89 | - 'torch/csrc/**/*.cpp', | 91 | + 'torch_npu/csrc/**/*.cpp', |
| 90 | - 'torch/nativert/**/*.h', | 92 | + 'torch_npu/nativert/**/*.h', |
| 91 | - 'torch/nativert/**/*.cpp', | 93 | + 'torch_npu/nativert/**/*.cpp', |
| 92 | - 'torch/headeronly/**/*.h', | 94 | + 'torch_npu/headeronly/**/*.h', |
| 93 | 'test/cpp/**/*.h', | 95 | 'test/cpp/**/*.h', |
| 94 | 'test/cpp/**/*.cpp', | 96 | 'test/cpp/**/*.cpp', |
| 95 | ] | 97 | ] |
| @@ -98,9 +100,9 @@ exclude_patterns = [ | |||
| 98 | 'aten/src/ATen/native/mps/kernels/Quantized.metal', | 100 | 'aten/src/ATen/native/mps/kernels/Quantized.metal', |
| 99 | 'c10/util/strong_type.h', | 101 | 'c10/util/strong_type.h', |
| 100 | '**/fb/**', | 102 | '**/fb/**', |
| 101 | - 'torch/csrc/inductor/aoti_torch/generated/**', | 103 | + 'torch_npu/csrc/inductor/aoti_torch/generated/**', |
| 102 | - 'torch/csrc/jit/serialization/mobile_bytecode_generated.h', | 104 | + 'torch_npu/csrc/jit/serialization/mobile_bytecode_generated.h', |
| 103 | - 'torch/csrc/utils/pythoncapi_compat.h', | 105 | + 'torch_npu/csrc/utils/pythoncapi_compat.h', |
| 104 | 'aten/src/ATen/dlpack.h', | 106 | 'aten/src/ATen/dlpack.h', |
| 105 | ] | 107 | ] |
| 106 | init_command = [ | 108 | init_command = [ |
| @@ -125,8 +127,8 @@ is_formatter = true | |||
| 125 | [[linter]] | 127 | [[linter]] |
| 126 | code = 'PYREFLY' | 128 | code = 'PYREFLY' |
| 127 | include_patterns = [ | 129 | include_patterns = [ |
| 128 | - 'torch/**/*.py', | 130 | + 'torch_npu/**/*.py', |
| 129 | - 'torch/**/*.pyi', | 131 | + 'torch_npu/**/*.pyi', |
| 130 | 'torchgen/**/*.py', | 132 | 'torchgen/**/*.py', |
| 131 | 'torchgen/**/*.pyi', | 133 | 'torchgen/**/*.pyi', |
| 132 | 'functorch/**/*.py', | 134 | 'functorch/**/*.py', |
| @@ -135,8 +137,10 @@ include_patterns = [ | |||
| 135 | 'tools/**/*.pyi', | 137 | 'tools/**/*.pyi', |
| 136 | ] | 138 | ] |
| 137 | exclude_patterns = [ | 139 | exclude_patterns = [ |
| 138 | - 'torch/_inductor/kernel/vendored_templates/cutedsl/kernels/**', | 140 | + 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/kernels/**', |
| 139 | - 'torch/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py', | 141 | + 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py', |
| 142 | + 'tools/linter/**', | ||
| 143 | + 'tools/setup_helpers/**', | ||
| 140 | ] | 144 | ] |
| 141 | command = [ | 145 | command = [ |
| 142 | 'uv', | 146 | 'uv', |
| @@ -175,20 +179,20 @@ include_patterns = [ | |||
| 175 | 'aten/src/ATen/xpu/**/*.cpp', | 179 | 'aten/src/ATen/xpu/**/*.cpp', |
| 176 | 'c10/**/*.cpp', | 180 | 'c10/**/*.cpp', |
| 177 | 'c10/**/*.h', | 181 | 'c10/**/*.h', |
| 178 | - 'torch/*.h', | 182 | + 'torch_npu/*.h', |
| 179 | - 'torch/_inductor/codegen/aoti_runtime/*.h', | 183 | + 'torch_npu/_inductor/codegen/aoti_runtime/*.h', |
| 180 | - 'torch/_inductor/codegen/aoti_runtime/*.cpp', | 184 | + 'torch_npu/_inductor/codegen/aoti_runtime/*.cpp', |
| 181 | - 'torch/csrc/*.h', | 185 | + 'torch_npu/csrc/*.h', |
| 182 | - 'torch/csrc/*.cpp', | 186 | + 'torch_npu/csrc/*.cpp', |
| 183 | - 'torch/csrc/**/*.h', | 187 | + 'torch_npu/csrc/**/*.h', |
| 184 | - 'torch/csrc/**/*.cpp', | 188 | + 'torch_npu/csrc/**/*.cpp', |
| 185 | - 'torch/csrc/jit/serialization/*.h', | 189 | + 'torch_npu/csrc/jit/serialization/*.h', |
| 186 | - 'torch/csrc/jit/serialization/*.cpp', | 190 | + 'torch_npu/csrc/jit/serialization/*.cpp', |
| 187 | - 'torch/nativert/*.h', | 191 | + 'torch_npu/nativert/*.h', |
| 188 | - 'torch/nativert/*.cpp', | 192 | + 'torch_npu/nativert/*.cpp', |
| 189 | - 'torch/nativert/**/*.h', | 193 | + 'torch_npu/nativert/**/*.h', |
| 190 | - 'torch/nativert/**/*.cpp', | 194 | + 'torch_npu/nativert/**/*.cpp', |
| 191 | - 'torch/headeronly/**/*.h', | 195 | + 'torch_npu/headeronly/**/*.h', |
| 192 | ] | 196 | ] |
| 193 | exclude_patterns = [ | 197 | exclude_patterns = [ |
| 194 | # The negative filters below are to exclude files that include onnx_pb.h or | 198 | # The negative filters below are to exclude files that include onnx_pb.h or |
| @@ -218,17 +222,17 @@ exclude_patterns = [ | |||
| 218 | 'c10/test/**/*.h', | 222 | 'c10/test/**/*.h', |
| 219 | 'c10/test/**/*.cpp', | 223 | 'c10/test/**/*.cpp', |
| 220 | 'third_party/**/*', | 224 | 'third_party/**/*', |
| 221 | - 'torch/csrc/autograd/generated/**', | 225 | + 'torch_npu/csrc/autograd/generated/**', |
| 222 | - 'torch/csrc/distributed/**/*.cu', | 226 | + 'torch_npu/csrc/distributed/**/*.cu', |
| 223 | - 'torch/csrc/distributed/c10d/WinSockUtils.hpp', | 227 | + 'torch_npu/csrc/distributed/c10d/WinSockUtils.hpp', |
| 224 | - 'torch/csrc/distributed/c10d/quantization/quantization_gpu.h', | 228 | + 'torch_npu/csrc/distributed/c10d/quantization/quantization_gpu.h', |
| 225 | - 'torch/csrc/dynamo/eval_frame.h', | 229 | + 'torch_npu/csrc/dynamo/eval_frame.h', |
| 226 | - 'torch/csrc/inductor/aoti_torch/c/shim.h', | 230 | + 'torch_npu/csrc/inductor/aoti_torch/c/shim.h', |
| 227 | - 'torch/csrc/jit/**/*', | 231 | + 'torch_npu/csrc/jit/**/*', |
| 228 | - 'torch/csrc/jit/serialization/mobile_bytecode_generated.h', | 232 | + 'torch_npu/csrc/jit/serialization/mobile_bytecode_generated.h', |
| 229 | - 'torch/csrc/utils/generated_serialization_types.h', | 233 | + 'torch_npu/csrc/utils/generated_serialization_types.h', |
| 230 | - 'torch/csrc/utils/pythoncapi_compat.h', | 234 | + 'torch_npu/csrc/utils/pythoncapi_compat.h', |
| 231 | - 'torch/csrc/inductor/aoti_runtime/sycl_runtime_wrappers.h', | 235 | + 'torch_npu/csrc/inductor/aoti_runtime/sycl_runtime_wrappers.h', |
| 232 | ] | 236 | ] |
| 233 | init_command = [ | 237 | init_command = [ |
| 234 | 'python3', | 238 | 'python3', |
| @@ -268,16 +272,16 @@ include_patterns = [ | |||
| 268 | 'c10/util/llvmMathExtras.h', | 272 | 'c10/util/llvmMathExtras.h', |
| 269 | 'c10/util/overflows.h', | 273 | 'c10/util/overflows.h', |
| 270 | 'c10/util/safe_numerics.h', | 274 | 'c10/util/safe_numerics.h', |
| 271 | - # torch/headeronly headers that must be C++17 compatible | 275 | + # torch_npu/headeronly headers that must be C++17 compatible |
| 272 | - 'torch/headeronly/macros/cmake_macros.h', | 276 | + 'torch_npu/headeronly/macros/cmake_macros.h', |
| 273 | - 'torch/headeronly/macros/Export.h', | 277 | + 'torch_npu/headeronly/macros/Export.h', |
| 274 | - 'torch/headeronly/macros/Macros.h', | 278 | + 'torch_npu/headeronly/macros/Macros.h', |
| 275 | - 'torch/headeronly/util/BFloat16.h', | 279 | + 'torch_npu/headeronly/util/BFloat16.h', |
| 276 | - 'torch/headeronly/util/Half.h', | 280 | + 'torch_npu/headeronly/util/Half.h', |
| 277 | - 'torch/headeronly/util/TypeSafeSignMath.h', | 281 | + 'torch_npu/headeronly/util/TypeSafeSignMath.h', |
| 278 | - 'torch/headeronly/util/bit_cast.h', | 282 | + 'torch_npu/headeronly/util/bit_cast.h', |
| 279 | - 'torch/headeronly/util/complex.h', | 283 | + 'torch_npu/headeronly/util/complex.h', |
| 280 | - 'torch/headeronly/util/floating_point_utils.h', | 284 | + 'torch_npu/headeronly/util/floating_point_utils.h', |
| 281 | ] | 285 | ] |
| 282 | exclude_patterns = [ | 286 | exclude_patterns = [ |
| 283 | '**/fb/**', | 287 | '**/fb/**', |
| @@ -517,7 +521,7 @@ include_patterns = [ | |||
| 517 | ] | 521 | ] |
| 518 | exclude_patterns = [ | 522 | exclude_patterns = [ |
| 519 | 'test_upstream/**', | 523 | 'test_upstream/**', |
| 520 | - 'torch/headeronly/macros/Macros.h', | 524 | + 'torch_npu/headeronly/macros/Macros.h', |
| 521 | ] | 525 | ] |
| 522 | command = [ | 526 | command = [ |
| 523 | 'python3', | 527 | 'python3', |
| @@ -541,7 +545,7 @@ include_patterns = [ | |||
| 541 | ] | 545 | ] |
| 542 | exclude_patterns = [ | 546 | exclude_patterns = [ |
| 543 | 'test_upstream/**', | 547 | 'test_upstream/**', |
| 544 | - 'torch/headeronly/macros/Macros.h', | 548 | + 'torch_npu/headeronly/macros/Macros.h', |
| 545 | ] | 549 | ] |
| 546 | command = [ | 550 | command = [ |
| 547 | 'python3', | 551 | 'python3', |
| @@ -571,7 +575,7 @@ exclude_patterns = [ | |||
| 571 | 'aten/src/ATen/native/quantized/cpu/qnnpack/**', | 575 | 'aten/src/ATen/native/quantized/cpu/qnnpack/**', |
| 572 | 'aten/src/ATen/native/transformers/cuda/mem_eff_attention/**', | 576 | 'aten/src/ATen/native/transformers/cuda/mem_eff_attention/**', |
| 573 | # Standalone code that cannot depend on c10 | 577 | # Standalone code that cannot depend on c10 |
| 574 | - 'torch/csrc/inductor/aoti_runtime/**', | 578 | + 'torch_npu/csrc/inductor/aoti_runtime/**', |
| 575 | # Test files use EXPECT_THROW which is a gtest macro | 579 | # Test files use EXPECT_THROW which is a gtest macro |
| 576 | 'test/cpp/**/*.cpp', | 580 | 'test/cpp/**/*.cpp', |
| 577 | # Python C API bindings use python_error/py::error_already_set for exception propagation | 581 | # Python C API bindings use python_error/py::error_already_set for exception propagation |
| @@ -583,9 +587,7 @@ exclude_patterns = [ | |||
| 583 | ] | 587 | ] |
| 584 | command = [ | 588 | command = [ |
| 585 | 'python3', | 589 | 'python3', |
| 586 | - 'tools/linter/adapters/grep_linter.py', | 590 | + 'tools/linter/adapters/rawthrow_linter.py', |
| 587 | - '--pattern=\bthrow\b', | ||
| 588 | - '--allowlist-pattern=@allow-raw-throw', | ||
| 589 | '--linter-name=RAWTHROW', | 591 | '--linter-name=RAWTHROW', |
| 590 | '--error-name=raw throw statement', | 592 | '--error-name=raw throw statement', |
| 591 | """--error-description=\ | 593 | """--error-description=\ |
| @@ -605,16 +607,16 @@ code = 'INCLUDE' | |||
| 605 | include_patterns = [ | 607 | include_patterns = [ |
| 606 | 'c10/**', | 608 | 'c10/**', |
| 607 | 'aten/**', | 609 | 'aten/**', |
| 608 | - 'torch/csrc/**', | 610 | + 'torch_npu/csrc/**', |
| 609 | - 'torch/nativert/**', | 611 | + 'torch_npu/nativert/**', |
| 610 | ] | 612 | ] |
| 611 | exclude_patterns = [ | 613 | exclude_patterns = [ |
| 612 | 'aten/src/ATen/native/quantized/cpu/qnnpack/**', | 614 | 'aten/src/ATen/native/quantized/cpu/qnnpack/**', |
| 613 | 'aten/src/ATen/native/vulkan/api/vk_mem_alloc.h', | 615 | 'aten/src/ATen/native/vulkan/api/vk_mem_alloc.h', |
| 614 | 'aten/src/ATen/native/vulkan/glsl/**', | 616 | 'aten/src/ATen/native/vulkan/glsl/**', |
| 615 | '**/fb/**', | 617 | '**/fb/**', |
| 616 | - 'torch/csrc/jit/serialization/mobile_bytecode_generated.h', | 618 | + 'torch_npu/csrc/jit/serialization/mobile_bytecode_generated.h', |
| 617 | - 'torch/csrc/utils/pythoncapi_compat.h', | 619 | + 'torch_npu/csrc/utils/pythoncapi_compat.h', |
| 618 | ] | 620 | ] |
| 619 | command = [ | 621 | command = [ |
| 620 | 'python3', | 622 | 'python3', |
| @@ -638,8 +640,8 @@ include_patterns = [ | |||
| 638 | ] | 640 | ] |
| 639 | exclude_patterns = [ | 641 | exclude_patterns = [ |
| 640 | 'test_upstream/**', | 642 | 'test_upstream/**', |
| 641 | - 'torch/csrc/utils/pybind.h', | 643 | + 'torch_npu/csrc/utils/pybind.h', |
| 642 | - 'torch/utils/benchmark/utils/valgrind_wrapper/compat_bindings.cpp', | 644 | + 'torch_npu/utils/benchmark/utils/valgrind_wrapper/compat_bindings.cpp', |
| 643 | 'caffe2/**/*', | 645 | 'caffe2/**/*', |
| 644 | ] | 646 | ] |
| 645 | command = [ | 647 | command = [ |
| @@ -657,7 +659,7 @@ command = [ | |||
| 657 | '--replace-pattern=1,/(#include <pybind11\/)/ s/(#include <pybind11\/)/#include <torch\/csrc\/utils\/pybind.h>\n\1/', | 659 | '--replace-pattern=1,/(#include <pybind11\/)/ s/(#include <pybind11\/)/#include <torch\/csrc\/utils\/pybind.h>\n\1/', |
| 658 | """--error-description=\ | 660 | """--error-description=\ |
| 659 | This #include directly includes pybind11 without also including \ | 661 | This #include directly includes pybind11 without also including \ |
| 660 | - #include <torch/csrc/utils/pybind.h>; this means some important \ | 662 | + #include <torch_npu/csrc/utils/pybind.h>; this means some important \ |
| 661 | specializations may not be included.\ | 663 | specializations may not be included.\ |
| 662 | """, | 664 | """, |
| 663 | '--', | 665 | '--', |
| @@ -667,11 +669,11 @@ command = [ | |||
| 667 | [[linter]] | 669 | [[linter]] |
| 668 | code = 'ERROR_PRONE_ISINSTANCE' | 670 | code = 'ERROR_PRONE_ISINSTANCE' |
| 669 | include_patterns = [ | 671 | include_patterns = [ |
| 670 | - 'torch/_refs/**/*.py', | 672 | + 'torch_npu/_refs/**/*.py', |
| 671 | - 'torch/_prims/**/*.py', | 673 | + 'torch_npu/_prims/**/*.py', |
| 672 | - 'torch/_prims_common/**/*.py', | 674 | + 'torch_npu/_prims_common/**/*.py', |
| 673 | - 'torch/_decomp/**/*.py', | 675 | + 'torch_npu/_decomp/**/*.py', |
| 674 | - 'torch/_meta_registrations.py', | 676 | + 'torch_npu/_meta_registrations.py', |
| 675 | ] | 677 | ] |
| 676 | exclude_patterns = [ | 678 | exclude_patterns = [ |
| 677 | '**/fb/**', | 679 | '**/fb/**', |
| @@ -705,10 +707,10 @@ include_patterns = [ | |||
| 705 | exclude_patterns = [ | 707 | exclude_patterns = [ |
| 706 | 'test_upstream/**', | 708 | 'test_upstream/**', |
| 707 | # The place for all orphan specializations | 709 | # The place for all orphan specializations |
| 708 | - 'torch/csrc/utils/pybind.h', | 710 | + 'torch_npu/csrc/utils/pybind.h', |
| 709 | # These specializations are non-orphan | 711 | # These specializations are non-orphan |
| 710 | - 'torch/csrc/distributed/c10d/init.cpp', | 712 | + 'torch_npu/csrc/distributed/c10d/init.cpp', |
| 711 | - 'torch/csrc/jit/python/pybind.h', | 713 | + 'torch_npu/csrc/jit/python/pybind.h', |
| 712 | 'fb/**', | 714 | 'fb/**', |
| 713 | '**/fb/**', | 715 | '**/fb/**', |
| 714 | # These are safe to exclude as they do not have Python | 716 | # These are safe to exclude as they do not have Python |
| @@ -722,7 +724,7 @@ command = [ | |||
| 722 | '--error-name=pybind11 specialization in non-standard location', | 724 | '--error-name=pybind11 specialization in non-standard location', |
| 723 | """--error-description=\ | 725 | """--error-description=\ |
| 724 | This pybind11 specialization (PYBIND11_DECLARE_HOLDER_TYPE) should \ | 726 | This pybind11 specialization (PYBIND11_DECLARE_HOLDER_TYPE) should \ |
| 725 | - be placed in torch/csrc/utils/pybind.h so that it is guaranteed to be \ | 727 | + be placed in torch_npu/csrc/utils/pybind.h so that it is guaranteed to be \ |
| 726 | included at any site that may potentially make use of it via py::cast. \ | 728 | included at any site that may potentially make use of it via py::cast. \ |
| 727 | If your specialization is in the same header file as the definition \ | 729 | If your specialization is in the same header file as the definition \ |
| 728 | of the holder type, you can ignore this lint by adding your header to \ | 730 | of the holder type, you can ignore this lint by adding your header to \ |
| @@ -766,7 +768,7 @@ include_patterns = ['**'] | |||
| 766 | exclude_patterns = [ | 768 | exclude_patterns = [ |
| 767 | 'test_upstream/**', | 769 | 'test_upstream/**', |
| 768 | 'third_party/**', | 770 | 'third_party/**', |
| 769 | - 'torch/bin/**', | 771 | + 'torch_npu/bin/**', |
| 770 | '**/*.so', | 772 | '**/*.so', |
| 771 | '**/*.py', | 773 | '**/*.py', |
| 772 | '**/*.sh', | 774 | '**/*.sh', |
| @@ -836,8 +838,8 @@ code = 'RAWCUDADEVICE' | |||
| 836 | include_patterns = [ | 838 | include_patterns = [ |
| 837 | 'aten/**', | 839 | 'aten/**', |
| 838 | 'c10/**', | 840 | 'c10/**', |
| 839 | - 'torch/csrc/**', | 841 | + 'torch_npu/csrc/**', |
| 840 | - 'torch/nativert/**', | 842 | + 'torch_npu/nativert/**', |
| 841 | ] | 843 | ] |
| 842 | exclude_patterns = [ | 844 | exclude_patterns = [ |
| 843 | 'aten/src/ATen/cuda/CUDAContext.cpp', | 845 | 'aten/src/ATen/cuda/CUDAContext.cpp', |
| @@ -847,7 +849,7 @@ exclude_patterns = [ | |||
| 847 | 'c10/cuda/CUDAFunctions.cpp', | 849 | 'c10/cuda/CUDAFunctions.cpp', |
| 848 | 'c10/cuda/CUDAGuard.h', | 850 | 'c10/cuda/CUDAGuard.h', |
| 849 | 'c10/cuda/impl/CUDATest.cpp', | 851 | 'c10/cuda/impl/CUDATest.cpp', |
| 850 | - 'torch/csrc/cuda/nccl.cpp', | 852 | + 'torch_npu/csrc/cuda/nccl.cpp', |
| 851 | '**/fb/**', | 853 | '**/fb/**', |
| 852 | ] | 854 | ] |
| 853 | command = [ | 855 | command = [ |
| @@ -875,7 +877,7 @@ exclude_patterns = [ | |||
| 875 | 'tools/**', | 877 | 'tools/**', |
| 876 | 'test/**', | 878 | 'test/**', |
| 877 | 'benchmarks/**', | 879 | 'benchmarks/**', |
| 878 | - 'torch/distributed/run.py', | 880 | + 'torch_npu/distributed/run.py', |
| 879 | 'functorch/benchmarks/**', | 881 | 'functorch/benchmarks/**', |
| 880 | # Grandfathered in | 882 | # Grandfathered in |
| 881 | 'caffe2/**', | 883 | 'caffe2/**', |
| @@ -952,7 +954,7 @@ command = [ | |||
| 952 | [[linter]] | 954 | [[linter]] |
| 953 | code = 'SHELLCHECK' | 955 | code = 'SHELLCHECK' |
| 954 | include_patterns = [ | 956 | include_patterns = [ |
| 955 | - '.ci/pytorch/**/*.sh' | 957 | + '.ci/pytorch_npu/**/*.sh' |
| 956 | ] | 958 | ] |
| 957 | exclude_patterns = [ | 959 | exclude_patterns = [ |
| 958 | '**/fb/**', | 960 | '**/fb/**', |
| @@ -995,23 +997,22 @@ init_command = [ | |||
| 995 | '--output-name=actionlint', | 997 | '--output-name=actionlint', |
| 996 | ] | 998 | ] |
| 997 | 999 | ||
| 998 | -[[linter]] | 1000 | +# [[linter]] |
| 999 | -code = 'TESTOWNERS' | 1001 | +# code = 'TESTOWNERS' |
| 1000 | -include_patterns = [ | 1002 | +# include_patterns = [ |
| 1001 | - 'test/**/test_*.py', | 1003 | +# 'test/**/test_*.py', |
| 1002 | - 'test/**/*_test.py', | 1004 | +# 'test/**/*_test.py', |
| 1003 | -] | 1005 | +# ] |
| 1004 | -exclude_patterns = [ | 1006 | +# exclude_patterns = [ |
| 1005 | - 'test_upstream/**', | 1007 | +# 'test/run_test.py', |
| 1006 | - 'test/run_test.py', | 1008 | +# '**/fb/**', |
| 1007 | - '**/fb/**', | 1009 | +# ] |
| 1008 | -] | 1010 | +# command = [ |
| 1009 | -command = [ | 1011 | +# 'python3', |
| 1010 | - 'python3', | 1012 | +# 'tools/linter/adapters/testowners_linter.py', |
| 1011 | - 'tools/linter/adapters/testowners_linter.py', | 1013 | +# '--', |
| 1012 | - '--', | 1014 | +# '@{{PATHSFILE}}', |
| 1013 | - '@{{PATHSFILE}}', | 1015 | +# ] |
| 1014 | -] | ||
| 1015 | 1016 | ||
| 1016 | [[linter]] | 1017 | [[linter]] |
| 1017 | code = 'TEST_HAS_MAIN' | 1018 | code = 'TEST_HAS_MAIN' |
| @@ -1091,8 +1092,8 @@ code = 'CALL_ONCE' | |||
| 1091 | include_patterns = [ | 1092 | include_patterns = [ |
| 1092 | 'c10/**', | 1093 | 'c10/**', |
| 1093 | 'aten/**', | 1094 | 'aten/**', |
| 1094 | - 'torch/csrc/**', | 1095 | + 'torch_npu/csrc/**', |
| 1095 | - 'torch/nativert/**', | 1096 | + 'torch_npu/nativert/**', |
| 1096 | ] | 1097 | ] |
| 1097 | exclude_patterns = [ | 1098 | exclude_patterns = [ |
| 1098 | 'c10/util/CallOnce.h', | 1099 | 'c10/util/CallOnce.h', |
| @@ -1115,7 +1116,7 @@ command = [ | |||
| 1115 | [[linter]] | 1116 | [[linter]] |
| 1116 | code = 'CONTEXT_DECORATOR' | 1117 | code = 'CONTEXT_DECORATOR' |
| 1117 | include_patterns = [ | 1118 | include_patterns = [ |
| 1118 | - 'torch/**', | 1119 | + 'torch_npu/**', |
| 1119 | ] | 1120 | ] |
| 1120 | command = [ | 1121 | command = [ |
| 1121 | 'python3', | 1122 | 'python3', |
| @@ -1137,8 +1138,8 @@ code = 'ONCE_FLAG' | |||
| 1137 | include_patterns = [ | 1138 | include_patterns = [ |
| 1138 | 'c10/**', | 1139 | 'c10/**', |
| 1139 | 'aten/**', | 1140 | 'aten/**', |
| 1140 | - 'torch/csrc/**', | 1141 | + 'torch_npu/csrc/**', |
| 1141 | - 'torch/nativert/**', | 1142 | + 'torch_npu/nativert/**', |
| 1142 | ] | 1143 | ] |
| 1143 | exclude_patterns = [ | 1144 | exclude_patterns = [ |
| 1144 | '**/fb/**', | 1145 | '**/fb/**', |
| @@ -1212,12 +1213,12 @@ exclude_patterns = [ | |||
| 1212 | '**/fb/**', | 1213 | '**/fb/**', |
| 1213 | 'third_party/**', | 1214 | 'third_party/**', |
| 1214 | 'test/dynamo/cpython/**', | 1215 | 'test/dynamo/cpython/**', |
| 1215 | - 'torch/_vendor/**', | 1216 | + 'torch_npu/_vendor/**', |
| 1216 | - 'torch/_inductor/fx_passes/serialized_patterns/**', | 1217 | + 'torch_npu/_inductor/fx_passes/serialized_patterns/**', |
| 1217 | - 'torch/_inductor/autoheuristic/artifacts/**', | 1218 | + 'torch_npu/_inductor/autoheuristic/artifacts/**', |
| 1218 | - 'torch/_inductor/kernel/vendored_templates/cutedsl/kernels/**', | 1219 | + 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/kernels/**', |
| 1219 | - 'torch/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py', | 1220 | + 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py', |
| 1220 | - 'torch/utils/model_dump/preact.mjs', | 1221 | + 'torch_npu/utils/model_dump/preact.mjs', |
| 1221 | # NPUGraph logs files | 1222 | # NPUGraph logs files |
| 1222 | 'torch_npu/_logging/_internal.py', | 1223 | 'torch_npu/_logging/_internal.py', |
| 1223 | 'torch_npu/csrc/core/npu/NPUGraph.cpp', | 1224 | 'torch_npu/csrc/core/npu/NPUGraph.cpp', |
| @@ -1256,11 +1257,11 @@ exclude_patterns = [ | |||
| 1256 | 'test/dynamo/cpython/**', | 1257 | 'test/dynamo/cpython/**', |
| 1257 | 'third_party/**/*.py', | 1258 | 'third_party/**/*.py', |
| 1258 | 'third_party/**/*.pyi', | 1259 | 'third_party/**/*.pyi', |
| 1259 | - 'torch/_vendor/**', | 1260 | + 'torch_npu/_vendor/**', |
| 1260 | - 'torch/_inductor/fx_passes/serialized_patterns/**', | 1261 | + 'torch_npu/_inductor/fx_passes/serialized_patterns/**', |
| 1261 | - 'torch/_inductor/autoheuristic/artifacts/**', | 1262 | + 'torch_npu/_inductor/autoheuristic/artifacts/**', |
| 1262 | # Needs Python 3.12+ | 1263 | # Needs Python 3.12+ |
| 1263 | - 'torch/testing/_internal/py312_intrinsics.py', | 1264 | + 'torch_npu/testing/_internal/py312_intrinsics.py', |
| 1264 | # These files are all grandfathered in, feel free to remove from this list | 1265 | # These files are all grandfathered in, feel free to remove from this list |
| 1265 | # as necessary | 1266 | # as necessary |
| 1266 | 'test/quantization/__init__.py', | 1267 | 'test/quantization/__init__.py', |
| @@ -1367,145 +1368,145 @@ exclude_patterns = [ | |||
| 1367 | 'test/test_type_promotion.py', | 1368 | 'test/test_type_promotion.py', |
| 1368 | 'test/test_unary_ufuncs.py', | 1369 | 'test/test_unary_ufuncs.py', |
| 1369 | 'test/test_vulkan.py', | 1370 | 'test/test_vulkan.py', |
| 1370 | - 'torch/_awaits/__init__.py', | 1371 | + 'torch_npu/_awaits/__init__.py', |
| 1371 | - 'torch/_export/__init__.py', | 1372 | + 'torch_npu/_export/__init__.py', |
| 1372 | - 'torch/_export/constraints.py', | 1373 | + 'torch_npu/_export/constraints.py', |
| 1373 | - 'torch/_export/db/__init__.py', | 1374 | + 'torch_npu/_export/db/__init__.py', |
| 1374 | - 'torch/_export/db/case.py', | 1375 | + 'torch_npu/_export/db/case.py', |
| 1375 | - 'torch/_export/db/examples/__init__.py', | 1376 | + 'torch_npu/_export/db/examples/__init__.py', |
| 1376 | - 'torch/_export/db/examples/assume_constant_result.py', | 1377 | + 'torch_npu/_export/db/examples/assume_constant_result.py', |
| 1377 | - 'torch/_export/db/examples/autograd_function.py', | 1378 | + 'torch_npu/_export/db/examples/autograd_function.py', |
| 1378 | - 'torch/_export/db/examples/class_method.py', | 1379 | + 'torch_npu/_export/db/examples/class_method.py', |
| 1379 | - 'torch/_export/db/examples/cond_branch_class_method.py', | 1380 | + 'torch_npu/_export/db/examples/cond_branch_class_method.py', |
| 1380 | - 'torch/_export/db/examples/cond_branch_nested_function.py', | 1381 | + 'torch_npu/_export/db/examples/cond_branch_nested_function.py', |
| 1381 | - 'torch/_export/db/examples/cond_branch_nonlocal_variables.py', | 1382 | + 'torch_npu/_export/db/examples/cond_branch_nonlocal_variables.py', |
| 1382 | - 'torch/_export/db/examples/cond_closed_over_variable.py', | 1383 | + 'torch_npu/_export/db/examples/cond_closed_over_variable.py', |
| 1383 | - 'torch/_export/db/examples/cond_operands.py', | 1384 | + 'torch_npu/_export/db/examples/cond_operands.py', |
| 1384 | - 'torch/_export/db/examples/cond_predicate.py', | 1385 | + 'torch_npu/_export/db/examples/cond_predicate.py', |
| 1385 | - 'torch/_export/db/examples/decorator.py', | 1386 | + 'torch_npu/_export/db/examples/decorator.py', |
| 1386 | - 'torch/_export/db/examples/dictionary.py', | 1387 | + 'torch_npu/_export/db/examples/dictionary.py', |
| 1387 | - 'torch/_export/db/examples/dynamic_shape_assert.py', | 1388 | + 'torch_npu/_export/db/examples/dynamic_shape_assert.py', |
| 1388 | - 'torch/_export/db/examples/dynamic_shape_constructor.py', | 1389 | + 'torch_npu/_export/db/examples/dynamic_shape_constructor.py', |
| 1389 | - 'torch/_export/db/examples/dynamic_shape_if_guard.py', | 1390 | + 'torch_npu/_export/db/examples/dynamic_shape_if_guard.py', |
| 1390 | - 'torch/_export/db/examples/dynamic_shape_map.py', | 1391 | + 'torch_npu/_export/db/examples/dynamic_shape_map.py', |
| 1391 | - 'torch/_export/db/examples/dynamic_shape_round.py', | 1392 | + 'torch_npu/_export/db/examples/dynamic_shape_round.py', |
| 1392 | - 'torch/_export/db/examples/dynamic_shape_slicing.py', | 1393 | + 'torch_npu/_export/db/examples/dynamic_shape_slicing.py', |
| 1393 | - 'torch/_export/db/examples/dynamic_shape_view.py', | 1394 | + 'torch_npu/_export/db/examples/dynamic_shape_view.py', |
| 1394 | - 'torch/_export/db/examples/fn_with_kwargs.py', | 1395 | + 'torch_npu/_export/db/examples/fn_with_kwargs.py', |
| 1395 | - 'torch/_export/db/examples/list_contains.py', | 1396 | + 'torch_npu/_export/db/examples/list_contains.py', |
| 1396 | - 'torch/_export/db/examples/list_unpack.py', | 1397 | + 'torch_npu/_export/db/examples/list_unpack.py', |
| 1397 | - 'torch/_export/db/examples/nested_function.py', | 1398 | + 'torch_npu/_export/db/examples/nested_function.py', |
| 1398 | - 'torch/_export/db/examples/null_context_manager.py', | 1399 | + 'torch_npu/_export/db/examples/null_context_manager.py', |
| 1399 | - 'torch/_export/db/examples/pytree_flatten.py', | 1400 | + 'torch_npu/_export/db/examples/pytree_flatten.py', |
| 1400 | - 'torch/_export/db/examples/scalar_output.py', | 1401 | + 'torch_npu/_export/db/examples/scalar_output.py', |
| 1401 | - 'torch/_export/db/examples/specialized_attribute.py', | 1402 | + 'torch_npu/_export/db/examples/specialized_attribute.py', |
| 1402 | - 'torch/_export/db/examples/static_for_loop.py', | 1403 | + 'torch_npu/_export/db/examples/static_for_loop.py', |
| 1403 | - 'torch/_export/db/examples/static_if.py', | 1404 | + 'torch_npu/_export/db/examples/static_if.py', |
| 1404 | - 'torch/_export/db/examples/tensor_setattr.py', | 1405 | + 'torch_npu/_export/db/examples/tensor_setattr.py', |
| 1405 | - 'torch/_export/db/examples/type_reflection_method.py', | 1406 | + 'torch_npu/_export/db/examples/type_reflection_method.py', |
| 1406 | - 'torch/_export/db/gen_example.py', | 1407 | + 'torch_npu/_export/db/gen_example.py', |
| 1407 | - 'torch/_export/db/logging.py', | 1408 | + 'torch_npu/_export/db/logging.py', |
| 1408 | - 'torch/testing/_internal/__init__.py', | 1409 | + 'torch_npu/testing/_internal/__init__.py', |
| 1409 | - 'torch/testing/_internal/autocast_test_lists.py', | 1410 | + 'torch_npu/testing/_internal/autocast_test_lists.py', |
| 1410 | - 'torch/testing/_internal/autograd_function_db.py', | 1411 | + 'torch_npu/testing/_internal/autograd_function_db.py', |
| 1411 | - 'torch/testing/_internal/check_kernel_launches.py', | 1412 | + 'torch_npu/testing/_internal/check_kernel_launches.py', |
| 1412 | - 'torch/testing/_internal/codegen/__init__.py', | 1413 | + 'torch_npu/testing/_internal/codegen/__init__.py', |
| 1413 | - 'torch/testing/_internal/codegen/random_topo_test.py', | 1414 | + 'torch_npu/testing/_internal/codegen/random_topo_test.py', |
| 1414 | - 'torch/testing/_internal/common_cuda.py', | 1415 | + 'torch_npu/testing/_internal/common_cuda.py', |
| 1415 | - 'torch/testing/_internal/common_jit.py', | 1416 | + 'torch_npu/testing/_internal/common_jit.py', |
| 1416 | - 'torch/testing/_internal/common_methods_invocations.py', | 1417 | + 'torch_npu/testing/_internal/common_methods_invocations.py', |
| 1417 | - 'torch/testing/_internal/common_modules.py', | 1418 | + 'torch_npu/testing/_internal/common_modules.py', |
| 1418 | - 'torch/testing/_internal/common_nn.py', | 1419 | + 'torch_npu/testing/_internal/common_nn.py', |
| 1419 | - 'torch/testing/_internal/common_pruning.py', | 1420 | + 'torch_npu/testing/_internal/common_pruning.py', |
| 1420 | - 'torch/testing/_internal/common_quantization.py', | 1421 | + 'torch_npu/testing/_internal/common_quantization.py', |
| 1421 | - 'torch/testing/_internal/common_quantized.py', | 1422 | + 'torch_npu/testing/_internal/common_quantized.py', |
| 1422 | - 'torch/testing/_internal/common_subclass.py', | 1423 | + 'torch_npu/testing/_internal/common_subclass.py', |
| 1423 | - 'torch/testing/_internal/common_utils.py', | 1424 | + 'torch_npu/testing/_internal/common_utils.py', |
| 1424 | - 'torch/testing/_internal/composite_compliance.py', | 1425 | + 'torch_npu/testing/_internal/composite_compliance.py', |
| 1425 | - 'torch/testing/_internal/hop_db.py', | 1426 | + 'torch_npu/testing/_internal/hop_db.py', |
| 1426 | - 'torch/testing/_internal/custom_op_db.py', | 1427 | + 'torch_npu/testing/_internal/custom_op_db.py', |
| 1427 | - 'torch/testing/_internal/data/__init__.py', | 1428 | + 'torch_npu/testing/_internal/data/__init__.py', |
| 1428 | - 'torch/testing/_internal/data/network1.py', | 1429 | + 'torch_npu/testing/_internal/data/network1.py', |
| 1429 | - 'torch/testing/_internal/data/network2.py', | 1430 | + 'torch_npu/testing/_internal/data/network2.py', |
| 1430 | - 'torch/testing/_internal/dist_utils.py', | 1431 | + 'torch_npu/testing/_internal/dist_utils.py', |
| 1431 | - 'torch/testing/_internal/generated/__init__.py', | 1432 | + 'torch_npu/testing/_internal/generated/__init__.py', |
| 1432 | - 'torch/testing/_internal/hypothesis_utils.py', | 1433 | + 'torch_npu/testing/_internal/hypothesis_utils.py', |
| 1433 | - 'torch/testing/_internal/inductor_utils.py', | 1434 | + 'torch_npu/testing/_internal/inductor_utils.py', |
| 1434 | - 'torch/testing/_internal/jit_metaprogramming_utils.py', | 1435 | + 'torch_npu/testing/_internal/jit_metaprogramming_utils.py', |
| 1435 | - 'torch/testing/_internal/jit_utils.py', | 1436 | + 'torch_npu/testing/_internal/jit_utils.py', |
| 1436 | - 'torch/testing/_internal/logging_tensor.py', | 1437 | + 'torch_npu/testing/_internal/logging_tensor.py', |
| 1437 | - 'torch/testing/_internal/logging_utils.py', | 1438 | + 'torch_npu/testing/_internal/logging_utils.py', |
| 1438 | - 'torch/testing/_internal/optests/__init__.py', | 1439 | + 'torch_npu/testing/_internal/optests/__init__.py', |
| 1439 | - 'torch/testing/_internal/optests/aot_autograd.py', | 1440 | + 'torch_npu/testing/_internal/optests/aot_autograd.py', |
| 1440 | - 'torch/testing/_internal/optests/compile_check.py', | 1441 | + 'torch_npu/testing/_internal/optests/compile_check.py', |
| 1441 | - 'torch/testing/_internal/optests/fake_tensor.py', | 1442 | + 'torch_npu/testing/_internal/optests/fake_tensor.py', |
| 1442 | - 'torch/testing/_internal/optests/make_fx.py', | 1443 | + 'torch_npu/testing/_internal/optests/make_fx.py', |
| 1443 | - 'torch/testing/_internal/quantization_torch_package_models.py', | 1444 | + 'torch_npu/testing/_internal/quantization_torch_package_models.py', |
| 1444 | - 'torch/testing/_internal/test_module/__init__.py', | 1445 | + 'torch_npu/testing/_internal/test_module/__init__.py', |
| 1445 | - 'torch/testing/_internal/test_module/future_div.py', | 1446 | + 'torch_npu/testing/_internal/test_module/future_div.py', |
| 1446 | - 'torch/testing/_internal/test_module/no_future_div.py', | 1447 | + 'torch_npu/testing/_internal/test_module/no_future_div.py', |
| 1447 | - 'torch/utils/benchmark/__init__.py', | 1448 | + 'torch_npu/utils/benchmark/__init__.py', |
| 1448 | - 'torch/utils/benchmark/examples/__init__.py', | 1449 | + 'torch_npu/utils/benchmark/examples/__init__.py', |
| 1449 | - 'torch/utils/benchmark/examples/compare.py', | 1450 | + 'torch_npu/utils/benchmark/examples/compare.py', |
| 1450 | - 'torch/utils/benchmark/examples/fuzzer.py', | 1451 | + 'torch_npu/utils/benchmark/examples/fuzzer.py', |
| 1451 | - 'torch/utils/benchmark/examples/op_benchmark.py', | 1452 | + 'torch_npu/utils/benchmark/examples/op_benchmark.py', |
| 1452 | - 'torch/utils/benchmark/examples/simple_timeit.py', | 1453 | + 'torch_npu/utils/benchmark/examples/simple_timeit.py', |
| 1453 | - 'torch/utils/benchmark/examples/sparse/compare.py', | 1454 | + 'torch_npu/utils/benchmark/examples/sparse/compare.py', |
| 1454 | - 'torch/utils/benchmark/examples/sparse/fuzzer.py', | 1455 | + 'torch_npu/utils/benchmark/examples/sparse/fuzzer.py', |
| 1455 | - 'torch/utils/benchmark/examples/sparse/op_benchmark.py', | 1456 | + 'torch_npu/utils/benchmark/examples/sparse/op_benchmark.py', |
| 1456 | - 'torch/utils/benchmark/examples/spectral_ops_fuzz_test.py', | 1457 | + 'torch_npu/utils/benchmark/examples/spectral_ops_fuzz_test.py', |
| 1457 | - 'torch/utils/benchmark/op_fuzzers/__init__.py', | 1458 | + 'torch_npu/utils/benchmark/op_fuzzers/__init__.py', |
| 1458 | - 'torch/utils/benchmark/op_fuzzers/binary.py', | 1459 | + 'torch_npu/utils/benchmark/op_fuzzers/binary.py', |
| 1459 | - 'torch/utils/benchmark/op_fuzzers/sparse_binary.py', | 1460 | + 'torch_npu/utils/benchmark/op_fuzzers/sparse_binary.py', |
| 1460 | - 'torch/utils/benchmark/op_fuzzers/sparse_unary.py', | 1461 | + 'torch_npu/utils/benchmark/op_fuzzers/sparse_unary.py', |
| 1461 | - 'torch/utils/benchmark/op_fuzzers/spectral.py', | 1462 | + 'torch_npu/utils/benchmark/op_fuzzers/spectral.py', |
| 1462 | - 'torch/utils/benchmark/op_fuzzers/unary.py', | 1463 | + 'torch_npu/utils/benchmark/op_fuzzers/unary.py', |
| 1463 | - 'torch/utils/benchmark/utils/__init__.py', | 1464 | + 'torch_npu/utils/benchmark/utils/__init__.py', |
| 1464 | - 'torch/utils/benchmark/utils/_stubs.py', | 1465 | + 'torch_npu/utils/benchmark/utils/_stubs.py', |
| 1465 | - 'torch/utils/benchmark/utils/common.py', | 1466 | + 'torch_npu/utils/benchmark/utils/common.py', |
| 1466 | - 'torch/utils/benchmark/utils/compare.py', | 1467 | + 'torch_npu/utils/benchmark/utils/compare.py', |
| 1467 | - 'torch/utils/benchmark/utils/compile.py', | 1468 | + 'torch_npu/utils/benchmark/utils/compile.py', |
| 1468 | - 'torch/utils/benchmark/utils/cpp_jit.py', | 1469 | + 'torch_npu/utils/benchmark/utils/cpp_jit.py', |
| 1469 | - 'torch/utils/benchmark/utils/fuzzer.py', | 1470 | + 'torch_npu/utils/benchmark/utils/fuzzer.py', |
| 1470 | - 'torch/utils/benchmark/utils/sparse_fuzzer.py', | 1471 | + 'torch_npu/utils/benchmark/utils/sparse_fuzzer.py', |
| 1471 | - 'torch/utils/benchmark/utils/timer.py', | 1472 | + 'torch_npu/utils/benchmark/utils/timer.py', |
| 1472 | - 'torch/utils/benchmark/utils/valgrind_wrapper/__init__.py', | 1473 | + 'torch_npu/utils/benchmark/utils/valgrind_wrapper/__init__.py', |
| 1473 | - 'torch/utils/benchmark/utils/valgrind_wrapper/timer_interface.py', | 1474 | + 'torch_npu/utils/benchmark/utils/valgrind_wrapper/timer_interface.py', |
| 1474 | - 'torch/utils/bundled_inputs.py', | 1475 | + 'torch_npu/utils/bundled_inputs.py', |
| 1475 | - 'torch/utils/checkpoint.py', | 1476 | + 'torch_npu/utils/checkpoint.py', |
| 1476 | - 'torch/utils/collect_env.py', | 1477 | + 'torch_npu/utils/collect_env.py', |
| 1477 | - 'torch/utils/cpp_backtrace.py', | 1478 | + 'torch_npu/utils/cpp_backtrace.py', |
| 1478 | - 'torch/utils/cpp_extension.py', | 1479 | + 'torch_npu/utils/cpp_extension.py', |
| 1479 | - 'torch/utils/dlpack.py', | 1480 | + 'torch_npu/utils/dlpack.py', |
| 1480 | - 'torch/utils/file_baton.py', | 1481 | + 'torch_npu/utils/file_baton.py', |
| 1481 | - 'torch/utils/flop_counter.py', | 1482 | + 'torch_npu/utils/flop_counter.py', |
| 1482 | - 'torch/utils/hipify/__init__.py', | 1483 | + 'torch_npu/utils/hipify/__init__.py', |
| 1483 | - 'torch/utils/hipify/constants.py', | 1484 | + 'torch_npu/utils/hipify/constants.py', |
| 1484 | - 'torch/utils/hipify/cuda_to_hip_mappings.py', | 1485 | + 'torch_npu/utils/hipify/cuda_to_hip_mappings.py', |
| 1485 | - 'torch/utils/hipify/hipify_python.py', | 1486 | + 'torch_npu/utils/hipify/hipify_python.py', |
| 1486 | - 'torch/utils/hipify/version.py', | 1487 | + 'torch_npu/utils/hipify/version.py', |
| 1487 | - 'torch/utils/hooks.py', | 1488 | + 'torch_npu/utils/hooks.py', |
| 1488 | - 'torch/utils/jit/__init__.py', | 1489 | + 'torch_npu/utils/jit/__init__.py', |
| 1489 | - 'torch/utils/jit/log_extract.py', | 1490 | + 'torch_npu/utils/jit/log_extract.py', |
| 1490 | - 'torch/utils/mkldnn.py', | 1491 | + 'torch_npu/utils/mkldnn.py', |
| 1491 | - 'torch/utils/mobile_optimizer.py', | 1492 | + 'torch_npu/utils/mobile_optimizer.py', |
| 1492 | - 'torch/utils/model_dump/__init__.py', | 1493 | + 'torch_npu/utils/model_dump/__init__.py', |
| 1493 | - 'torch/utils/model_dump/__main__.py', | 1494 | + 'torch_npu/utils/model_dump/__main__.py', |
| 1494 | - 'torch/utils/model_zoo.py', | 1495 | + 'torch_npu/utils/model_zoo.py', |
| 1495 | - 'torch/utils/show_pickle.py', | 1496 | + 'torch_npu/utils/show_pickle.py', |
| 1496 | - 'torch/utils/tensorboard/__init__.py', | 1497 | + 'torch_npu/utils/tensorboard/__init__.py', |
| 1497 | - 'torch/utils/tensorboard/_caffe2_graph.py', | 1498 | + 'torch_npu/utils/tensorboard/_caffe2_graph.py', |
| 1498 | - 'torch/utils/tensorboard/_convert_np.py', | 1499 | + 'torch_npu/utils/tensorboard/_convert_np.py', |
| 1499 | - 'torch/utils/tensorboard/_embedding.py', | 1500 | + 'torch_npu/utils/tensorboard/_embedding.py', |
| 1500 | - 'torch/utils/tensorboard/_onnx_graph.py', | 1501 | + 'torch_npu/utils/tensorboard/_onnx_graph.py', |
| 1501 | - 'torch/utils/tensorboard/_proto_graph.py', | 1502 | + 'torch_npu/utils/tensorboard/_proto_graph.py', |
| 1502 | - 'torch/utils/tensorboard/_pytorch_graph.py', | 1503 | + 'torch_npu/utils/tensorboard/_pytorch_graph.py', |
| 1503 | - 'torch/utils/tensorboard/_utils.py', | 1504 | + 'torch_npu/utils/tensorboard/_utils.py', |
| 1504 | - 'torch/utils/tensorboard/summary.py', | 1505 | + 'torch_npu/utils/tensorboard/summary.py', |
| 1505 | - 'torch/utils/tensorboard/writer.py', | 1506 | + 'torch_npu/utils/tensorboard/writer.py', |
| 1506 | - 'torch/utils/throughput_benchmark.py', | 1507 | + 'torch_npu/utils/throughput_benchmark.py', |
| 1507 | - 'torch/utils/viz/__init__.py', | 1508 | + 'torch_npu/utils/viz/__init__.py', |
| 1508 | - 'torch/utils/viz/_cycles.py', | 1509 | + 'torch_npu/utils/viz/_cycles.py', |
| 1509 | # NPUGraph logs files | 1510 | # NPUGraph logs files |
| 1510 | 'torch_npu/_logging/_internal.py', | 1511 | 'torch_npu/_logging/_internal.py', |
| 1511 | 'torch_npu/npu/_graph_tree.py', | 1512 | 'torch_npu/npu/_graph_tree.py', |
| @@ -1617,10 +1618,10 @@ exclude_patterns = [ | |||
| 1617 | 'test_upstream/**', | 1618 | 'test_upstream/**', |
| 1618 | 'caffe2/**', | 1619 | 'caffe2/**', |
| 1619 | 'functorch/docs/**', | 1620 | 'functorch/docs/**', |
| 1620 | - 'torch/_inductor/fx_passes/serialized_patterns/**', | 1621 | + 'torch_npu/_inductor/fx_passes/serialized_patterns/**', |
| 1621 | - 'torch/_inductor/autoheuristic/artifacts/**', | 1622 | + 'torch_npu/_inductor/autoheuristic/artifacts/**', |
| 1622 | - 'torch/_inductor/kernel/vendored_templates/cutedsl/kernels/**', | 1623 | + 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/kernels/**', |
| 1623 | - 'torch/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py', | 1624 | + 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py', |
| 1624 | 'test/dynamo/cpython/**', | 1625 | 'test/dynamo/cpython/**', |
| 1625 | 'test/test_torchfuzz_repros.py', | 1626 | 'test/test_torchfuzz_repros.py', |
| 1626 | 'scripts/**', | 1627 | 'scripts/**', |
| @@ -1666,7 +1667,7 @@ is_formatter = true | |||
| 1666 | [[linter]] | 1667 | [[linter]] |
| 1667 | code = 'META_NO_CREATE_UNBACKED' | 1668 | code = 'META_NO_CREATE_UNBACKED' |
| 1668 | include_patterns = [ | 1669 | include_patterns = [ |
| 1669 | - "torch/_meta_registrations.py" | 1670 | + "torch_npu/_meta_registrations.py" |
| 1670 | ] | 1671 | ] |
| 1671 | command = [ | 1672 | command = [ |
| 1672 | 'python3', | 1673 | 'python3', |
| @@ -1676,8 +1677,8 @@ command = [ | |||
| 1676 | '--error-name=no create_unbacked in meta registrations', | 1677 | '--error-name=no create_unbacked in meta registrations', |
| 1677 | """--error-description=\ | 1678 | """--error-description=\ |
| 1678 | Data-dependent operators should have their meta \ | 1679 | Data-dependent operators should have their meta \ |
| 1679 | - registration in torch/_subclasses/fake_impls.py, \ | 1680 | + registration in torch_npu/_subclasses/fake_impls.py, \ |
| 1680 | - not torch/_meta_registrations.py | 1681 | + not torch_npu/_meta_registrations.py |
| 1681 | """, | 1682 | """, |
| 1682 | '--', | 1683 | '--', |
| 1683 | '@{{PATHSFILE}}' | 1684 | '@{{PATHSFILE}}' |
| @@ -1785,8 +1786,8 @@ command = [ | |||
| 1785 | '@{{PATHSFILE}}' | 1786 | '@{{PATHSFILE}}' |
| 1786 | ] | 1787 | ] |
| 1787 | include_patterns = [ | 1788 | include_patterns = [ |
| 1788 | - "torch/_inductor/**/*.py", | 1789 | + "torch_npu/_inductor/**/*.py", |
| 1789 | - "torch/_functorch/partitioners.py", | 1790 | + "torch_npu/_functorch/partitioners.py", |
| 1790 | ] | 1791 | ] |
| 1791 | is_formatter = true | 1792 | is_formatter = true |
| 1792 | 1793 | ||
| @@ -1803,11 +1804,11 @@ command = [ | |||
| 1803 | '@{{PATHSFILE}}' | 1804 | '@{{PATHSFILE}}' |
| 1804 | ] | 1805 | ] |
| 1805 | include_patterns = [ | 1806 | include_patterns = [ |
| 1806 | - 'torch/_inductor/**/*.py' | 1807 | + 'torch_npu/_inductor/**/*.py' |
| 1807 | ] | 1808 | ] |
| 1808 | exclude_patterns = [ | 1809 | exclude_patterns = [ |
| 1809 | - 'torch/_inductor/kernel/vendored_templates/cutedsl/kernels/**', | 1810 | + 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/kernels/**', |
| 1810 | - 'torch/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py', | 1811 | + 'torch_npu/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py', |
| 1811 | ] | 1812 | ] |
| 1812 | is_formatter = false | 1813 | is_formatter = false |
| 1813 | 1814 | ||
| @@ -1821,7 +1822,7 @@ command = [ | |||
| 1821 | '@{{PATHSFILE}}' | 1822 | '@{{PATHSFILE}}' |
| 1822 | ] | 1823 | ] |
| 1823 | include_patterns = [ | 1824 | include_patterns = [ |
| 1824 | - 'torch/_dynamo/**', | 1825 | + 'torch_npu/_dynamo/**', |
| 1825 | ] | 1826 | ] |
| 1826 | is_formatter = false | 1827 | is_formatter = false |
| 1827 | 1828 | ||
| @@ -1850,14 +1851,14 @@ command = [ | |||
| 1850 | 'tools/linter/adapters/header_only_linter.py', | 1851 | 'tools/linter/adapters/header_only_linter.py', |
| 1851 | ] | 1852 | ] |
| 1852 | include_patterns = [ | 1853 | include_patterns = [ |
| 1853 | - 'torch/header_only_apis.txt', | 1854 | + 'torch_npu/header_only_apis.txt', |
| 1854 | ] | 1855 | ] |
| 1855 | is_formatter = false | 1856 | is_formatter = false |
| 1856 | 1857 | ||
| 1857 | 1858 | ||
| 1858 | [[linter]] | 1859 | [[linter]] |
| 1859 | code = "GB_REGISTRY" | 1860 | code = "GB_REGISTRY" |
| 1860 | -include_patterns = ["torch/_dynamo/**/*.py"] | 1861 | +include_patterns = ["torch_npu/_dynamo/**/*.py"] |
| 1861 | command = [ | 1862 | command = [ |
| 1862 | "python3", | 1863 | "python3", |
| 1863 | "tools/linter/adapters/gb_registry_linter.py", | 1864 | "tools/linter/adapters/gb_registry_linter.py", |
| @@ -1866,8 +1867,8 @@ command = [ | |||
| 1866 | [[linter]] | 1867 | [[linter]] |
| 1867 | code = 'STABLE_SHIM_VERSION' | 1868 | code = 'STABLE_SHIM_VERSION' |
| 1868 | include_patterns = [ | 1869 | include_patterns = [ |
| 1869 | - 'torch/csrc/stable/c/shim.h', | 1870 | + 'torch_npu/csrc/stable/c/shim.h', |
| 1870 | - 'torch/csrc/inductor/aoti_torch/c/shim.h' | 1871 | + 'torch_npu/csrc/inductor/aoti_torch/c/shim.h' |
| 1871 | ] | 1872 | ] |
| 1872 | command = [ | 1873 | command = [ |
| 1873 | 'python3', | 1874 | 'python3', |
| @@ -1879,7 +1880,7 @@ command = [ | |||
| 1879 | [[linter]] | 1880 | [[linter]] |
| 1880 | code = 'STABLE_SHIM_USAGE' | 1881 | code = 'STABLE_SHIM_USAGE' |
| 1881 | include_patterns = [ | 1882 | include_patterns = [ |
| 1882 | - 'torch/csrc/stable/**/*.h', | 1883 | + 'torch_npu/csrc/stable/**/*.h', |
| 1883 | ] | 1884 | ] |
| 1884 | command = [ | 1885 | command = [ |
| 1885 | 'python3', | 1886 | 'python3', |
| @@ -5,7 +5,6 @@ python-version = "3.12" | |||
| 5 | project-includes = [ | 5 | project-includes = [ |
| 6 | "torch", | 6 | "torch", |
| 7 | "caffe2", | 7 | "caffe2", |
| 8 | - "tools", | ||
| 9 | "test/test_bundled_images.py", | 8 | "test/test_bundled_images.py", |
| 10 | "test/test_bundled_inputs.py", | 9 | "test/test_bundled_inputs.py", |
| 11 | "test/test_complex.py", | 10 | "test/test_complex.py", |
| @@ -21,6 +20,7 @@ project-includes = [ | |||
| 21 | "test/test_utils.py", | 20 | "test/test_utils.py", |
| 22 | ] | 21 | ] |
| 23 | project-excludes = [ | 22 | project-excludes = [ |
| 23 | + "tools/**", | ||
| 24 | "torch/_inductor/runtime/triton_heuristics.py", | 24 | "torch/_inductor/runtime/triton_heuristics.py", |
| 25 | "torch/_inductor/runtime/triton_helpers.py", | 25 | "torch/_inductor/runtime/triton_helpers.py", |
| 26 | "torch/_inductor/runtime/halide_helpers.py", | 26 | "torch/_inductor/runtime/halide_helpers.py", |
| @@ -118,6 +118,7 @@ untyped-def-behavior = "check-and-infer-return-any" | |||
| 118 | # In lots of places they define their attributes in `_init` or similar. | 118 | # In lots of places they define their attributes in `_init` or similar. |
| 119 | # https://github.com/pytorch/pytorch/blob/75f3e5a88df60caef27fd9c9df3fd51161378fcc/torch/fx/experimental/symbolic_shapes.py#L3632C1-L3633C1 | 119 | # https://github.com/pytorch/pytorch/blob/75f3e5a88df60caef27fd9c9df3fd51161378fcc/torch/fx/experimental/symbolic_shapes.py#L3632C1-L3633C1 |
| 120 | errors.implicitly-defined-attribute = false | 120 | errors.implicitly-defined-attribute = false |
| 121 | +errors.missing-import = false | ||
| 121 | # In many methods that are overridden, parameters are renamed. | 122 | # In many methods that are overridden, parameters are renamed. |
| 122 | # We can come up with a codemod for this in the future | 123 | # We can come up with a codemod for this in the future |
| 123 | errors.bad-param-name-override = false | 124 | errors.bad-param-name-override = false |
| @@ -0,0 +1,279 @@ | |||
| 1 | +""" | ||
| 2 | +Linter for raw `throw` statements in C++ code. | ||
| 3 | + | ||
| 4 | +Unlike grep_linter.py with a plain regex, this linter performs lightweight | ||
| 5 | +C++ lexical analysis to skip: | ||
| 6 | + - single-line comments (//...) | ||
| 7 | + - block comments (/* ... */) | ||
| 8 | + - string literals ("...") | ||
| 9 | + - character literals ('...') | ||
| 10 | + - raw string literals (R"delim(...)delim") | ||
| 11 | +before searching for the `throw` keyword. This avoids false positives from | ||
| 12 | +`throw` appearing inside log messages, comments, or other non-code contexts. | ||
| 13 | + | ||
| 14 | +The `@allow-raw-throw` allowlist marker on a file is still honored. | ||
| 15 | +""" | ||
| 16 | + | ||
| 17 | +from __future__ import annotations | ||
| 18 | + | ||
| 19 | +import argparse | ||
| 20 | +import json | ||
| 21 | +import logging | ||
| 22 | +import os | ||
| 23 | +import re | ||
| 24 | +import sys | ||
| 25 | +from enum import Enum | ||
| 26 | +from typing import NamedTuple | ||
| 27 | + | ||
| 28 | + | ||
| 29 | +MAX_FILE_SIZE: int = 1024 * 1024 * 1024 # 1GB | ||
| 30 | +MAX_MATCHES_PER_FILE: int = 100 | ||
| 31 | + | ||
| 32 | + | ||
| 33 | +class LintSeverity(str, Enum): | ||
| 34 | + ERROR = "error" | ||
| 35 | + WARNING = "warning" | ||
| 36 | + ADVICE = "advice" | ||
| 37 | + DISABLED = "disabled" | ||
| 38 | + | ||
| 39 | + | ||
| 40 | +LINTER_NAME: str = "" | ||
| 41 | +ERROR_DESCRIPTION: str | None = None | ||
| 42 | + | ||
| 43 | + | ||
| 44 | +class LintMessage(NamedTuple): | ||
| 45 | + path: str | None | ||
| 46 | + line: int | None | ||
| 47 | + char: int | None | ||
| 48 | + code: str | ||
| 49 | + severity: LintSeverity | ||
| 50 | + name: str | ||
| 51 | + original: str | None | ||
| 52 | + replacement: str | None | ||
| 53 | + description: str | None | ||
| 54 | + | ||
| 55 | + | ||
| 56 | +def print_lint_message( | ||
| 57 | + name: str, | ||
| 58 | + severity: LintSeverity = LintSeverity.ERROR, | ||
| 59 | + path: str | None = None, | ||
| 60 | + line: int | None = None, | ||
| 61 | + description: str | None = None, | ||
| 62 | +) -> None: | ||
| 63 | + msg = LintMessage( | ||
| 64 | + path=path, | ||
| 65 | + line=line, | ||
| 66 | + char=None, | ||
| 67 | + code=LINTER_NAME, | ||
| 68 | + severity=severity, | ||
| 69 | + name=name, | ||
| 70 | + original=None, | ||
| 71 | + replacement=None, | ||
| 72 | + description=description or ERROR_DESCRIPTION, | ||
| 73 | + ) | ||
| 74 | + print(json.dumps(msg._asdict()), flush=True) | ||
| 75 | + | ||
| 76 | + | ||
| 77 | +THROW_RE = re.compile(r"\bthrow\b") | ||
| 78 | +ALLOW_RE = re.compile(r"@allow-raw-throw") | ||
| 79 | + | ||
| 80 | + | ||
| 81 | +def strip_cpp_noncode(source: str) -> str: | ||
| 82 | + """ | ||
| 83 | + Return a copy of `source` with comments and string/char literals replaced | ||
| 84 | + by spaces (preserving line numbers and total length, so line offsets are | ||
| 85 | + accurate for the caller). | ||
| 86 | + """ | ||
| 87 | + out: list[str] = [] | ||
| 88 | + i = 0 | ||
| 89 | + n = len(source) | ||
| 90 | + | ||
| 91 | + def blank(span: str) -> str: | ||
| 92 | + # Preserve newlines so line numbers line up; blank out everything else. | ||
| 93 | + return "".join(c if c == "\n" else " " for c in span) | ||
| 94 | + | ||
| 95 | + while i < n: | ||
| 96 | + c = source[i] | ||
| 97 | + nxt = source[i + 1] if i + 1 < n else "" | ||
| 98 | + | ||
| 99 | + # Raw string literal: R"delim(...)delim" | ||
| 100 | + # Allow a u8/u/U/L prefix before R. | ||
| 101 | + if c == "R" and nxt == '"': | ||
| 102 | + prefix_end = i + 2 | ||
| 103 | + delim_end = source.find("(", prefix_end) | ||
| 104 | + if delim_end != -1: | ||
| 105 | + delim = source[prefix_end:delim_end] | ||
| 106 | + close = f'){delim}"' | ||
| 107 | + close_idx = source.find(close, delim_end + 1) | ||
| 108 | + if close_idx != -1: | ||
| 109 | + end = close_idx + len(close) | ||
| 110 | + out.append(blank(source[i:end])) | ||
| 111 | + i = end | ||
| 112 | + continue | ||
| 113 | + # Malformed; fall through to treat as regular char. | ||
| 114 | + | ||
| 115 | + # Optional prefix (u8, u, U, L) before R"..." or "..." | ||
| 116 | + if c in ("u", "U", "L") and i + 1 < n: | ||
| 117 | + # Check u8R"..." / uR"..." / u"..." etc. | ||
| 118 | + j = i + 1 | ||
| 119 | + if c == "u" and source[j : j + 1] == "8": | ||
| 120 | + j += 1 | ||
| 121 | + if source[j : j + 1] == "R" and source[j + 1 : j + 2] == '"': | ||
| 122 | + # Let the R-string branch handle it on the next iteration by | ||
| 123 | + # fast-forwarding i to j. | ||
| 124 | + out.append(source[i:j]) | ||
| 125 | + i = j | ||
| 126 | + continue | ||
| 127 | + if source[j : j + 1] == '"': | ||
| 128 | + out.append(source[i:j]) | ||
| 129 | + i = j | ||
| 130 | + continue | ||
| 131 | + | ||
| 132 | + # Block comment /* ... */ | ||
| 133 | + if c == "/" and nxt == "*": | ||
| 134 | + end = source.find("*/", i + 2) | ||
| 135 | + end = n if end == -1 else end + 2 | ||
| 136 | + out.append(blank(source[i:end])) | ||
| 137 | + i = end | ||
| 138 | + continue | ||
| 139 | + | ||
| 140 | + # Line comment // ... | ||
| 141 | + if c == "/" and nxt == "/": | ||
| 142 | + end = source.find("\n", i + 2) | ||
| 143 | + end = n if end == -1 else end | ||
| 144 | + out.append(blank(source[i:end])) | ||
| 145 | + i = end | ||
| 146 | + continue | ||
| 147 | + | ||
| 148 | + # String literal "..." | ||
| 149 | + if c == '"': | ||
| 150 | + j = i + 1 | ||
| 151 | + while j < n: | ||
| 152 | + ch = source[j] | ||
| 153 | + if ch == "\\" and j + 1 < n: | ||
| 154 | + j += 2 | ||
| 155 | + continue | ||
| 156 | + if ch == '"': | ||
| 157 | + j += 1 | ||
| 158 | + break | ||
| 159 | + if ch == "\n": | ||
| 160 | + # Unterminated string on this line; stop to avoid runaway. | ||
| 161 | + break | ||
| 162 | + j += 1 | ||
| 163 | + out.append(blank(source[i:j])) | ||
| 164 | + i = j | ||
| 165 | + continue | ||
| 166 | + | ||
| 167 | + # Char literal '...' | ||
| 168 | + if c == "'": | ||
| 169 | + j = i + 1 | ||
| 170 | + while j < n: | ||
| 171 | + ch = source[j] | ||
| 172 | + if ch == "\\" and j + 1 < n: | ||
| 173 | + j += 2 | ||
| 174 | + continue | ||
| 175 | + if ch == "'": | ||
| 176 | + j += 1 | ||
| 177 | + break | ||
| 178 | + if ch == "\n": | ||
| 179 | + break | ||
| 180 | + j += 1 | ||
| 181 | + out.append(blank(source[i:j])) | ||
| 182 | + i = j | ||
| 183 | + continue | ||
| 184 | + | ||
| 185 | + out.append(c) | ||
| 186 | + i += 1 | ||
| 187 | + | ||
| 188 | + return "".join(out) | ||
| 189 | + | ||
| 190 | + | ||
| 191 | +def lint_file(filename: str, error_name: str) -> None: | ||
| 192 | + try: | ||
| 193 | + with open(filename, encoding="utf-8", errors="replace") as f: | ||
| 194 | + source = f.read() | ||
| 195 | + except OSError as err: | ||
| 196 | + print_lint_message( | ||
| 197 | + path=filename, | ||
| 198 | + name="file-access-error", | ||
| 199 | + description=f"Failed to read file: {err}", | ||
| 200 | + ) | ||
| 201 | + return | ||
| 202 | + | ||
| 203 | + # Respect file-level allowlist. | ||
| 204 | + if ALLOW_RE.search(source): | ||
| 205 | + return | ||
| 206 | + | ||
| 207 | + stripped = strip_cpp_noncode(source) | ||
| 208 | + | ||
| 209 | + matches: list[int] = [] | ||
| 210 | + for m in THROW_RE.finditer(stripped): | ||
| 211 | + line_no = stripped.count("\n", 0, m.start()) + 1 | ||
| 212 | + matches.append(line_no) | ||
| 213 | + if len(matches) >= MAX_MATCHES_PER_FILE + 1: | ||
| 214 | + break | ||
| 215 | + | ||
| 216 | + report = matches[:MAX_MATCHES_PER_FILE] | ||
| 217 | + for line_no in report: | ||
| 218 | + print_lint_message(path=filename, line=line_no, name=error_name) | ||
| 219 | + | ||
| 220 | + if len(matches) > MAX_MATCHES_PER_FILE: | ||
| 221 | + print_lint_message( | ||
| 222 | + path=filename, | ||
| 223 | + name="too-many-matches", | ||
| 224 | + description=( | ||
| 225 | + f"File has more than {MAX_MATCHES_PER_FILE} matches, " | ||
| 226 | + "only showing the first ones" | ||
| 227 | + ), | ||
| 228 | + ) | ||
| 229 | + | ||
| 230 | + | ||
| 231 | +def main() -> None: | ||
| 232 | + parser = argparse.ArgumentParser( | ||
| 233 | + description="Raw `throw` linter for C++ sources.", | ||
| 234 | + fromfile_prefix_chars="@", | ||
| 235 | + ) | ||
| 236 | + parser.add_argument("--linter-name", required=True) | ||
| 237 | + parser.add_argument("--error-name", required=True) | ||
| 238 | + parser.add_argument("--error-description", required=True) | ||
| 239 | + parser.add_argument("--verbose", action="store_true") | ||
| 240 | + parser.add_argument("filenames", nargs="+") | ||
| 241 | + args = parser.parse_args() | ||
| 242 | + | ||
| 243 | + global LINTER_NAME, ERROR_DESCRIPTION | ||
| 244 | + LINTER_NAME = args.linter_name | ||
| 245 | + ERROR_DESCRIPTION = args.error_description | ||
| 246 | + | ||
| 247 | + logging.basicConfig( | ||
| 248 | + format="<%(threadName)s:%(levelname)s> %(message)s", | ||
| 249 | + level=logging.DEBUG if args.verbose else logging.INFO, | ||
| 250 | + stream=sys.stderr, | ||
| 251 | + ) | ||
| 252 | + | ||
| 253 | + for filename in args.filenames: | ||
| 254 | + try: | ||
| 255 | + size = os.path.getsize(filename) | ||
| 256 | + except OSError as err: | ||
| 257 | + print_lint_message( | ||
| 258 | + path=filename, | ||
| 259 | + name="file-access-error", | ||
| 260 | + description=f"Failed to stat file: {err}", | ||
| 261 | + ) | ||
| 262 | + continue | ||
| 263 | + | ||
| 264 | + if size > MAX_FILE_SIZE: | ||
| 265 | + print_lint_message( | ||
| 266 | + path=filename, | ||
| 267 | + severity=LintSeverity.WARNING, | ||
| 268 | + name="file-too-large", | ||
| 269 | + description=( | ||
| 270 | + f"File size ({size} bytes) exceeds {MAX_FILE_SIZE} bytes, skipping" | ||
| 271 | + ), | ||
| 272 | + ) | ||
| 273 | + continue | ||
| 274 | + | ||
| 275 | + lint_file(filename, args.error_name) | ||
| 276 | + | ||
| 277 | + | ||
| 278 | +if __name__ == "__main__": | ||
| 279 | + main() | ||