-
-
Notifications
You must be signed in to change notification settings - Fork 614
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
Add a way to choose line endings in compiled files #1448
Comments
Imho pip-compile should reuse whatever line separator it finds first in requirements.txt, and fall back to the first line separator it finds in requirements.in |
Can you please elaborate on the problem? Do you not have a guaranteed order of hook runs (to ensure the line-ending hook runs last)? |
Run this on Windows (due to
See the output:
The problem is that |
I've done a first try at https://github.com/AndydeCleyre/pip-tools/tree/feature/linesep -- no tests yet, no PR yet. @jack1142 can you test out that branch in your pre-commit setup, and add the arg |
@AndydeCleyre Seems to work as intended. |
If any Windows users are reading this who haven't already responded to the poll about the best default behavior, please go have a look, thanks! |
This comment was marked as outdated.
This comment was marked as outdated.
In the usecase stated in the issue "preserve" is a better choice. The pre-commit hook https://github.com/pre-commit/pre-commit-hooks#mixed-line-ending in combination with "preserve" will handle this |
So more like an |
Seems fine to me though Thomas commented in the PR that preserve should be default (which I'm not sure I agree with but it doesn't matter to me since it's going to end up as LF in both cases anyway) |
I am for LF implicit and having a single opt-in preserve option for those looking for one. That keeps the added complexity out of the execution path for most users. TBH, I do find any developer that does not configure git to force LF as looking for trouble, especially as most tools work well with LF, even on Windows. Just think about mounting and cross platform issues. |
In my experience, trying to force LF has resulted in similar issues, where some tool edits a file and naïvely uses CRLF. Git does a good job at converting back to LF on check in, so there shouldn't be a need to force a specific line ending on check out. |
Poll:
You can vote for one or more if you're feeling flexible. |
How about preserve by default, and fall back to the line endings in With just the preserve by default behaviour, there will already be several options to force a specific line ending:
Are these insufficient? |
To be clear, the "preserve newlines" behavior as implemented in alternative PRs
I'm less sure, and welcome a description of any real user cases violating this prediction. Theoretically some users may not be using git... Anyway I'll add an option to the poll:
|
Yeah, fair enough. The first point is indeed the strongest one I think. |
means pip-compile crashes when used with data from stdin? |
No, it means try to use newline from existing output, and failing that, try to use newline from input file, and failing that, use |
#1584 could use a PR description as the difference between these PRs is not immediately clear. Based on the code read, it seems that #1584 has the behavior of I personally did not see the need for |
The most important thing to me is that pip-tools stops producing files with mixed line endings. I don't care what the line ending is as long as its consistent. Both PRs seem to accomplish this, but I lean towards #1584 since it's simpler. In fact, I don't think a way to force line endings is needed (as outlined in #1448 (comment), there are alternatives to accomplish this). Not a dealbreaker though; it's an extra argument but at least it doesn't seem to have much impact on the complexity of the implementation. |
|
What's the problem this feature will solve?
I'm trying to use the pip-compile hook with my existing pre-commit configuration but one of the hooks I have is a mixed line ending auto-fixer (which I use to ensure all files in the repository use LF for line endings):
This configuration causes issues whenever I try to touch a requirements file.
Describe the solution you'd like
A way to set the line endings used for the generated
requirements.txt
file. The alternative would be for pip-compile to always use\n
but then I'm guessing someone else might complain about it in the future like I'm doing now :)Alternative Solutions
I can work around this issue by excluding requirement files from the check but this doesn't really solve it as I still end up with requirements files ending with CRLF, it just allows me to continue to use both hooks.
Another solution would be a way for
--dry-run
to return non-zero exit code when the file would have any dependencies changed (like what #882 and #1215 suggest) but this doesn't fully solve it either as then you lose the benefit of pip-compile auto-fixing the issue during pre-commit run.Additional context
I'm using on Windows -
os.linesep
is equal to"\r\n"
thereThe text was updated successfully, but these errors were encountered: