Skip to content

Addresses bug where blank lines are dropped when there is no shebang#2328

Open
cjames23 wants to merge 2 commits into
pypa:masterfrom
cjames23:fix-flaky-test
Open

Addresses bug where blank lines are dropped when there is no shebang#2328
cjames23 wants to merge 2 commits into
pypa:masterfrom
cjames23:fix-flaky-test

Conversation

@cjames23

Copy link
Copy Markdown
Member

Fixes #2319

Track blank lines and only discard if we find a shebang

@henryiii henryiii left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me.

@@ -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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good call!

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 this pull request may close these issues.

Flaky test_default_shared_scripts: shared-scripts shebang rewriter drops leading blank line from random binary fixture

3 participants