Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion backend/src/hatchling/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Comment thread
cjames23 marked this conversation as resolved.
content = BytesIO()
leading_blank_lines = []
for line in f:
# Ignore leading blank lines
# Buffer leading blank lines: they are only stripped when they
# precede a shebang, otherwise the file is preserved verbatim
# (e.g. a binary or a script that legitimately starts blank).
if not line.strip():
leading_blank_lines.append(line)
continue

if not line.startswith(b"#!"):
content.write(b"".join(leading_blank_lines))

match = shebang.match(line)
if match is None:
content.write(line)
Expand All @@ -697,6 +704,9 @@ def add_shared_scripts(self, archive: WheelArchive, records: RecordFile, build_d

content.write(f.read())
break
else:
# No non-blank line was found (empty or all-blank file); preserve it.
content.write(b"".join(leading_blank_lines))

record = archive.write_shared_script(shared_script, content.getvalue())
records.write(record)
Expand Down
Loading