Skip to content

Commit 5bcbbf5

Browse files
samestepfacebook-github-bot
authored andcommitted
Lint trailing newlines (pytorch#54737)
Summary: *Context:* pytorch#53406 added a lint for trailing whitespace at the ends of lines. However, in order to pass FB-internal lints, that PR also had to normalize the trailing newlines in four of the files it touched. This PR adds an OSS lint to normalize trailing newlines. The changes to the following files (made in 54847d0) are the only manually-written parts of this PR: - `.github/workflows/lint.yml` - `mypy-strict.ini` - `tools/README.md` - `tools/test/test_trailing_newlines.py` - `tools/trailing_newlines.py` I would have liked to make this just a shell one-liner like the other three similar lints, but nothing I could find quite fit the bill. Specifically, all the answers I tried from the following Stack Overflow questions were far too slow (at least a minute and a half to run on this entire repository): - [How to detect file ends in newline?](https://stackoverflow.com/q/38746) - [How do I find files that do not end with a newline/linefeed?](https://stackoverflow.com/q/4631068) - [How to list all files in the Git index without newline at end of file](https://stackoverflow.com/q/27624800) - [Linux - check if there is an empty line at the end of a file [duplicate]](https://stackoverflow.com/q/34943632) - [git ensure newline at end of each file](https://stackoverflow.com/q/57770972) To avoid giving false positives during the few days after this PR is merged, we should probably only merge it after pytorch#54967. Pull Request resolved: pytorch#54737 Test Plan: Running the shell script from the "Ensure correct trailing newlines" step in the `quick-checks` job of `.github/workflows/lint.yml` should print no output and exit in a fraction of a second with a status of 0. That was not the case prior to this PR, as shown by this failing GHA workflow run on an earlier draft of this PR: - https://github.com/pytorch/pytorch/runs/2197446987?check_suite_focus=true In contrast, this run (after correcting the trailing newlines in this PR) succeeded: - https://github.com/pytorch/pytorch/pull/54737/checks?check_run_id=2197553241 To unit-test `tools/trailing_newlines.py` itself (this is run as part of our "Test tools" GitHub Actions workflow): ``` python tools/test/test_trailing_newlines.py ``` Reviewed By: malfet Differential Revision: D27409736 Pulled By: samestep fbshipit-source-id: 46f565227046b39f68349bbd5633105b2d2e9b19
1 parent eafa235 commit 5bcbbf5

File tree

111 files changed

+122
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+122
-132
lines changed

.circleci/windows-jni/include/jni.h

-1
Original file line numberDiff line numberDiff line change
@@ -1129,4 +1129,3 @@ JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved);
11291129
#define JNI_ABORT 2 /* free buffer w/o copying back */
11301130

11311131
#endif /* JNI_H_ */
1132-

.github/workflows/lint.yml

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030
rm -r "shellcheck-${scversion}"
3131
shellcheck --version
3232
.jenkins/run-shellcheck.sh
33+
- name: Ensure correct trailing newlines
34+
run: |
35+
(! git grep -Il '' -- . ':(exclude)**/contrib/**' ':(exclude)third_party' ':(exclude)**.expect' | tools/trailing_newlines.py || (echo "The above files do not have correct trailing newlines; please normalize them"; false))
3336
- name: Ensure no trailing spaces
3437
run: |
3538
(! git grep -I -no ' $' -- . ':(exclude)**/contrib/**' ':(exclude)third_party' || (echo "The above files have trailing spaces; please remove them"; false))

.jenkins/pytorch/perf_test/test_cpu_speed_torch.sh

-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ test_cpu_speed_torch () {
2727
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
2828
run_test test_cpu_speed_torch "$@"
2929
fi
30-

.jenkins/pytorch/perf_test/test_cpu_speed_torch_tensor.sh

-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ test_cpu_speed_torch_tensor () {
2727
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
2828
run_test test_cpu_speed_torch_tensor "$@"
2929
fi
30-

android/test_app/app/src/main/res/layout/activity_main.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
android:background="@android:color/black"
1515
android:textColor="@android:color/white" />
1616

17-
</FrameLayout>
17+
</FrameLayout>

aten/src/ATen/NumericUtils.h

-1
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,3 @@ C10_HOST_DEVICE inline double tan<double>(double x) {
105105
}
106106

107107
} // namespace at
108-

aten/src/ATen/cpu/vec256/vsx/vec256_complex_double_vsx.h

-1
Original file line numberDiff line numberDiff line change
@@ -594,4 +594,3 @@ Vec256<ComplexDbl> inline minimum(
594594
} // namespace
595595
} // namespace vec256
596596
} // namespace at
597-

aten/src/ATen/cpu/vec256/vsx/vsx_helpers.h

-1
Original file line numberDiff line numberDiff line change
@@ -386,4 +386,3 @@ const vfloat64 vd_pi_2 = vfloat64{M_PI / 2.0, 0.0};
386386
} // namespace
387387
} // namespace vec256
388388
} // namespace at
389-

aten/src/ATen/cudnn/cudnn-wrapper.h

-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@
1313

1414
#undef STRINGIFY
1515
#undef STRING
16-

aten/src/ATen/div_rtn.h

-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ static inline T div_rtn(T x, T y) {
88
if ((r!=0) && ((r<0) != (y<0))) --q;
99
return q;
1010
}
11-

aten/src/ATen/native/Cross.h

-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ using cross_fn = void(*)(Tensor&, const Tensor&, const Tensor&, const int64_t d)
1010
DECLARE_DISPATCH(cross_fn, cross_stub);
1111

1212
}} // namespace at::native
13-

aten/src/ATen/native/batch_norm.h

-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ DECLARE_DISPATCH(batch_norm_fn, batch_norm_cpu_inference_contiguous_stub);
1515
} // namespace native
1616

1717
} // namespace at
18-

aten/src/ATen/native/cpu/CrossKernel.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,3 @@ static void cross_kernel_impl(Tensor& result, const Tensor& a, const Tensor& b,
7575
REGISTER_DISPATCH(cross_stub, &cross_kernel_impl);
7676

7777
}} // namespace at::native
78-

aten/src/ATen/native/cuda/CrossKernel.cu

-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ void cross_kernel_impl(Tensor& result, const Tensor& x1, const Tensor& x2, const
1212
REGISTER_DISPATCH(cross_stub, &cross_kernel_impl);
1313

1414
}}
15-

aten/src/ATen/native/cuda/EmbeddingBackwardKernel.cuh

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ Tensor embedding_backward_cuda_kernel(
3333
const Tensor &bag_size = Tensor(),
3434
const Tensor &per_sample_weights = Tensor());
3535

36-
}}
36+
}}

aten/src/ATen/native/quantized/cpu/kernels/README.md

+1-1

aten/src/ATen/native/quantized/cpu/qnnpack/CONTRIBUTING.md

+1-1

aten/src/ATen/test/NamedTensor_test.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,3 @@ TEST(NamedTensorTest, TensorNamesCheckUnique) {
233233
ASSERT_THROW(tensornames.checkUnique("op_name"), c10::Error);
234234
}
235235
}
236-
237-

aten/src/ATen/test/cuda_complex_math_test.cu

-1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ __global__ void CUDA##a##b()
3535
#define C10_DEFINE_TEST(a, b) TEST(a##Host, b)
3636
#define C10_ASSERT_NEAR(a, b, tol) ASSERT_NEAR(a, b, tol)
3737
#include <c10/test/util/complex_math_test_common.h>
38-

aten/src/ATen/test/pow_test.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,3 @@ TEST(PowTest, TestIntegralPow) {
364364
test_inverse(longs);
365365
test_inverse(ints);
366366
}
367-
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
#include <THC/THCTensorMathCompareT.cuh>
22
#include <THC/THCTensor.hpp>
3-
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
#include <THC/THCTensorMathCompareT.cuh>
22
#include <THC/THCTensor.hpp>
3-
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
#include <THC/THCTensorMathCompareT.cuh>
22
#include <THC/THCTensor.hpp>
3-
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
#include <THC/THCTensorMathCompareT.cuh>
22
#include <THC/THCTensor.hpp>
3-
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
#include <THC/THCTensorMathCompareT.cuh>
22
#include <THC/THCTensor.hpp>
3-
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
#include <THC/THCTensorMathCompareT.cuh>
22
#include <THC/THCTensor.hpp>
3-
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
#include <THC/THCTensorMathCompareT.cuh>
22
#include <THC/THCTensor.hpp>
3-
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
#include <THC/THCTensorMathCompareT.cuh>
22
#include <THC/THCTensor.hpp>
3-
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
#include <THC/THCTensorMathCompareT.cuh>
22
#include <THC/THCTensor.hpp>
3-

benchmarks/README.md

-1

benchmarks/fastrnns/README.md

-1

c10/util/Optional.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
#if (!defined(__CUDA_ARCH__) || !defined(CUDA_VERSION) || CUDA_VERSION > 9200)
88
static_assert(C10_IS_TRIVIALLY_COPYABLE(c10::optional<int>), "c10::optional<int> should be trivially copyable");
99
static_assert(C10_IS_TRIVIALLY_COPYABLE(c10::optional<bool>), "c10::optional<bool> should be trivially copyable");
10-
#endif
10+
#endif

c10/util/Unicode.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ std::string u16u8(const std::wstring& wstr) {
4646
return str;
4747
}
4848
#endif
49-
} // namespace c10
49+
} // namespace c10

caffe2/core/common_test.cc

-2
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,3 @@ TEST(CommonTest, TestStod) {
4141
#endif // __ANDROID__
4242

4343
} // namespace caffe2
44-
45-

caffe2/core/nomnigraph/tests/AlgorithmsTest.cc

-1
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,3 @@ TEST(Subgraph, InduceEdgesCycle) {
123123
EXPECT_TRUE(sg.hasEdge(edge));
124124
}
125125
}
126-

caffe2/onnx/device.cc

-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ Device::Device(const std::string &spec) {
1515
device_id = atoi(spec.substr(pos + 1).c_str());
1616
}
1717
}}
18-

caffe2/operators/roi_align_op.cc

-1
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,3 @@ C10_EXPORT_CAFFE2_OP_TO_C10_CPU(
312312
" bool aligned"
313313
") -> Tensor",
314314
caffe2::RoIAlignCPUOp<float>);
315-

caffe2/opt/optimizer.cc

-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,3 @@ NetDef optimize(NetDef net, int level) {
4545

4646
} // namespace opt
4747
} // namespace caffe2
48-

caffe2/python/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ prepend(Caffe2_HIP_PYTHON_SRCS ${CMAKE_CURRENT_SOURCE_DIR} ${Caffe2_HIP_PYTHON_S
3333
set(Caffe2_CPU_PYTHON_SRCS ${Caffe2_CPU_PYTHON_SRCS} PARENT_SCOPE)
3434
set(Caffe2_GPU_PYTHON_SRCS ${Caffe2_GPU_PYTHON_SRCS} PARENT_SCOPE)
3535
set(Caffe2_HIP_PYTHON_SRCS ${Caffe2_HIP_PYTHON_SRCS} PARENT_SCOPE)
36-

caffe2/python/convert.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
## @package workspace
22
# Module caffe2.python.workspace
3-
4-
5-
6-
7-

caffe2/python/fakelowp/init_shared_libs.py

-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
lib = os.environ['OSS_ONNXIFI_LIB']
88
print("Loading ONNXIFI lib: ".format(lib))
99
ctypes.CDLL(lib, ctypes.RTLD_GLOBAL)
10-

caffe2/python/onnx/README.md

-1

caffe2/python/onnx/backend_cpp_rep.py

-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,3 @@ def run(self, inputs):
4949
# single input
5050
output_values = self.__core.run([inputs])
5151
return namedtupledict('Outputs', self.__external_outputs)(*output_values)
52-

caffe2/python/onnx/test_onnxifi.py

-2
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,3 @@ def test_resnet50_core(self):
197197
output_values = [workspace.FetchBlob(name) for name in net_outputs]
198198
Y_trt = namedtupledict('Outputs', net_outputs)(*output_values)
199199
np.testing.assert_allclose(Y_c2, Y_trt, rtol=1e-3)
200-
201-

caffe2/python/onnx/tests/__init__.py

-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
2-
3-
4-

caffe2/python/onnx/tests/test_utils.py

-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ def add_test_case(self, name, test_func):
2727
if hasattr(self, name):
2828
raise ValueError('Duplicated test name: {}'.format(name))
2929
setattr(self, name, test_func)
30-

caffe2/python/operator_test/mean_op_test.py

-1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@ def mean_ref(*args):
6060

6161
if __name__ == "__main__":
6262
unittest.main()
63-

caffe2/python/rnn/__init__.py

-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
2-
3-
4-
5-

caffe2/python/serialized_test/SerializedTestCoverage.md

-1

caffe2/python/trt/data/class_labels.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -997,4 +997,4 @@ earthstar
997997
hen-of-the-woods
998998
bolete
999999
ear
1000-
toilet tissue
1000+
toilet tissue

caffe2/python/trt/test_trt.py

-2
Original file line numberDiff line numberDiff line change
@@ -277,5 +277,3 @@ def test_resnet50_core(self):
277277
output_values = [workspace.FetchBlob(name) for name in net_outputs]
278278
Y_trt = namedtupledict('Outputs', net_outputs)(*output_values)
279279
np.testing.assert_allclose(Y_c2, Y_trt, rtol=1e-3)
280-
281-

caffe2/python/trt/transform.py

-1
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,3 @@ def transform_caffe2_net(
106106
pred_net_cut = caffe2_pb2.NetDef()
107107
pred_net_cut.ParseFromString(pred_net_str)
108108
return pred_net_cut
109-

caffe2/utils/simple_queue_test.cc

-2
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,3 @@ TEST(SimpleQueueDeathTest, CannotAddAfterQueueFinished) {
6868

6969

7070
} // namespace caffe2
71-
72-

cmake/Modules/FindAtlas.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,3 @@ if(ATLAS_FOUND)
4949

5050
message(STATUS "Found Atlas (include: ${Atlas_CBLAS_INCLUDE_DIR}, library: ${Atlas_BLAS_LIBRARY})")
5151
endif(ATLAS_FOUND)
52-

cmake/Modules/FindHiredis.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ if(HIREDIS_FOUND)
2121
message(STATUS "Found Hiredis (include: ${Hiredis_INCLUDE_DIR}, library: ${Hiredis_LIBRARIES})")
2222
mark_as_advanced(Hiredis_INCLUDE_DIR Hiredis_LIBRARIES)
2323
endif()
24-

cmake/Modules/FindNumPy.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,3 @@ if(NUMPY_FOUND)
5555
endif()
5656

5757
caffe_clear_vars(__result __output __error_value __values __ver_check __error_value)
58-

cmake/Modules/FindNuma.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@ if(NUMA_FOUND)
2626
"Found Numa (include: ${Numa_INCLUDE_DIR}, library: ${Numa_LIBRARIES})")
2727
mark_as_advanced(Numa_INCLUDE_DIR Numa_LIBRARIES)
2828
endif()
29-

cmake/Modules/FindOpenBLAS.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,3 @@ MARK_AS_ADVANCED(
6363
OpenBLAS_LIB
6464
OpenBLAS
6565
)
66-

cmake/Modules/FindRocksDB.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ if(ROCKSDB_FOUND)
2121
message(STATUS "Found RocksDB (include: ${RocksDB_INCLUDE_DIR}, library: ${RocksDB_LIBRARIES})")
2222
mark_as_advanced(RocksDB_INCLUDE_DIR RocksDB_LIBRARIES)
2323
endif()
24-

cmake/Modules/FindSnappy.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ if(SNAPPY_FOUND)
2424
SNAPPY_VERION_LINES SNAPPY_MAJOR SNAPPY_MINOR SNAPPY_PATCHLEVEL)
2525
set(Snappy_VERSION "${SNAPPY_MAJOR}.${SNAPPY_MINOR}.${SNAPPY_PATCHLEVEL}")
2626
endif()
27-

cmake/Modules/FindVSX.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
3232
endif()
3333
message("-- </FindVSX>")
3434
endif()
35-

cmake/Modules_CUDA_fix/upstream/FindCUDA/parse_cubin.cmake

-2
Original file line numberDiff line numberDiff line change
@@ -107,5 +107,3 @@ if (NOT "${file_text}" STREQUAL "")
107107
else()
108108
# message("FOUND NO DEPENDS")
109109
endif()
110-
111-

cmake/public/gflags.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,3 @@ if(NOT TARGET gflags)
8181
"Caffe2 or a Caffe2 dependent library, the next warning / error will "
8282
"give you more info.")
8383
endif()
84-

cmake/public/glog.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,3 @@ if(NOT TARGET glog::glog)
6868
"Caffe2 or a Caffe2 dependent library, the next warning / error will "
6969
"give you more info.")
7070
endif()
71-

cmake/public/utils.cmake

-1
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,3 @@ function(torch_set_target_props libname)
484484
set_target_properties(${libname} PROPERTIES STATIC_LIBRARY_FLAGS_DEBUG "/NODEFAULTLIB:${VCOMP_LIB}d")
485485
endif()
486486
endfunction()
487-

docs/caffe2/DOXYGEN.md

-1

docs/cpp/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,3 @@ clean:
2525
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
2626
%: Makefile
2727
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
28-

docs/source/community/persons_of_interest.rst

-3

docs/source/dlpack.rst

-1

docs/source/jit_builtin_functions.rst

-1

docs/source/notes/cpu_threading_torchscript_inference.svg

+1-1

docs/source/notes/randomness.rst

-2

docs/source/special.rst

+1-1

docs/source/storage.rst

-1

0 commit comments

Comments
 (0)