-
-
Notifications
You must be signed in to change notification settings - Fork 600
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 --newline=[LF|CRLF|native|preserve] option to compile, to override the line separator characters used #1491
Conversation
This comment has been minimized.
This comment has been minimized.
45e639b
to
2b2143b
Compare
This comment has been minimized.
This comment has been minimized.
2b2143b
to
8eaca63
Compare
This comment has been minimized.
This comment has been minimized.
IMO |
8eaca63
to
44458d3
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I do care about backwards compatibility, but I must note that the current (and "backward" behavior) on Windows is, I think, an inconsistent mix of line endings, depending on annotations and warnings and maybe hashes. This is because we create some multi line "line" strings for warnings, for example, then join/print these. |
This comment was marked as outdated.
This comment was marked as outdated.
@AndydeCleyre this looks like a bug. We can fix that inconsistency before the |
What would the backwards compatible behavior be, for windows? |
I'd guess, If we fix the "inconsistent mix of line endings" then it would be |
I'd like someone using Windows to confirm. If that is indeed the case, then isn't this PR, in its current state, what is desired anyway? |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
44458d3
to
ac27bbd
Compare
This comment was marked as outdated.
This comment was marked as outdated.
ac27bbd
to
e34ce65
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
6874650
to
d5791c9
Compare
Duplicating my own comment from the relevant issue, for visibility and feedback here: Maybe the move forward is to collpase #1491 into a single new flag,
What do you think? |
preserve-newlines should be the default. Having no example line separator and forcing pip-compile to guess is so rare (passed from stdin) that the choice barely matters |
So more like an |
Perhaps it barely matters which line ending is chosen but it does matter for it to be consistent between systems which is not currently the case either. |
I just threw up draft #1584 based on this PR and one more commit that implements this change and all it entails: @click.option(
- "--newline",
- type=click.Choice(("LF", "CRLF", "native", "preserve"), case_sensitive=False),
- default="preserve",
- help="Override the newline control characters used",
+ "--force-unix-newlines",
+ is_flag=True,
+ default=False,
+ help="Always use LF newlines, rather than auto-detecting from existing files.",
) Is that close to what we need? |
I'd like to direct anyone here to the latest poll back at the source issue, about which behavior should be the default, and what other options should be available, if any. Thanks for any feedback! |
d5791c9
to
c54a137
Compare
There aren't very many votes in the poll, but the current winner is still the implementation as it is here in this PR. |
f97dc49
to
dbd4ae0
Compare
dbd4ae0
to
8318634
Compare
8318634
to
c937691
Compare
5a845d4
to
fba38de
Compare
fba38de
to
387e8a6
Compare
387e8a6
to
5c9de44
Compare
- Use it in writer to override the line sep used in output - Set default to preserve, which checks the output file - Falls back to native if that's not possible, which uses os.linesep
Check the src_files for an existing newline, and use that if found
And remove outdated parameter to existing --newline test
when --newline=preserve and an existing newline isn't detected
This is either done by specifying --newline=LF, or *not* writing a newline to the input, so that the default --newline=preserve falls back to LF
5c9de44
to
386e90f
Compare
Whom from those with review/merge are supporting this feature? I am still -0.5 on it as it would add unrequired complexity to the code as users can control the newlines using git. If I would support something in this area it will enforcing use of @atugushev Are you? Asking because I do not want to see @AndydeCleyre spending more and more time on a task that never gets in. As I am against, he will need two +1 reviews to get it in. PS. Sorry, but I am only trying to protect the codebase. |
@@ -264,7 +266,7 @@ def write( | |||
else: | |||
log.info(line) | |||
self.dst_file.write(unstyle(line).encode()) | |||
self.dst_file.write(os.linesep.encode()) | |||
self.dst_file.write(self.linesep.encode()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be neater to use a TextIOWrapper so the existing code can continue to use \n
, which should sharply reduce the number of lines changed here
try:
dst_file = io.TextIOWrapper(self.dst_file, encoding="utf8", newlines=self.linesep):
for line in self._iter_lines(...):
dst_file.write(line)
dst_file.write("\n")
finally:
dst_file.detatch()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hugely in favor of this feature, and I think using a TextIOWrapper to translate the newlines will keep the changes small enough to justify it
Thanks! Closing this in favor of #1652 from +140 −17 |
pip-compile
gains an option withtwothreefour valid choices:--newline=[LF|CRLF|native|preserve]
,which can be used to override the guessed newline character used in the output file. The default is
native
preserve
, whichusestries to be consistent with an existing output file, or input file, oros.linesep
FALLBACK_VALUE (falls back tonative
, orLF
? TBD)LF
, in that order.This aims to address #1448.
Note: poll for fallback valueContributor checklist
Maintainer checklist
backwards incompatible
,feature
,enhancement
,deprecation
,bug
,dependency
,docs
orskip-changelog
as they determine changelog listing.