Repository: huggingface/transformers

Issue:
Doc styling utils adds parasites new lines
## Environment info
     
- `transformers` version: 4.2.0dev0
- Platform: Windows-10-10.0.18362-SP0
- Python version: 3.7.9
- PyTorch version (GPU?): 1.7.1 (False)
- Tensorflow version (GPU?): 2.3.1 (False)
- Using GPU in script?: Nope
- Using distributed or parallel set-up in script?: Nope

### Who can help

@sgugger 

## Information

Running the python util to style docs adds parasite new lines in every single docstring. See:

```bash
$ python utils/style_doc.py src/transformers docs/source --max_len 119 --check_only
Traceback (most recent call last):
  File "utils/style_doc.py", line 491, in <module>
    main(*args.files, max_len=args.max_len, check_only=args.check_only)
  File "utils/style_doc.py", line 479, in main
    raise ValueError(f"{len(changed)} files should be restyled!")
ValueError: 345 files should be restyled!
```

See this commit for an example of what it does: https://github.com/huggingface/transformers/pull/9150/commits/b4dedd5ca25f043c66d12c774fa00a34c74dffb2

## To reproduce

Steps to reproduce the behavior:

1. Checkout and update master branch
2. run `python utils/style_doc.py src/transformers docs/source --max_len 119 --check-only` from transformers root

Output:
```python
Traceback (most recent call last):
  File "utils/style_doc.py", line 491, in <module>
    main(*args.files, max_len=args.max_len, check_only=args.check_only)
  File "utils/style_doc.py", line 479, in main
    raise ValueError(f"{len(changed)} files should be restyled!")
ValueError: 345 files should be restyled!
```

It might have something to do with Windows or a particular setup of my machine because behavior cannot be reproduced by @patrickvonplaten.

## Expected behavior

On master branch, documentation should not need to be restyled



Discussion:
@sgugger do you maybe have an idea here? Now that I see that it's Window I think this could be the reason
Mmm, @jplu didn't have any issue with this I believe.
Sorry, reading again, you're not running make style but launching the script directly. There is nothing there to properly support Windows special line endings so it would probably require rewriting it from scratch to fix this. Can you use WSL for the styling?
I can run properly `python utils/style_doc.py src/transformers docs/source --max_len 119` on Windows (not on WSL) without any error. In order to properly run all the make targets on Windows I use the steps given in the [CONTRIBUTING readme](https://github.com/huggingface/transformers/blob/master/CONTRIBUTING.md#develop-on-windows).
Ah, there was one special magic option from GitHub for the line endings that could help, @LysandreJik do you remember which one? We had this problem with Niels on TAPAS.
It is the `core.autocrlf` config, you can see how to set it in the doc https://git-scm.com/book/fr/v2/Personnalisation-de-Git-Configuration-de-Git
Asked Lysandre and running `git config core.autocrlf false` solved the issue last time a contributor ran into it. @SBrandeis could you test if it does solve the issue for you? If that's the case, we'll add it to the `CONTRIBUTING` guide.
Setting `git config core.autocrlf` to `false` did not solve my issue, neither did running the python util from WSL.
 

Resolving patch:
diff --git a/utils/style_doc.py b/utils/style_doc.py
--- a/utils/style_doc.py
+++ b/utils/style_doc.py
@@ -381,9 +381,9 @@ def style_rst_file(doc_file, max_len=119, check_only=False):
         doc = f.read()
 
     # Add missing new lines before lists
-    doc = _add_new_lines_before_list(doc)
+    clean_doc = _add_new_lines_before_list(doc)
     # Style
-    clean_doc = rst_styler.style(doc, max_len=max_len)
+    clean_doc = rst_styler.style(clean_doc, max_len=max_len)
 
     diff = clean_doc != doc
     if not check_only and diff:


Test patch: