pytorch/docs/source
Sam Estep 5bcbbf5373 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
2021-03-30 13:09:52 -07:00
..
_static Add documentation page for pipeline parallelism. (#50791) 2021-01-25 13:47:13 -08:00
_templates various doc building cleanups (#53851) 2021-03-16 15:01:59 -07:00
community Lint trailing newlines (#54737) 2021-03-30 13:09:52 -07:00
notes Lint trailing newlines (#54737) 2021-03-30 13:09:52 -07:00
rpc Forbid trailing whitespace (#53406) 2021-03-05 17:22:55 -08:00
scripts Optimize SiLU (Swish) op in PyTorch (#42976) 2020-08-16 13:21:57 -07:00
__config__.rst Fix __config__ docs (#48557) 2020-11-29 23:57:06 -08:00
amp.rst Reference amp tutorial (recipe) from core amp docs (#44725) 2020-09-16 11:37:58 -07:00
autograd.rst Update docs feature classifications (#39966) 2020-06-24 15:35:59 -07:00
backends.rst Forbid trailing whitespace (#53406) 2021-03-05 17:22:55 -08:00
benchmark_utils.rst Expand benchmark utils docs (#51664) 2021-02-04 00:22:41 -08:00
bottleneck.rst [docs] Clarify more CUDA profiling gotchas in bottleneck docs (#6763) 2018-04-19 13:15:27 -04:00
checkpoint.rst Stashing checkpointing RNG states based on devices of arg tensors (#14518) 2018-12-11 09:48:45 -08:00
complex_numbers.rst various doc building cleanups (#53851) 2021-03-16 15:01:59 -07:00
conf.py various doc building cleanups (#53851) 2021-03-16 15:01:59 -07:00
cpp_extension.rst correct some cpp extension code usages and documents (#39766) 2020-06-10 08:31:22 -07:00
cpp_index.rst Add C++ Landing Page (#38450) 2020-05-14 16:02:01 -07:00
cuda.rst docs: add reset_peak_memory_stats in cuda.rst (#54668) 2021-03-29 10:05:20 -07:00
cudnn_persistent_rnn.rst Forbid trailing whitespace (#53406) 2021-03-05 17:22:55 -08:00
cudnn_rnn_determinism.rst Forbid trailing whitespace (#53406) 2021-03-05 17:22:55 -08:00
data.rst Forbid trailing whitespace (#53406) 2021-03-05 17:22:55 -08:00
ddp_comm_hooks.rst [Gradient Compression] Introduce fp16_compress_wrapper in ddp_comm_hooks.rst (#54052) 2021-03-16 15:40:10 -07:00
distributed.optim.rst [Reland] Update and expose ZeroRedundancyOptimizer docs (#53112) 2021-03-02 14:16:12 -08:00
distributed.rst update distributed doc table for alltoall nccl (#54277) 2021-03-19 15:35:10 -07:00
distributions.rst Add sample validation for LKJCholesky.log_prob (#52763) 2021-02-25 16:12:29 -08:00
dlpack.rst Lint trailing newlines (#54737) 2021-03-30 13:09:52 -07:00
docutils.conf Revert "Revert D21337640: [pytorch][PR] Split up documentation into subpages and clean up some warnings" (#37778) 2020-05-04 14:32:35 -07:00
fft.rst Remove deprecated spectral ops from torch namespace (#48594) 2020-12-05 04:12:32 -08:00
futures.rst [JIT x RPC] Consolidate Future type class and Future impl class (#40406) 2020-06-24 01:44:49 -07:00
fx.rst [FX][docs] Render inherited methods in fx.Tracer API reference (#53630) 2021-03-09 14:30:41 -08:00
hub.rst Add a torch.hub.load_local() function that can load models from any local directory with a hubconf.py (#44204) 2020-09-21 14:17:21 -07:00
index.rst [special] add torch.special namespace (#52296) 2021-03-04 00:04:36 -08:00
jit_builtin_functions.rst Lint trailing newlines (#54737) 2021-03-30 13:09:52 -07:00
jit_language_reference_v2.rst [docs] Add updated TorchScript language reference section for types (#53673) 2021-03-30 10:32:58 -07:00
jit_language_reference.rst add type annotations to torch.nn.modules.conv (#49564) 2021-01-15 11:16:11 -08:00
jit_python_reference.rst [JIT] Add support for with statements (#34705) 2020-06-18 16:57:18 -07:00
jit_unsupported.rst [JIT] Update docs for recently added features (#45232) 2020-09-28 18:17:42 -07:00
jit.rst Add documentation for torch.jit.Attribute and torch.jit.annotate (#54485) 2021-03-29 14:44:53 -07:00
linalg.rst Added torch.linalg.matrix_power (#52608) 2021-03-23 15:10:06 -07:00
math-quantizer-equation.png adding quantization.rst file for quantization feature (#27559) 2019-10-09 16:45:09 -07:00
mobile_optimizer.rst Mod lists to neutral+descriptive terms in caffe2/docs (#49803) 2020-12-23 11:37:11 -08:00
model_zoo.rst add/move a few apis in torch.hub (#18758) 2019-04-10 23:10:39 -07:00
multiprocessing.rst Forbid trailing whitespace (#53406) 2021-03-05 17:22:55 -08:00
name_inference.rst Fixed median nan propagation and implemented nanmedian (#45847) 2020-10-08 11:20:21 -07:00
named_tensor.rst Forbid trailing whitespace (#53406) 2021-03-05 17:22:55 -08:00
nn.functional.rst docs: add functional group_norm (#54673) 2021-03-29 10:21:50 -07:00
nn.init.rst Bag of documentation fixes; fix more sphinx warnings (#27850) 2019-10-15 07:31:14 -07:00
nn.rst docs: separate autosummary for flatten layers (#54663) 2021-03-29 10:23:34 -07:00
onnx.rst [ONNX] Update ONNX documentation (#51362) (#53313) 2021-03-12 02:49:38 -08:00
optim.rst Forbid trailing whitespace (#53406) 2021-03-05 17:22:55 -08:00
pipeline.rst Forbid trailing whitespace (#53406) 2021-03-05 17:22:55 -08:00
profiler.rst Update docs for torch.profiler.tensorboard_trace_handler (#51636) 2021-02-04 13:32:59 -08:00
quantization-support.rst [quantization] Add some support for 3d operations (#50003) 2021-03-10 16:40:35 -08:00
quantization.rst [docs][quant] Fix FX Graph Mode Quantization tutorial link (#54715) 2021-03-29 17:25:19 -07:00
random.rst Remove duplicated entries in random.rst (#39725) 2020-06-10 16:51:15 -07:00
rpc.rst Add 'remote_parameters' and 'get_module_rref' to RemoteModule docs. (#54645) 2021-03-26 21:41:28 -07:00
sparse.rst [wip] doc_fix (#51825) 2021-02-06 11:36:36 -08:00
special.rst Lint trailing newlines (#54737) 2021-03-30 13:09:52 -07:00
storage.rst Lint trailing newlines (#54737) 2021-03-30 13:09:52 -07:00
tensor_attributes.rst Fix the repeated entry in the Tensor Attributes doc (#52995) 2021-03-01 16:42:32 -08:00
tensor_view.rst Add torch.swapdims and torch.swapaxes (#46041) 2020-11-18 11:35:53 -08:00
tensorboard.rst Add method add_hparams to API doc (#27344) 2019-10-03 17:07:45 -07:00
tensors.rst Deprecate legacy constructor torch.Tensor() (#54414) 2021-03-29 05:14:47 -07:00
torch.nn.intrinsic.qat.rst [quantization] Add some support for 3d operations (#50003) 2021-03-10 16:40:35 -08:00
torch.nn.intrinsic.quantized.rst Lint trailing newlines (#54737) 2021-03-30 13:09:52 -07:00
torch.nn.intrinsic.rst [quantization] Add some support for 3d operations (#50003) 2021-03-10 16:40:35 -08:00
torch.nn.qat.rst Lint trailing newlines (#54737) 2021-03-30 13:09:52 -07:00
torch.nn.quantized.dynamic.rst Forbid trailing whitespace (#53406) 2021-03-05 17:22:55 -08:00
torch.nn.quantized.rst [quant] add docs for embedding/embedding_bag (#51770) 2021-02-05 11:43:15 -08:00
torch.overrides.rst Add documentation for torch.overrides submodule. (#48170) 2020-11-30 11:25:31 -08:00
torch.quantization.rst Lint trailing newlines (#54737) 2021-03-30 13:09:52 -07:00
torch.rst [numpy] Add torch.take_along_dim (#52833) 2021-03-28 05:22:51 -07:00
type_info.rst DOC: split quantization.rst into smaller pieces (#41321) 2020-07-25 23:59:40 -07:00