Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

License files with carriage returns (\r) cause formatting issues #55

Closed
johnthagen opened this issue Jan 4, 2020 · 4 comments · Fixed by #56
Closed

License files with carriage returns (\r) cause formatting issues #55

johnthagen opened this issue Jan 4, 2020 · 4 comments · Fixed by #56

Comments

@johnthagen
Copy link
Contributor

johnthagen commented Jan 4, 2020

django-cors-headers uses \r carriage returns instead of \n newlines in its license. This causes pip-licenses's column formatting to break.

$ pip install pip-licenses django-cors-headers
$ pip-licenses --with-license-file --no-license-path
...
 django-cors-headers  3.2.0    MIT License  Copyright 2017 Otto Yiu and other contributors
http://ottoyiu.com

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
...

Perhaps \r should be converted to \n before being output to ensure that the column formatting is not disrupted?

@johnthagen johnthagen changed the title License files with carriage returns ( License files with carriage returns (\r) cause formatting issues Jan 4, 2020
@johnthagen
Copy link
Contributor Author

johnthagen commented Jan 4, 2020

I think this will happen for any packages that are bundled on Windows before being uploaded to PyPI.

@adamchainz
Copy link
Contributor

If open() is/would be used to read the license, its default behaviour of newline=None should translate newlines into \n: https://docs.python.org/3/library/functions.html#open

@johnthagen
Copy link
Contributor Author

The specific case that brought up this issue was fixed upstream with django-cors-headers 3.2.1. (Thanks @adamchainz!)

@raimon49 I'm inclined to close this issue so as to not add any more work for pip-licenses, but I'll leave it open until I hear from you in case this is something you did want to globally address.

adamchainz added a commit to adamchainz/pip-licenses that referenced this issue Jan 4, 2020
Fixes raimon49#55.

By using `open()` rather than `codecs.open()` the newline-fixing behaviour from Python 3 can be used.

Presumably `codecs.open()` was used previously to allow proper UTF-8 handling in Python 2, but since that has been dropped the normal `open()` can be used.

Also drop some inner imports in tests and empty `setUp()` and `tearDown()` methods.

Tested with:

```
$ pip install django-cors-headers==3.2.0
$ python piplicenses.py --with-license-file --no-license-path | grep -C 2 django-cors-headers
                                                                                                   END OF TERMS AND CONDITIONS

 django-cors-headers  3.2.0       MIT License                                                   Copyright 2017 Otto Yiu and other contributors
                                                                                                http://ottoyiu.com
```

This showed the same breakage as in the issue before the fix.
@raimon49
Copy link
Owner

raimon49 commented Jan 5, 2020

@johnthagen Thanks for the report and the discussion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants