From 8b1404ea285bab4428577eebc17b87f260d08ee2 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Fri, 7 Feb 2025 04:20:29 +0100 Subject: [PATCH] Python: skip scripts without python shebang some scripts like uv might not have one GitOrigin-RevId: 18e14b22378f03a6bb754dee7a79c33c7c976b93 --- .../buildserver_win_fix/fix_path.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/python/setup-test-environment/buildserver_win_fix/fix_path.py b/python/setup-test-environment/buildserver_win_fix/fix_path.py index 20aafd6a6a98..580ae9c77b1c 100644 --- a/python/setup-test-environment/buildserver_win_fix/fix_path.py +++ b/python/setup-test-environment/buildserver_win_fix/fix_path.py @@ -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]