Doc styling utils adds parasites new lines
Author: SBrandeis
Pull request: no
Labels: name: Documentation

## 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


Comments:
@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.
 

Just tried on my Windows laptop and I'm unable to reproduce, the line runs just fine on my side :-/, so it must be something else. The `newline="\n"` that jplu added everywhere we open a file should make it so that there is no different line endings problem in the first place, but there is still something here...

From the diff, it comes from [this regex](https://github.com/huggingface/transformers/blob/1c19b423bf274a465f95725a79819bf82f71329e/utils/style_doc.py#L417) but there should be no weird `\r` from Windows at this stage.

Anyhow, will rework the regex as a for loop and it should work everywhere hopefully.

(Not sure the PR above will actually fix the issue since I can't reproduce, please confirm if it does or no @SBrandeis )

Hi @sgugger, thanks a lot for the PR.
Unfortunately, it does not solve the issue on my side (the style_doc util still updates 196 files).
Since none of @jplu, @patrickvonplaten  and you can reproduce the issue, it must be related to my particular setup.
Not sure what is the cause though, but I'll let you know if I figure this out !

@SBrandeis as we are both on Windows, do you want we check that together offline?

I actually forgot to push the changes in #9488 because it was Friday evening and my brain was dead :-/
Will open a new PR.

@SBrandeis #9516 actually contains the code I wanted you to test, so if you could try again on this branch?

@jplu helped me troubleshoot this (thanks @jplu !)
Turns out my `git` was misconfigured, running `git config --global core.autocrlf input` solved my issue 😓 
I'll add a note in the `CONTRIBUTING.md` guide.