mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Lint trailing newlines (#54737)
Summary: *Context:* https://github.com/pytorch/pytorch/issues/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 54847d0adb9be71be4979cead3d9d4c02160e4cd) 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 https://github.com/pytorch/pytorch/issues/54967. Pull Request resolved: https://github.com/pytorch/pytorch/pull/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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
eafa235582
commit
5bcbbf5373
@ -1129,4 +1129,3 @@ JNIEXPORT void JNI_OnUnload(JavaVM* vm, void* reserved);
|
||||
#define JNI_ABORT 2 /* free buffer w/o copying back */
|
||||
|
||||
#endif /* JNI_H_ */
|
||||
|
||||
|
3
.github/workflows/lint.yml
vendored
3
.github/workflows/lint.yml
vendored
@ -30,6 +30,9 @@ jobs:
|
||||
rm -r "shellcheck-${scversion}"
|
||||
shellcheck --version
|
||||
.jenkins/run-shellcheck.sh
|
||||
- name: Ensure correct trailing newlines
|
||||
run: |
|
||||
(! 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))
|
||||
- name: Ensure no trailing spaces
|
||||
run: |
|
||||
(! git grep -I -no ' $' -- . ':(exclude)**/contrib/**' ':(exclude)third_party' || (echo "The above files have trailing spaces; please remove them"; false))
|
||||
|
@ -27,4 +27,3 @@ test_cpu_speed_torch () {
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
run_test test_cpu_speed_torch "$@"
|
||||
fi
|
||||
|
||||
|
@ -27,4 +27,3 @@ test_cpu_speed_torch_tensor () {
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
run_test test_cpu_speed_torch_tensor "$@"
|
||||
fi
|
||||
|
||||
|
@ -105,4 +105,3 @@ C10_HOST_DEVICE inline double tan<double>(double x) {
|
||||
}
|
||||
|
||||
} // namespace at
|
||||
|
||||
|
@ -594,4 +594,3 @@ Vec256<ComplexDbl> inline minimum(
|
||||
} // namespace
|
||||
} // namespace vec256
|
||||
} // namespace at
|
||||
|
||||
|
@ -386,4 +386,3 @@ const vfloat64 vd_pi_2 = vfloat64{M_PI / 2.0, 0.0};
|
||||
} // namespace
|
||||
} // namespace vec256
|
||||
} // namespace at
|
||||
|
||||
|
@ -13,4 +13,3 @@
|
||||
|
||||
#undef STRINGIFY
|
||||
#undef STRING
|
||||
|
||||
|
@ -8,4 +8,3 @@ static inline T div_rtn(T x, T y) {
|
||||
if ((r!=0) && ((r<0) != (y<0))) --q;
|
||||
return q;
|
||||
}
|
||||
|
||||
|
@ -10,4 +10,3 @@ using cross_fn = void(*)(Tensor&, const Tensor&, const Tensor&, const int64_t d)
|
||||
DECLARE_DISPATCH(cross_fn, cross_stub);
|
||||
|
||||
}} // namespace at::native
|
||||
|
||||
|
@ -15,4 +15,3 @@ DECLARE_DISPATCH(batch_norm_fn, batch_norm_cpu_inference_contiguous_stub);
|
||||
} // namespace native
|
||||
|
||||
} // namespace at
|
||||
|
||||
|
@ -75,4 +75,3 @@ static void cross_kernel_impl(Tensor& result, const Tensor& a, const Tensor& b,
|
||||
REGISTER_DISPATCH(cross_stub, &cross_kernel_impl);
|
||||
|
||||
}} // namespace at::native
|
||||
|
||||
|
@ -12,4 +12,3 @@ void cross_kernel_impl(Tensor& result, const Tensor& x1, const Tensor& x2, const
|
||||
REGISTER_DISPATCH(cross_stub, &cross_kernel_impl);
|
||||
|
||||
}}
|
||||
|
||||
|
@ -233,5 +233,3 @@ TEST(NamedTensorTest, TensorNamesCheckUnique) {
|
||||
ASSERT_THROW(tensornames.checkUnique("op_name"), c10::Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,4 +35,3 @@ __global__ void CUDA##a##b()
|
||||
#define C10_DEFINE_TEST(a, b) TEST(a##Host, b)
|
||||
#define C10_ASSERT_NEAR(a, b, tol) ASSERT_NEAR(a, b, tol)
|
||||
#include <c10/test/util/complex_math_test_common.h>
|
||||
|
||||
|
@ -364,4 +364,3 @@ TEST(PowTest, TestIntegralPow) {
|
||||
test_inverse(longs);
|
||||
test_inverse(ints);
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,2 @@
|
||||
#include <THC/THCTensorMathCompareT.cuh>
|
||||
#include <THC/THCTensor.hpp>
|
||||
|
||||
|
@ -1,3 +1,2 @@
|
||||
#include <THC/THCTensorMathCompareT.cuh>
|
||||
#include <THC/THCTensor.hpp>
|
||||
|
||||
|
@ -1,3 +1,2 @@
|
||||
#include <THC/THCTensorMathCompareT.cuh>
|
||||
#include <THC/THCTensor.hpp>
|
||||
|
||||
|
@ -1,3 +1,2 @@
|
||||
#include <THC/THCTensorMathCompareT.cuh>
|
||||
#include <THC/THCTensor.hpp>
|
||||
|
||||
|
@ -1,3 +1,2 @@
|
||||
#include <THC/THCTensorMathCompareT.cuh>
|
||||
#include <THC/THCTensor.hpp>
|
||||
|
||||
|
@ -1,3 +1,2 @@
|
||||
#include <THC/THCTensorMathCompareT.cuh>
|
||||
#include <THC/THCTensor.hpp>
|
||||
|
||||
|
@ -1,3 +1,2 @@
|
||||
#include <THC/THCTensorMathCompareT.cuh>
|
||||
#include <THC/THCTensor.hpp>
|
||||
|
||||
|
@ -1,3 +1,2 @@
|
||||
#include <THC/THCTensorMathCompareT.cuh>
|
||||
#include <THC/THCTensor.hpp>
|
||||
|
||||
|
@ -1,3 +1,2 @@
|
||||
#include <THC/THCTensorMathCompareT.cuh>
|
||||
#include <THC/THCTensor.hpp>
|
||||
|
||||
|
@ -26,4 +26,3 @@ python -c "import torch; print(torch.__version__)"
|
||||
Please refer to each subfolder to discover each benchmark suite
|
||||
|
||||
* [Fast RNNs benchmarks](fastrnns/README.md)
|
||||
|
||||
|
@ -39,4 +39,3 @@ you can also specify the models to generate nvprof files separately:
|
||||
|
||||
Use Linux for the most accurate timing. A lot of these tests only run
|
||||
on CUDA.
|
||||
|
||||
|
@ -41,5 +41,3 @@ TEST(CommonTest, TestStod) {
|
||||
#endif // __ANDROID__
|
||||
|
||||
} // namespace caffe2
|
||||
|
||||
|
||||
|
@ -123,4 +123,3 @@ TEST(Subgraph, InduceEdgesCycle) {
|
||||
EXPECT_TRUE(sg.hasEdge(edge));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,4 +15,3 @@ Device::Device(const std::string &spec) {
|
||||
device_id = atoi(spec.substr(pos + 1).c_str());
|
||||
}
|
||||
}}
|
||||
|
||||
|
@ -312,4 +312,3 @@ C10_EXPORT_CAFFE2_OP_TO_C10_CPU(
|
||||
" bool aligned"
|
||||
") -> Tensor",
|
||||
caffe2::RoIAlignCPUOp<float>);
|
||||
|
||||
|
@ -45,4 +45,3 @@ NetDef optimize(NetDef net, int level) {
|
||||
|
||||
} // namespace opt
|
||||
} // namespace caffe2
|
||||
|
||||
|
@ -33,4 +33,3 @@ prepend(Caffe2_HIP_PYTHON_SRCS ${CMAKE_CURRENT_SOURCE_DIR} ${Caffe2_HIP_PYTHON_S
|
||||
set(Caffe2_CPU_PYTHON_SRCS ${Caffe2_CPU_PYTHON_SRCS} PARENT_SCOPE)
|
||||
set(Caffe2_GPU_PYTHON_SRCS ${Caffe2_GPU_PYTHON_SRCS} PARENT_SCOPE)
|
||||
set(Caffe2_HIP_PYTHON_SRCS ${Caffe2_HIP_PYTHON_SRCS} PARENT_SCOPE)
|
||||
|
||||
|
@ -1,7 +1,2 @@
|
||||
## @package workspace
|
||||
# Module caffe2.python.workspace
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -7,4 +7,3 @@ if 'OSS_ONNXIFI_LIB' in os.environ:
|
||||
lib = os.environ['OSS_ONNXIFI_LIB']
|
||||
print("Loading ONNXIFI lib: ".format(lib))
|
||||
ctypes.CDLL(lib, ctypes.RTLD_GLOBAL)
|
||||
|
||||
|
@ -51,4 +51,3 @@ pip install -e caffe2/
|
||||
# License
|
||||
|
||||
[MIT License](LICENSE)
|
||||
|
||||
|
@ -49,4 +49,3 @@ class Caffe2CppRep(BackendRep):
|
||||
# single input
|
||||
output_values = self.__core.run([inputs])
|
||||
return namedtupledict('Outputs', self.__external_outputs)(*output_values)
|
||||
|
||||
|
@ -197,5 +197,3 @@ class OnnxifiTransformTest(TestCase):
|
||||
output_values = [workspace.FetchBlob(name) for name in net_outputs]
|
||||
Y_trt = namedtupledict('Outputs', net_outputs)(*output_values)
|
||||
np.testing.assert_allclose(Y_c2, Y_trt, rtol=1e-3)
|
||||
|
||||
|
||||
|
@ -1,4 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -27,4 +27,3 @@ class TestCase(unittest.TestCase):
|
||||
if hasattr(self, name):
|
||||
raise ValueError('Duplicated test name: {}'.format(name))
|
||||
setattr(self, name, test_func)
|
||||
|
||||
|
@ -60,4 +60,3 @@ class TestMean(serial.SerializedTestCase):
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
@ -1,5 +0,0 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -876,4 +876,3 @@ Serialized tests have covered 220/852 (25.8%) operators
|
||||
* LengthsSumFakeFp16
|
||||
* SparseLengthsMax
|
||||
</details>
|
||||
|
||||
|
@ -277,5 +277,3 @@ class TensorRTTransformTest(TestCase):
|
||||
output_values = [workspace.FetchBlob(name) for name in net_outputs]
|
||||
Y_trt = namedtupledict('Outputs', net_outputs)(*output_values)
|
||||
np.testing.assert_allclose(Y_c2, Y_trt, rtol=1e-3)
|
||||
|
||||
|
||||
|
@ -106,4 +106,3 @@ def transform_caffe2_net(
|
||||
pred_net_cut = caffe2_pb2.NetDef()
|
||||
pred_net_cut.ParseFromString(pred_net_str)
|
||||
return pred_net_cut
|
||||
|
||||
|
@ -68,5 +68,3 @@ TEST(SimpleQueueDeathTest, CannotAddAfterQueueFinished) {
|
||||
|
||||
|
||||
} // namespace caffe2
|
||||
|
||||
|
||||
|
@ -49,4 +49,3 @@ if(ATLAS_FOUND)
|
||||
|
||||
message(STATUS "Found Atlas (include: ${Atlas_CBLAS_INCLUDE_DIR}, library: ${Atlas_BLAS_LIBRARY})")
|
||||
endif(ATLAS_FOUND)
|
||||
|
||||
|
@ -21,4 +21,3 @@ if(HIREDIS_FOUND)
|
||||
message(STATUS "Found Hiredis (include: ${Hiredis_INCLUDE_DIR}, library: ${Hiredis_LIBRARIES})")
|
||||
mark_as_advanced(Hiredis_INCLUDE_DIR Hiredis_LIBRARIES)
|
||||
endif()
|
||||
|
||||
|
@ -55,4 +55,3 @@ if(NUMPY_FOUND)
|
||||
endif()
|
||||
|
||||
caffe_clear_vars(__result __output __error_value __values __ver_check __error_value)
|
||||
|
||||
|
@ -26,4 +26,3 @@ if(NUMA_FOUND)
|
||||
"Found Numa (include: ${Numa_INCLUDE_DIR}, library: ${Numa_LIBRARIES})")
|
||||
mark_as_advanced(Numa_INCLUDE_DIR Numa_LIBRARIES)
|
||||
endif()
|
||||
|
||||
|
@ -63,4 +63,3 @@ MARK_AS_ADVANCED(
|
||||
OpenBLAS_LIB
|
||||
OpenBLAS
|
||||
)
|
||||
|
||||
|
@ -21,4 +21,3 @@ if(ROCKSDB_FOUND)
|
||||
message(STATUS "Found RocksDB (include: ${RocksDB_INCLUDE_DIR}, library: ${RocksDB_LIBRARIES})")
|
||||
mark_as_advanced(RocksDB_INCLUDE_DIR RocksDB_LIBRARIES)
|
||||
endif()
|
||||
|
||||
|
@ -24,4 +24,3 @@ if(SNAPPY_FOUND)
|
||||
SNAPPY_VERION_LINES SNAPPY_MAJOR SNAPPY_MINOR SNAPPY_PATCHLEVEL)
|
||||
set(Snappy_VERSION "${SNAPPY_MAJOR}.${SNAPPY_MINOR}.${SNAPPY_PATCHLEVEL}")
|
||||
endif()
|
||||
|
||||
|
@ -32,4 +32,3 @@ IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
endif()
|
||||
message("-- </FindVSX>")
|
||||
endif()
|
||||
|
||||
|
@ -107,5 +107,3 @@ if (NOT "${file_text}" STREQUAL "")
|
||||
else()
|
||||
# message("FOUND NO DEPENDS")
|
||||
endif()
|
||||
|
||||
|
||||
|
@ -81,4 +81,3 @@ if(NOT TARGET gflags)
|
||||
"Caffe2 or a Caffe2 dependent library, the next warning / error will "
|
||||
"give you more info.")
|
||||
endif()
|
||||
|
||||
|
@ -68,4 +68,3 @@ if(NOT TARGET glog::glog)
|
||||
"Caffe2 or a Caffe2 dependent library, the next warning / error will "
|
||||
"give you more info.")
|
||||
endif()
|
||||
|
||||
|
@ -484,4 +484,3 @@ function(torch_set_target_props libname)
|
||||
set_target_properties(${libname} PROPERTIES STATIC_LIBRARY_FLAGS_DEBUG "/NODEFAULTLIB:${VCOMP_LIB}d")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
@ -71,4 +71,3 @@ def my_method(x, y):"""!
|
||||
```
|
||||
|
||||
Note that the bang (!) is added after the opening comment """! - this seems to do the trick and the remaining comments will be nicely parsed by Doxygen.
|
||||
|
||||
|
@ -25,4 +25,3 @@ clean:
|
||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||
%: Makefile
|
||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||
|
||||
|
@ -179,6 +179,3 @@ TorchAudio
|
||||
~~~~~~~~~~
|
||||
|
||||
- Vincent QB (`vincentqb <https://github.com/vincentqb>`__)
|
||||
|
||||
|
||||
|
||||
|
@ -5,4 +5,3 @@ torch.utils.dlpack
|
||||
|
||||
.. autofunction:: from_dlpack
|
||||
.. autofunction:: to_dlpack
|
||||
|
||||
|
@ -8,4 +8,3 @@ This is a full reference of functions and Tensor methods accessible in TorchScri
|
||||
.. contents:: :local:
|
||||
|
||||
.. automodule:: torch.jit.supported_ops
|
||||
|
||||
|
@ -149,5 +149,3 @@ Use :meth:`worker_init_fn` to preserve reproducibility::
|
||||
num_workers=num_workers,
|
||||
worker_init_fn=seed_worker
|
||||
)
|
||||
|
||||
|
||||
|
@ -85,4 +85,3 @@ Every :class:`torch.Tensor` has a corresponding storage of the same data type.
|
||||
:members:
|
||||
:undoc-members:
|
||||
:inherited-members:
|
||||
|
||||
|
@ -19,5 +19,3 @@ LinearReLU
|
||||
~~~~~~~~~~~~~~~
|
||||
.. autoclass:: LinearReLU
|
||||
:members:
|
||||
|
||||
|
||||
|
@ -16,6 +16,3 @@ Linear
|
||||
~~~~~~~~~~~~~~~
|
||||
.. autoclass:: Linear
|
||||
:members:
|
||||
|
||||
|
||||
|
||||
|
@ -65,4 +65,3 @@ Debugging utilities
|
||||
:nosignatures:
|
||||
|
||||
nn.intrinsic
|
||||
|
||||
|
@ -30,4 +30,3 @@ endif()
|
||||
if(CAFFE2_CMAKE_BUILDING_WITH_MAIN_REPO)
|
||||
set(Caffe2_MODULES ${Caffe2_MODULES} caffe2_observers_library PARENT_SCOPE)
|
||||
endif()
|
||||
|
||||
|
@ -46,6 +46,8 @@ files =
|
||||
tools/stats_utils/*.py,
|
||||
tools/test_history.py,
|
||||
tools/test/test_test_history.py,
|
||||
tools/test/test_trailing_newlines.py,
|
||||
tools/trailing_newlines.py,
|
||||
torch/testing/_internal/framework_utils.py,
|
||||
torch/utils/benchmark/utils/common.py,
|
||||
torch/utils/benchmark/utils/timer.py,
|
||||
|
@ -13,4 +13,3 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
@ -12,4 +12,3 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
##############################################################################
|
||||
|
||||
|
@ -88,7 +88,3 @@ if python_protobuf_installed and native_protobuf_installed:
|
||||
print(VERSION_MISMATCH)
|
||||
else:
|
||||
print('All looks good.')
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -193,4 +193,3 @@ class CommitDataCache:
|
||||
data = {commit: features._asdict() for commit, features in self.data.items()}
|
||||
with open(self.path, 'w') as f:
|
||||
json.dump(data, f)
|
||||
|
||||
|
@ -80,4 +80,3 @@ end
|
||||
|
||||
# run xcodebuild
|
||||
exec "xcodebuild clean build -project #{xcodeproj_path} -target #{target.name} -sdk #{sdk} -configuration Release PROVISIONING_PROFILE_SPECIFIER=#{profile} -arch #{arch}"
|
||||
|
||||
|
@ -30,4 +30,3 @@ for i, test in ipairs(tests) do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -49,6 +49,10 @@ Developer tools which you might find useful:
|
||||
appropriate subset of our `mypy*.ini` configs.
|
||||
* [test_history.py](test_history.py) - Query S3 to display history of a single
|
||||
test across multiple jobs over time.
|
||||
* [trailing_newlines.py](trailing_newlines.py) - Take names of UTF-8 files from
|
||||
stdin, print names of nonempty files whose contents don't end in exactly one
|
||||
trailing newline, exit with status 1 if no output printed or 0 if some
|
||||
filenames were printed.
|
||||
|
||||
Important if you want to run on AMD GPU:
|
||||
|
||||
|
@ -30,4 +30,3 @@ TORCH_LIBRARY_IMPL(aten, InplaceOrView, m) {
|
||||
|
||||
} // namespace
|
||||
} // namespace torch
|
||||
|
||||
|
49
tools/test/test_trailing_newlines.py
Normal file
49
tools/test/test_trailing_newlines.py
Normal file
@ -0,0 +1,49 @@
|
||||
from tools import trailing_newlines
|
||||
import unittest
|
||||
import tempfile
|
||||
|
||||
|
||||
def correct_trailing_newlines(file_contents: str) -> bool:
|
||||
with tempfile.NamedTemporaryFile(mode='w', delete=False) as tmp:
|
||||
filename = tmp.name
|
||||
tmp.write(file_contents)
|
||||
return trailing_newlines.correct_trailing_newlines(filename)
|
||||
|
||||
|
||||
class TestTrailingNewlines(unittest.TestCase):
|
||||
def test_empty(self) -> None:
|
||||
self.assertTrue(correct_trailing_newlines(''))
|
||||
|
||||
def test_single_byte(self) -> None:
|
||||
self.assertFalse(correct_trailing_newlines('a'))
|
||||
|
||||
def test_single_newline(self) -> None:
|
||||
self.assertFalse(correct_trailing_newlines('\n'))
|
||||
|
||||
def test_two_newlines(self) -> None:
|
||||
self.assertFalse(correct_trailing_newlines('\n\n'))
|
||||
|
||||
def test_three_newlines(self) -> None:
|
||||
self.assertFalse(correct_trailing_newlines('\n\n\n'))
|
||||
|
||||
def test_hello_world(self) -> None:
|
||||
self.assertFalse(correct_trailing_newlines('hello world'))
|
||||
|
||||
def test_hello_world_newline(self) -> None:
|
||||
self.assertTrue(correct_trailing_newlines('hello world\n'))
|
||||
|
||||
def test_hello_world_two_newlines(self) -> None:
|
||||
self.assertFalse(correct_trailing_newlines('hello world\n\n'))
|
||||
|
||||
def test_hello_world_three_newlines(self) -> None:
|
||||
self.assertFalse(correct_trailing_newlines('hello world\n\n\n'))
|
||||
|
||||
def test_hello_world_multiline(self) -> None:
|
||||
self.assertFalse(correct_trailing_newlines('hello\nworld'))
|
||||
|
||||
def test_hello_world_multiline_gap(self) -> None:
|
||||
self.assertTrue(correct_trailing_newlines('hello\n\nworld\n'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
37
tools/trailing_newlines.py
Executable file
37
tools/trailing_newlines.py
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import fileinput
|
||||
import os
|
||||
import sys
|
||||
|
||||
NEWLINE, = b'\n'
|
||||
|
||||
|
||||
def correct_trailing_newlines(filename: str) -> bool:
|
||||
with open(filename, 'rb') as f:
|
||||
a = len(f.read(2))
|
||||
if a == 0:
|
||||
return True
|
||||
elif a == 1:
|
||||
# file is wrong whether or not the only byte is a newline
|
||||
return False
|
||||
else:
|
||||
f.seek(-2, os.SEEK_END)
|
||||
b, c = f.read(2)
|
||||
# no ASCII byte is part of any non-ASCII character in UTF-8
|
||||
return b != NEWLINE and c == NEWLINE
|
||||
|
||||
|
||||
def main() -> int:
|
||||
# mimic git grep exit code behavior
|
||||
exit_code = 1
|
||||
for line in fileinput.input():
|
||||
stripped = line.rstrip()
|
||||
if not correct_trailing_newlines(stripped):
|
||||
exit_code = 0
|
||||
print(stripped)
|
||||
return exit_code
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
@ -25,4 +25,3 @@ target_link_libraries(test_deploy PUBLIC gtest dl torch_deploy)
|
||||
add_executable(deploy_benchmark ${DEPLOY_DIR}/example/benchmark.cpp)
|
||||
target_include_directories(deploy_benchmark PRIVATE ${PYTORCH_ROOT}/torch)
|
||||
target_link_libraries(deploy_benchmark PUBLIC torch_deploy)
|
||||
|
||||
|
@ -97,4 +97,3 @@ at::Dimname THPDimname_parse(PyObject* obj) {
|
||||
torch::kPyInternedStringToDimname.addMapping(obj, dimname);
|
||||
return dimname;
|
||||
}
|
||||
|
||||
|
@ -5,4 +5,3 @@
|
||||
at::Dimname THPDimname_parse(PyObject* obj);
|
||||
bool THPUtils_checkDimname(PyObject* obj);
|
||||
bool THPUtils_checkDimnameList(PyObject* obj);
|
||||
|
||||
|
@ -16,4 +16,3 @@
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
#error "Python 2 has reached end-of-life and is no longer supported by PyTorch."
|
||||
#endif
|
||||
|
||||
|
Reference in New Issue
Block a user