-
-
Notifications
You must be signed in to change notification settings - Fork 611
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 pip-compile
#1652
Add --newline=[LF|CRLF|native|preserve]
option to pip-compile
#1652
Conversation
See also: #1584, which adds a commit on top of this, reducing the options to a single |
My review was requested on this, and I really want the feature and the code looks great to me - but I don't feel like I'm in a position to approve this PR |
3d1f27a
to
b8df966
Compare
@ssbarnea are you happy for me to review this PR? |
@graingert If all those conditions are met, feel free to make your review official. As I said, I am bit of 0.5 on this, so we will need two approvals to merge it. I do not want to alienate the author, but at the same time I cannot refrain from seeing this feature as adding useless complexity, as use of git attributes looks like a valid workaround. |
6b372f0
to
4250f1e
Compare
I do see this as additional complexity however I think this PR has really hit the nail on the head of balancing usability and backwards compatibility. In addition it's solving a tough problem that has been frustrating me and the people I introduce to pip-tools and other CLI tools that edit config so I plan to reuse this pattern and point to this implementation as an example |
4250f1e
to
6571d55
Compare
6571d55
to
1bec196
Compare
- Use it in writer to override the line sep used in output, using io.TextIOWrapper - Set default to preserve, which checks the output file, then the input file(s) - Falls back to LF if that's not possible
- skip decode to save time - catch FileNotFoundError to avoid potential race condition Co-authored-by: Thomas Grainger <[email protected]>
1bec196
to
a55c423
Compare
log.info(line) | ||
self.dst_file.write(unstyle(line).encode()) | ||
self.dst_file.write(os.linesep.encode()) | ||
if not self.dry_run: |
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.
FWIW this could be cleaner if implemented with a context manager conditionally returning a dummy I/O object.
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.
done here #1698
if gen_hashes: | ||
opts += ("--generate-hashes",) | ||
|
||
with open("requirements.in", "w") as req_in: |
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 feel like with modern Pythons it'd be nicer if Pathlib.write_text()
was used. But more importantly, why don't you use the built-in tmp_path
fixture to write temporary files?
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.
Feel free to make any changes you like, and thanks! This change isn't for me personally, and I have COVID right now and can't bring my full focus to the task.
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'll try and make a PR with this fix in!
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.
done here: #1694
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.
Aside for a few refactoring suggestions, this LGTM.
--newline=[LF|CRLF|native|preserve]
to pip-compile
--newline=[LF|CRLF|native|preserve]
to pip-compile
--newline=[LF|CRLF|native|preserve]
option to pip-compile
pip-compile
gains an option with four 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
preserve
, which tries to be consistent with an existing output file, or input file, or falls back toLF
, in that order.This aims to address #1448.
Contributor checklist
Maintainer checklist
backwards incompatible
,feature
,enhancement
,deprecation
,bug
,dependency
,docs
orskip-changelog
as they determine changelog listing.