hyb
2026-01-30 44480e71b27aa9d4cb8441f50c873f1b110e9691
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#-----------------------------------------------------------------------------
# Copyright (c) 2015-2023, PyInstaller Development Team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: Apache-2.0
#-----------------------------------------------------------------------------
 
 
def _pyi_rthook():
    import atexit
    import os
    import sys
    import tempfile
 
    pixbuf_file = os.path.join(sys._MEIPASS, 'lib', 'gdk-pixbuf', 'loaders.cache')
 
    # If we are not on Windows, we need to rewrite the cache -> we rewrite on macOS to support --onefile mode
    if os.path.exists(pixbuf_file) and sys.platform != 'win32':
        with open(pixbuf_file, 'rb') as fp:
            contents = fp.read()
 
        # Create a temporary file with the cache and cleverly replace the prefix we injected with the actual path.
        fd, pixbuf_file = tempfile.mkstemp()
        with os.fdopen(fd, 'wb') as fp:
            libpath = os.path.join(sys._MEIPASS, 'lib').encode('utf-8')
            fp.write(contents.replace(b'@executable_path/lib', libpath))
 
        try:
            atexit.register(os.unlink, pixbuf_file)
        except OSError:
            pass
 
    os.environ['GDK_PIXBUF_MODULE_FILE'] = pixbuf_file
 
 
_pyi_rthook()
del _pyi_rthook