Addresses bug where blank lines are dropped when there is no shebang#2328
Open
cjames23 wants to merge 2 commits into
Open
Addresses bug where blank lines are dropped when there is no shebang#2328cjames23 wants to merge 2 commits into
cjames23 wants to merge 2 commits into
Conversation
ofek
reviewed
Jun 27, 2026
| @@ -682,11 +682,18 @@ def add_shared_scripts(self, archive: WheelArchive, records: RecordFile, build_d | |||
| for shared_script in self.recurse_explicit_files(shared_scripts): | |||
| with open(shared_script.path, "rb") as f: | |||
Contributor
There was a problem hiding this comment.
Let's create a MAX_SHEBANG_LENGTH constant and then:
Suggested change
| with open(shared_script.path, "rb") as f: | |
| with open(shared_script.path, "rb") as f: | |
| prefix = f.read(2) | |
| if prefix != b"#!": | |
| record = add_shared_script(shared_script) | |
| else: | |
| line = prefix + f.readline(MAX_SHEBANG_LENGTH- len(prefix)) | |
| if len(line) == MAX_SHEBANG_LENGTHand not line.endswith(b"\n"): | |
| record = add_shared_script(shared_script) | |
| else: | |
| if (match := shebang.match(line)) is None: | |
| record = add_shared_script(shared_script) | |
| else: | |
| content = BytesIO() | |
| content.write(b"#!python") | |
| if remaining := match.group(1): | |
| content.write(remaining) | |
| content.write(f.read()) | |
| record = archive.write_shared_script(shared_script, content.getvalue()) | |
| records.write(record) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2319
Track blank lines and only discard if we find a shebang