Method, device and equipment for constructing Python file based on Bazel and storage medium
By configuring Bazel's Python toolchain and injecting shell scripts, packaging Python projects and their dependencies, the problem of traditional Python binary files being not directly executable is solved, and direct execution and efficient deployment in various system environments are achieved.
Patent Information
- Application Number
- CN202411987878.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-05-13
AI Technical Summary
The Python binary files built by traditional Bazel are not directly executable and require pre-configuration of the correct Python runtime environment, which leads to inconvenience in deployment and use.
By configuring Bazel's Python toolchain, the Python project and its dependencies are packaged into compressed files, and the file header is injected into a second shell script to achieve direct executability of the spliced files.
It solves the execution complexity and system environment configuration requirements of Python binary files, improves the portability, compatibility and ease of use of Python projects, and enables the built Python files to be executed directly in various system environments.
Smart Images

Figure CN119987731A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of computer software development, and in particular to a method, apparatus, device and storage medium for building Python files based on Bazel. Background Art
[0002] Python is a widely used interpreted programming language that usually needs to be executed in a Python runtime environment that is compatible with its version. The Python runtime environment includes the Python interpreter and the dynamic link library files it depends on. The traditional Python runtime environment can be installed in the system directory or packaged into the software to be released in the form of a portable file package, so that the built software has stronger portability. However, the portable runtime environment will increase the size of the software.
[0003] Bazel is an open source build and test automation tool that supports cross-platform and multi-language builds. Its Python toolchain can control the Python version and runtime environment for building Python projects, and allows Python projects to be built into binary files containing source code and third-party libraries. These binary files are in zip compression format, which contains all source code, library files, and Python runtime environments, making it easy to run on other systems.
[0004] However, the Python binary files built by traditional Bazel still have some limitations. First, the generated zip file is not a direct executable file, but needs to be loaded and executed by the Python interpreter, which increases the complexity of use. Second, the system running these binary files must be pre-configured with the correct Python runtime environment, otherwise it will not be able to execute normally. Summary of the invention
[0005] The present application provides a method, apparatus, device and storage medium for building Python files based on Bazel. The Python files built based on Bazel are not directly executable files, but must rely on a pre-configured correctly Python runtime environment, which is inconvenient to deploy and use.
[0006] A first aspect of the present application provides a method for building Python files based on Bazel, comprising: configuring Bazel's Python toolchain according to a portable Python runtime of a Python project;
[0007] Using the Bazel Python tool chain, the source code of the Python project and its dependent Python library code, the portable Python runtime and the code entry file are used to build a Python compressed file;
[0008] Injecting a preset second shell script into the file header of the Python compressed file through a preset first shell script in the Python tool chain of Bazel to obtain a spliced file, wherein the second shell script can replace the image executing its process with the Python interpreter of the portable Python runtime, and pass the path of the spliced file as a command line parameter to the Python interpreter;
[0009] The spliced file is given executable permission and named to obtain a target Python file.
[0010] A second aspect of the present application provides a device for building Python files based on Bazel, comprising: a configuration module for configuring Bazel's Python toolchain according to a portable Python runtime of a Python project;
[0011] A building module, used to build a Python compressed file from the source code of the Python project and its dependent Python library code, the portable Python runtime and the code entry file through the Bazel Python tool chain;
[0012] A file header injection module, used for injecting a preset second shell script into the file header of the Python compressed file through a preset first shell script in the Python tool chain of Bazel to obtain a spliced file, wherein the second shell script can replace the image executing its process with the Python interpreter of the portable Python runtime, and pass the path of the spliced file as a command line parameter to the Python interpreter;
[0013] The processing module is used to grant executable permission to the spliced file and name it to obtain a target Python file.
[0014] A third aspect of the present application provides a device for building Python files based on Bazel, comprising: a memory and at least one processor, wherein instructions are stored in the memory; the at least one processor calls the instructions in the memory so that the device for building Python files based on Bazel executes the above-mentioned method for building Python files based on Bazel.
[0015] A fourth aspect of the present application provides a computer-readable storage medium, which stores instructions. When the computer-readable storage medium is run on a computer, the computer executes the above-mentioned method for building Python files based on Bazel.
[0016] In the technical solution provided in this application, the process of Bazel building Python files is improved, and the execution complexity, system environment configuration requirements and executability issues of traditional Python binary files are solved. By configuring Bazel's Python tool chain, the Python project and its dependencies are packaged as compressed files, and the second shell script is innovatively injected as the file header, the direct executability of the spliced files is achieved, which significantly improves the portability, compatibility and ease of use of the Python project, so that the final constructed Python file can be directly executed in various system environments without the need for additional environment configuration and installation steps. The software release and operation process is simplified, greatly improving the user experience and system deployment efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 A schematic diagram of an embodiment of a method for building Python files based on Bazel in this application;
[0018] Figure 2 This is another embodiment schematic diagram of the method for building Python files based on Bazel in this application;
[0019] Figure 3 A schematic diagram of an embodiment of a device for building Python files based on Bazel in this application;
[0020] Figure 4 A schematic diagram of another embodiment of a device for building Python files based on Bazel in the present application;
[0021] Figure 5 A schematic diagram of an embodiment of a device for building Python files based on Bazel in this application. DETAILED DESCRIPTION
[0022] The present application provides a method, apparatus, device and storage medium for building Python files based on Bazel, which is used for building a method based on Bazel combined with shell scripts to create a portable Python file that can be directly executed without pre-configuring the Python environment.
[0023] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0024] For ease of understanding, the specific process of the embodiment of the present application is described below. Figure 1 , an embodiment of the method for building Python files based on Bazel in the present application includes:
[0025] 101. Configure Bazel’s Python toolchain based on the portable Python runtime for Python projects.
[0026] It is understandable that the execution subject of the present application can be a device for building Python files based on Bazel, or a terminal or a server, which is not limited here. The present application embodiment is described by taking the terminal as the execution subject as an example.
[0027] First, start the Bazel build system on the terminal, determine the requirements of the Python project selected by the user, determine the corresponding portable Python runtime, Python project source code, dependent Python library code, etc. Then, configure Bazel's Python toolchain based on the determined content.
[0028] This step involves editing Bazel’s configuration file, specifying the path to the Python interpreter and any necessary build options, ensuring that Bazel can recognize and use this portable Python runtime to build Python projects.
[0029] The Bazel Python toolchain in this example decouples the logic of Bazel's Python rules from the selection of Python build tools when building a Python project. In an environment where multiple platforms and multiple versions of Python coexist, it allows Bazel to select the appropriate Python version and dependencies when building without modifying Bazel's own build rules. This avoids modifying the Python version and runtime environment configuration every time you build.
[0030] 102. Use Bazel's Python tool chain to build a Python compressed file from the source code of the Python project and its dependent Python library code, portable Python runtime, and code entry file.
[0031] Using Bazel's Python toolchain, the source code of the Python project, its dependent Python library code, the portable Python runtime, and the code entry file (for example, main.py) are packaged into a compressed file. This compressed file is in zip format and contains all the files and libraries required to run the Python project.
[0032] Specifically, you can write a Bazel build rule that specifies the names of source code files, dependencies, and output files. Then, run the Bazel build command, and Bazel will automatically handle dependencies and package all necessary files into a compressed file.
[0033] 103. Inject the preset second shell script into the file header of the Python compressed file through the preset first shell script in the Python tool chain of Bazel to obtain a spliced file.
[0034] The preset second shell script is injected into the file header of the Python compressed file through the preset first shell script in the Python tool chain of Bazel.
[0035] The second shell script can replace the image executing its process with the Python interpreter of the portable Python runtime, and pass the path of the spliced file to the Python interpreter as a command line parameter.
[0036] 104. Grant executable permissions to the spliced file and name it to obtain the target Python file.
[0037] Give executable permissions to the concatenated file and name it appropriately so that users can easily identify and execute it.
[0038] In this embodiment, the process of Bazel building Python files is improved, solving the problems of traditional Python binary file execution complexity, system environment configuration requirements and executability. By configuring Bazel's Python tool chain, the Python project and its dependencies are packaged as compressed files, and the second shell script is innovatively injected as the file header, the direct executability of the spliced files is achieved, which significantly improves the portability, compatibility and ease of use of the Python project, so that the final built Python file can be directly executed in various system environments without additional environment configuration and installation steps. The software release and operation process is simplified, greatly improving the user experience and system deployment efficiency.
[0039] See also Figure 2 Another embodiment of the method for building Python files based on Bazel in the present application includes:
[0040] 201. Configure Bazel's Python toolchain based on the portable Python runtime for Python projects.
[0041] Specifically, the interpreter properties of the Python toolchain are configured according to the Python interpreter in the portable Python runtime; and the file properties of the Python toolchain are configured to be a Bazel file group consisting of all files in the portable Python runtime.
[0042] Optionally, configure the interpreter property of the py_runtime rule to be a Python interpreter in a portable Python runtime, and configure the files property of the py_runtime rule to be a bazel file group consisting of all files in the portable Python runtime. In this example, you specify which version of Python to use and related dependencies through the py_runtime rule. For example, this step will configure a portable Python runtime environment so that the generated Python project no longer depends on the Python environment installed on the system.
[0043] 202. Use Bazel's Python tool chain to build a Python compressed file from the source code of a Python project and its dependent Python library code, a portable Python runtime, and code entry files.
[0044] Specifically, the source code of the Python project and its dependent Python library code and portable Python runtime are extracted from the Python tool chain of Bazel to obtain a Python project combination file; the Python combination file and the code entry file are compressed to obtain a Python compressed file. In this embodiment, the portable Python runtime environment is directly embedded into the generated binary file. The Python compressed file contains all the necessary runtime environments, so the file can be executed on any system as long as the system can execute the executable file, ensuring the cross-platform and portability of the Python program.
[0045] Exemplarily, by implementing a bazel macro or bazel rule in Bazel: take out the bazel file group consisting of files with the output_group attribute of "python_zip_file" from the native bazel py_binary rule. This file group actually contains only one file - the Python source code and its dependent Python library code, the portable Python runtime, and a __main__.py file as the code entry point, compressed by zip.
[0046] Among them, the py_binary rule in Bazel is used to define how to build Python executable files. It can package Python source code and dependencies into a binary executable file. In Bazel, output_group is a way to output file groups, which specifies a part of the multiple file groups generated during the build process. In this scenario, the file group with the output_group attribute "python_zip_file" refers to the file group that contains the packaged Python code, dependencies, runtime, and entry files.
[0047] The python_zip_file packaged the Python code and related files in zip format for easy distribution and execution.
[0048] 203. The Python compressed file is used as a byte stream by the first shell script, and is spliced with the second shell script as a file header to obtain a spliced file.
[0049] In this embodiment, the second shell script can replace the image executing its process with the Python interpreter of the portable Python runtime, and pass the path of the spliced file as a command line parameter to the Python interpreter. This embodiment can ensure that the binary file can be run in an environment where Python is not installed on the system through the second shell script
[0050] Optionally, after the first shell script is used to treat the Python compressed file as a byte stream and splices it with the second shell script as a file header to obtain a spliced file, the method further includes: checking the spliced file and saving the spliced file that passes the check. In this embodiment, after the splicing is completed, the spliced file is checked to ensure its integrity and correctness. This may include verifying the file size, checking and / or attempting to execute the second shell script to ensure that it can correctly start the portable Python interpreter.
[0051] Among them, checking the integrity of the file includes: calculating the checksum: in the first shell script, calculating the first checksum of the second shell script and the Python compressed file before splicing, such as MD5, SHA-1, SHA-256, etc. After the splicing is completed, calculating the second checksum of the spliced file again; comparing the checksum of each file before splicing with the checksum of the spliced file to ensure that the data is not lost or damaged during the splicing process.
[0052] Compare checksums: Compare the checksums of the individual files before splicing with the checksums of the spliced files to ensure that no data is lost or damaged during the splicing process.
[0053] 204. Grant executable permission to the spliced file and name it to obtain the target Python file.
[0054] After the spliced file is generated, the spliced file is given executable permissions and named as required. In Linux / Unix systems, the chmod+ command can be used to give the file execution permissions. In this embodiment, the target Python file becomes an independent, executable unit, and the user can run it directly on a system without pre-installing the Python runtime, without manually decompressing or configuring the Python environment.
[0055] 205. Obtain the path for executing the spliced file through the second shell script in the target Python file.
[0056] Specifically, the second shell script in the target Python file automatically obtains its execution path, and usually uses $0 to obtain the path of the current script.
[0057] In some cases, such as when executing a script with a relative path, $0 may not contain the full path to the script. To ensure that the full path is obtained, some additional commands can be used to handle it, such as realpath or readlink -f.
[0058] 206. Extract the portable Python runtime in the concatenated file into a temporary directory.
[0059] Specifically, the Python runtime environment in the concatenated file will be extracted and stored in a temporary directory, ready to be started.
[0060] 207. Start the main process through the Python interpreter in the temporary directory according to the path of the spliced file.
[0061] Specifically, the process image is replaced through the Python interpreter in the temporary directory; the path of the spliced file is passed to the Python interpreter as a command line parameter and executed.
[0062] In this embodiment, the process of Bazel building Python files is improved, solving the problems of traditional Python binary file execution complexity, system environment configuration requirements and executability. By configuring Bazel's Python tool chain, the Python project and its dependencies are packaged as compressed files, and the second shell script is innovatively injected as the file header, the direct executability of the spliced files is achieved, which significantly improves the portability, compatibility and ease of use of the Python project, so that the final built Python file can be directly executed in various system environments without additional environment configuration and installation steps. The software release and operation process is simplified, greatly improving the user experience and system deployment efficiency.
[0063] The above describes the method for building Python files based on Bazel in this application. The following describes the device for building Python files based on Bazel in this application. Figure 3 , an embodiment of a device for building Python files based on Bazel in this application includes:
[0064] A configuration module 301 is used to configure Bazel's Python toolchain according to a portable Python runtime for a Python project;
[0065] A construction module 302 is used to construct a Python compressed file from the source code of the Python project and its dependent Python library code, the portable Python runtime and the code entry file through the Python tool chain of Bazel;
[0066] A file header injection module 303 is used to inject a preset second shell script into the file header of the Python compressed file through a preset first shell script in the Python tool chain of Bazel to obtain a spliced file, wherein the second shell script can replace the image executing its process with the Python interpreter of the portable Python runtime, and pass the path of the spliced file as a command line parameter to the Python interpreter;
[0067] The processing module 304 is used to grant executable permissions to the spliced file and name it to obtain a target Python file.
[0068] In this embodiment, the process of Bazel building Python files is improved, solving the problems of traditional Python binary file execution complexity, system environment configuration requirements and executability. By configuring Bazel's Python tool chain, the Python project and its dependencies are packaged as compressed files, and the second shell script is innovatively injected as the file header, the direct executability of the spliced files is achieved, which significantly improves the portability, compatibility and ease of use of the Python project, so that the final built Python file can be directly executed in various system environments without additional environment configuration and installation steps. The software release and operation process is simplified, greatly improving the user experience and system deployment efficiency.
[0069] See also Figure 4 Another embodiment of the device for building Python files based on Bazel in the present application includes:
[0070] A configuration module 301 is used to configure Bazel's Python toolchain according to a portable Python runtime for a Python project;
[0071] A construction module 302 is used to construct a Python compressed file from the source code of the Python project and its dependent Python library code, the portable Python runtime and the code entry file through the Python tool chain of Bazel;
[0072] A file header injection module 303 is used to inject a preset second shell script into the file header of the Python compressed file through a preset first shell script in the Python tool chain of Bazel to obtain a spliced file, wherein the second shell script can replace the image executing its process with the Python interpreter of the portable Python runtime, and pass the path of the spliced file as a command line parameter to the Python interpreter;
[0073] The processing module 304 is used to grant executable permissions to the spliced file and name it to obtain a target Python file.
[0074] Optionally, the configuration module 301 is specifically used to: configure the interpreter properties of the Python tool chain according to the Python interpreter in the portable Python runtime;
[0075] Configure the Python toolchain's file property to contain a Bazel file group consisting of all the files in the portable Python runtime.
[0076] Optionally, the building module 302 is specifically used to: extract the source code of the Python project and its dependent Python library code and portable Python runtime from the Python tool chain of Bazel to obtain a Python project combination file;
[0077] Compress the Python combination file and the code entry file to obtain a Python compressed file.
[0078] Optionally, the file header injection module 303 includes: a splicing unit 3031, which is used to use the first shell script to take the Python compressed file as a byte stream and splice it with the second shell script as the file header to obtain a spliced file.
[0079] Optionally, the file header injection module 303 further includes: an inspection unit 3032, which is used to inspect the spliced file and save the spliced file that passes the inspection.
[0080] The apparatus for building Python files based on Bazel also includes: a deployment module 305, which is used to obtain a path for executing the spliced file through a second shell script in the target Python file;
[0081] Unpack the portable Python runtime in the concatenated file into a temporary directory;
[0082] The main process is started through the Python interpreter in the temporary directory according to the path of the spliced file.
[0083] The deployment module 305 is specifically used to: replace the process image through the Python interpreter in the temporary directory;
[0084] Pass the path to the concatenated file as a command line argument to the Python interpreter and execute it.
[0085] In this embodiment, the process of Bazel building Python files is improved, solving the problems of traditional Python binary file execution complexity, system environment configuration requirements and executability. By configuring Bazel's Python tool chain, the Python project and its dependencies are packaged as compressed files, and the second shell script is innovatively injected as the file header, the direct executability of the spliced files is achieved, which significantly improves the portability, compatibility and ease of use of the Python project, so that the final built Python file can be directly executed in various system environments without additional environment configuration and installation steps. The software release and operation process is simplified, greatly improving the user experience and system deployment efficiency.
[0086] above Figure 3 and Figure 4 The device for building Python files based on Bazel in the present application is described in detail from the perspective of modular functional entities. The device for building Python files based on Bazel in the present application is described in detail from the perspective of hardware processing.
[0087] See also Figure 5 As shown, the device for building Python files based on Bazel includes a processor 500 and a memory 501. The memory 501 stores machine executable instructions that can be executed by the processor 500. The processor 500 executes the machine executable instructions to implement the above-mentioned method for building Python files based on Bazel.
[0088] further, Figure 5 The device for building Python files based on Bazel shown also includes a bus 502 and a communication interface 503 , and the processor 500 , the communication interface 503 and the memory 501 are connected via the bus 502 .
[0089] The memory 501 may include a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), for example, at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 503 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 502 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0090] The processor 500 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 500. The above processor 500 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as a hardware decoding processor to be executed, or a combination of hardware and software modules in the decoding processor can be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 501 , and the processor 500 reads the information in the memory 501 and completes the method steps of the above-mentioned embodiment in combination with its hardware.
[0091] The present application also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes the steps of the method for building Python files based on Bazel.
[0092] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0093] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0094] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for building Python files based on Bazel, characterized in that: include: Configure Bazel's Python toolchain based on the portable Python runtime for your Python project; Using the Bazel Python tool chain, the source code of the Python project and its dependent Python library code, the portable Python runtime and the code entry file are used to build a Python compressed file; Injecting a preset second shell script into the file header of the Python compressed file through a preset first shell script in the Python tool chain of Bazel to obtain a spliced file, wherein the second shell script can replace the image executing its process with the Python interpreter of the portable Python runtime, and pass the path of the spliced file as a command line parameter to the Python interpreter; The spliced file is given executable permission and named to obtain a target Python file.
2. The method for building Python files based on Bazel according to claim 1, characterized in that: Configure Bazel's Python toolchain based on the portable Python runtime for Python projects, including: configuring interpreter properties of the Python toolchain according to the Python interpreter in the portable Python runtime; Configure the file property of the Python toolchain to contain a Bazel file group consisting of all files in the portable Python runtime.
3. The method for building Python files based on Bazel according to claim 1, characterized in that: The method of using the Bazel Python tool chain to construct a Python compressed file from the source code of the Python project and its dependent Python library code, the portable Python runtime and the code entry file includes: Extract the source code of the Python project and its dependent Python library code and the portable Python runtime from the Bazel Python tool chain to obtain a Python project combination file; The Python combination file and the code entry file are compressed to obtain a Python compressed file.
4. The method for building Python files based on Bazel according to claim 1, characterized in that: The method of injecting a preset second shell script into the file header of the Python compressed file through a preset first shell script in the Bazel Python tool chain to obtain a spliced file includes: The Python compressed file is used as a byte stream by the first shell script, and is spliced with the second shell script as a file header to obtain a spliced file.
5. The method for building Python files based on Bazel according to claim 4, further comprising: after the first shell script is used to take the Python compressed file as a byte stream and to splice it with the second shell script as a file header to obtain the spliced file: The spliced files are checked, and the spliced files that pass the check are saved.
6. The method for building Python files based on Bazel according to any one of claims 1 to 5, characterized in that: After granting the executable permission to the spliced file and naming it to obtain the target Python file, it also includes: Obtaining a path for executing the spliced file through a second shell script in the target Python file; Unpack the portable Python runtime in the concatenated file into a temporary directory; The main process is started by the Python interpreter in the temporary directory according to the path of the spliced file.
7. The method for building Python files based on Bazel according to claim 6, characterized in that: The starting of the main process according to the path of the spliced file by the Python interpreter in the temporary directory includes: Performing process image replacement via the Python interpreter in the temporary directory; The path of the spliced file is passed as a command line parameter to the Python interpreter and executed.
8. A device for building Python files based on Bazel, characterized in that: The device for building Python files based on Bazel includes: A configuration module for configuring Bazel's Python toolchain based on a portable Python runtime for Python projects; A building module, used to build a Python compressed file from the source code of the Python project and its dependent Python library code, the portable Python runtime and the code entry file through the Bazel Python tool chain; A file header injection module, used for injecting a preset second shell script into the file header of the Python compressed file through a preset first shell script in the Python tool chain of Bazel to obtain a spliced file, wherein the second shell script can replace the image executing its process with the Python interpreter of the portable Python runtime, and pass the path of the spliced file as a command line parameter to the Python interpreter; The processing module is used to grant executable permission to the spliced file and name it to obtain a target Python file.
9. A device for building Python files based on Bazel, characterized in that: The device for building Python files based on Bazel includes: a memory and at least one processor, wherein instructions are stored in the memory; The at least one processor calls the instructions in the memory to enable the device for building Python files based on Bazel to perform the method for building Python files based on Bazel as described in any one of claims 1-7.
10. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instruction is read and executed, the method for building Python files based on Bazel as described in any one of claims 1 to 7 is executed.