mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Python: skip scripts without python shebang
some scripts like uv might not have one GitOrigin-RevId: 18e14b22378f03a6bb754dee7a79c33c7c976b93
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bf280c6f4a
commit
8b1404ea28
@@ -23,14 +23,16 @@ def put_script_data(script_path: Path, script_data: bytes):
|
||||
def find_shebang_start_index(where_to_search_shebang: bytes) -> int:
|
||||
# Almost always shebang starts here (right after the last PE section)
|
||||
default_offset: int = 0x1A600
|
||||
if len(where_to_search_shebang) > default_offset and where_to_search_shebang[default_offset] == '#':
|
||||
if len(where_to_search_shebang) > default_offset and where_to_search_shebang[
|
||||
default_offset] == '#':
|
||||
return default_offset
|
||||
|
||||
# Not found in default offset? Let's search
|
||||
for drive_letter_code in range(ord('a'), ord('z')):
|
||||
for drive_letter in [chr(drive_letter_code), chr(drive_letter_code).upper()]:
|
||||
try:
|
||||
return where_to_search_shebang.index(f"#!{drive_letter}:\\".encode('UTF-8'))
|
||||
return where_to_search_shebang.index(
|
||||
f"#!{drive_letter}:\\".encode('UTF-8'))
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
@@ -41,7 +43,9 @@ if __name__ == "__main__":
|
||||
for script in Path(scripts_dir).glob("*.exe"):
|
||||
script_content = get_script_content(script)
|
||||
shebang_start = find_shebang_start_index(script_content)
|
||||
assert shebang_start, f"No python found in {script}"
|
||||
if not shebang_start:
|
||||
print(f"No python found in {script}")
|
||||
continue
|
||||
shebang_end = script_content.find(b'\n', shebang_start)
|
||||
assert shebang_end, "No shebang end found: broken binary?"
|
||||
old_shebang = script_content[shebang_start:shebang_end]
|
||||
|
||||
Reference in New Issue
Block a user