Python third-party package handling methods, devices, storage media and equipment

By detecting whether a Python third-party package contains a basic information folder and obtaining the module name using specified files or package configuration parameters, the problem of users having difficulty identifying package names is solved, thus improving development efficiency.

CN115509600BActive Publication Date: 2025-10-31QI-ANXIN LEGENDSEC INFORMATION TECH (BEIJING) INC +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211281737.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-10-19
Publication Date
2025-10-31
Estimated Expiration
2042-10-19

AI Technical Summary

Technical Problem

In existing technologies, users have difficulty accurately identifying the package names of modules that Python third-party packages depend on, resulting in low development efficiency.

Method used

The analysis detects whether the package to be analyzed contains a basic information folder. If it does, the module name is obtained by reading the specified file. If it does not, the package configuration parameters are obtained, and the module name is obtained using an abstract syntax tree or other methods. The correspondence between the package name and the module name is recorded.

Benefits of technology

It enables automatic extraction of module names corresponding to third-party Python packages, helping users accurately identify the package names of dependent modules and improving development efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115509600B_ABST
    Figure CN115509600B_ABST
Patent Text Reader

Abstract

This application provides a method, apparatus, storage medium, and device for processing Python third-party packages. In this method, for packages to be analyzed that contain a basic information folder, the corresponding module name is obtained by reading a specified file within the basic information folder. For packages to be analyzed that do not contain a basic information folder, package configuration parameters are obtained through an abstract syntax tree, and then the corresponding module name is obtained based on these parameters. The correspondence between package names and module names is recorded to facilitate user development. This automatic extraction of module names from Python third-party packages helps users accurately identify the package names of modules that a package depends on, thereby improving development efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and more specifically, to a method, apparatus, storage medium, and device for processing Python third-party packages. Background Technology

[0002] Python is an object-oriented, interpreted programming language that has gained widespread recognition in industry and academia for its concise syntax, rich community, and powerful cross-platform capabilities. When developing in Python, it's often necessary to use third-party packages. However, because the names of third-party packages and their contained modules may differ, users often need to guess and install possible packages if a third-party package imports other modules, leading to low development efficiency. Summary of the Invention

[0003] The purpose of this application is to provide a Python third-party package processing method, apparatus, storage medium, and device to solve the problem in the related art where users have difficulty accurately identifying the third-party package names corresponding to the modules that a package depends on, resulting in low development efficiency.

[0004] In a first aspect, an embodiment of this application provides a method for processing third-party Python packages, including:

[0005] Check if the package to be analyzed contains a basic information folder;

[0006] If the package to be analyzed contains a basic information folder, the module name corresponding to the package to be analyzed is obtained by reading a specified file in the basic information folder;

[0007] If the package to be analyzed does not contain a basic information folder, obtain the package configuration parameters, and obtain the module name corresponding to the package to be analyzed based on the package configuration parameters;

[0008] Record the correspondence between the package name and module name of the package to be analyzed.

[0009] In the above implementation process, for packages to be analyzed that contain a basic information folder, the corresponding module name is obtained by reading a specified file in the basic information folder. For packages to be analyzed that do not contain a basic information folder, the package configuration parameters are obtained, and then the corresponding module name is obtained based on the package configuration parameters. The correspondence between the package name and module name of the package to be analyzed is then recorded to facilitate user development. In this way, the automatic extraction of module names corresponding to third-party Python packages helps users accurately identify the package names of modules that a package depends on, thereby improving user development efficiency.

[0010] Furthermore, in some embodiments, obtaining the package configuration parameters includes:

[0011] Package configuration parameters are obtained through an abstract syntax tree; each node of the abstract syntax tree represents a structure in the source code of the package to be analyzed; the package configuration parameters correspond to one of the nodes of the abstract syntax tree.

[0012] In the above implementation process, a solution is provided for obtaining package configuration parameters, namely, obtaining them through the abstract syntax tree of the package to be analyzed.

[0013] Furthermore, in some embodiments, the abstract syntax tree is obtained based on the following method:

[0014] The package to be analyzed is decompressed, and the source code of the package to be analyzed is obtained from the decompressed contents;

[0015] The source code is converted into an abstract syntax tree using the AST module.

[0016] In the above implementation process, a solution for obtaining the abstract syntax tree is provided.

[0017] Furthermore, in some embodiments, detecting whether the package to be analyzed contains a basic information folder includes:

[0018] Detect the packaging format of the package to be analyzed;

[0019] If the package to be analyzed is in Wheel format, it is determined that the package to be analyzed contains a basic information folder.

[0020] In the above implementation process, when the package to be analyzed is a whl package, it is directly determined that the package to be analyzed contains a basic information folder, thereby improving the analysis efficiency of the package to be analyzed.

[0021] Furthermore, in some embodiments, if the package to be analyzed is in Tar format, the system detects whether the package to be analyzed contains a basic information folder based on the names of all the folders contained within the package.

[0022] In the above implementation process, when the package to be analyzed is a tar package, the names of all folders contained in the package to be analyzed are first obtained, and then the basic information folder is checked based on the obtained folder names to improve the analysis efficiency of the package to be analyzed.

[0023] Furthermore, in some embodiments, the names of all folders contained in the package to be analyzed are obtained using the os.listdir function.

[0024] In the above implementation process, a solution is provided to obtain the names of all folders within a package.

[0025] Furthermore, in some embodiments, detecting whether the package to be analyzed contains a basic information folder includes:

[0026] Obtain the names of all folders contained within the package to be analyzed;

[0027] If all the folder names contain a folder name with the extension dist-info, it is determined that the package to be analyzed contains a basic information folder.

[0028] In the above implementation process, a specific solution is provided for detecting whether the package to be analyzed contains a basic information folder. That is, first obtain the names of all folders contained in the package to be analyzed, and then query whether there is a folder name with the extension dist-info, thereby determining whether the package to be analyzed contains a basic information folder.

[0029] Furthermore, in some embodiments, obtaining the module name corresponding to the package to be analyzed based on the package configuration parameters includes:

[0030] If the value of the package configuration parameter is a package configuration search function, then all folder names are determined as the module names corresponding to the package to be analyzed.

[0031] If the value of the package configuration parameter is a list, the name recorded in the list is determined as the module name corresponding to the package to be analyzed.

[0032] In the above implementation process, Python third-party packages that do not contain basic information folders are analyzed in a systematic and automatic manner to quickly obtain the corresponding module names.

[0033] Furthermore, in some embodiments, the method further includes:

[0034] The correspondence between records can be visualized using diagrams or tables.

[0035] In the above implementation process, the correspondence of the records is visualized, so that when users are developing Python projects, they can quickly find the package name of the module they need to reference, thus improving the user experience.

[0036] Furthermore, in some embodiments, the method further includes:

[0037] When a module import error is detected, the package name corresponding to the module with the error is obtained according to the recorded correspondence, and the corresponding third-party package is installed according to the package name.

[0038] In the above implementation process, the system automatically finds the third-party packages needed by users quickly and accurately, thereby improving users' development efficiency.

[0039] Secondly, an embodiment of this application provides a Python third-party package processing device, comprising:

[0040] The detection module is used to detect whether the package to be analyzed contains a basic information folder;

[0041] The first acquisition module is used to obtain the module name corresponding to the package to be analyzed by reading a specified file in the basic information folder if the package to be analyzed contains a basic information folder;

[0042] The second acquisition module is used to acquire package configuration parameters if the package to be analyzed does not contain a basic information folder, and to acquire the module name corresponding to the package to be analyzed based on the package configuration parameters.

[0043] The recording module is used to record the correspondence between the package name and the module name of the package to be analyzed.

[0044] Thirdly, an electronic device provided in this application includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method as described in any of the first aspects.

[0045] Fourthly, embodiments of this application provide a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the method described in any of the first aspects.

[0046] Fifthly, embodiments of this application provide a computer program product that, when run on a computer, causes the computer to perform the method described in any of the first aspects.

[0047] Other features and advantages disclosed in this application will be set forth in the following description, or some features and advantages may be inferred from the description or determined without doubt, or may be learned by practicing the above-described technology disclosed in this application.

[0048] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0049] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0050] Figure 1 A flowchart illustrating the Python third-party package processing method provided in this application embodiment;

[0051] Figure 2 A schematic diagram illustrating the workflow of a host processing PyPI packets provided in an embodiment of this application;

[0052] Figure 3 A block diagram of a Python third-party package processing device provided in an embodiment of this application;

[0053] Figure 4 This is a structural block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0054] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.

[0055] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0056] As described in the background section, related technologies suffer from the problem of low development efficiency because users have difficulty accurately identifying the third-party package names corresponding to the modules that a package depends on. Therefore, this application provides a Python third-party package processing method to solve this problem.

[0057] First, some of the technical terms used in the embodiments of this application will be explained:

[0058] A module is a collection of related code organized together, building upon functions and classes. In Python, a module is a source file with the .py extension that contains Python object definitions and Python statements.

[0059] A package is a container for modules. A package can contain one or more modules. In Python, for ease of use, modules with similar functions are often grouped together, or a more complex module is broken down into multiple parts. These source code files can be placed in the same folder and managed according to Python's rules. Such a folder and the files within it are called a package.

[0060] PyPI (Python Package Index) is an official software repository for the unified distribution of third-party Python packages. Software written in Python by developers worldwide is shared in a standard package format, known as a third-party package. Users can download and install suitable third-party packages from PyPI according to their needs.

[0061] Package name: The name by which a third-party package can be searched on PyPI. Third-party packages uploaded to PyPI have unique package names.

[0062] Module name: The name of the module. When a Python third-party package is installed, all its modules are placed in the site-packages folder. Each module is a folder, and the folder name is the module name. Users need to import the module name in their code, i.e., import(module name). Only after importing a module can you use the functions or classes defined in the package in your Python code.

[0063] The embodiments of this application will be described below:

[0064] like Figure 1 As shown, Figure 1 This is a flowchart illustrating a Python third-party package processing method provided in an embodiment of this application. The method can be applied to a terminal or server. The terminal can be various electronic devices, including but not limited to smartphones, tablets, laptops, and desktop computers. The server can be a single server or a distributed server cluster composed of multiple servers. The terminal or server provides a Python data analysis environment, which includes software and hardware components. The software component mainly includes an operating system, such as Windows or Linux, while the hardware component mainly includes computing resources and storage resources, such as a CPU (Central Processing Unit), memory, and hard disk. It should be noted that the terminal / server can also be implemented as multiple software programs or software modules, or as a single software program or software module; this application does not impose any limitations on this.

[0065] The method includes:

[0066] In step 101, check whether the package to be analyzed contains a basic information folder;

[0067] The packages to be analyzed in this step are Python third-party packages. These can be downloaded locally from PyPI or obtained from other sources, such as other servers or terminals. In Python, the basic information folder usually refers to a folder with the extension dist-info. This basic information folder is generated when the Python third-party package is compiled using official tools, and the files in it record basic information such as the package author's name and contact information.

[0068] In some embodiments, this step may include: detecting the packaging format of the package to be analyzed; if the packaging format of the package to be analyzed is Wheel format, determining that the package to be analyzed contains a basic information folder. Wheel format is a mainstream packaging format for third-party Python packages, and its extension is .whl. Therefore, a package in Wheel format can also be called a .whl package. Generally speaking, a .whl package is a package that has already been compiled using official tools. Therefore, when the package to be analyzed is a .whl package, it can be directly determined that the package to be analyzed contains a basic information folder.

[0069] Furthermore, in some other embodiments, if the package to be analyzed is in Tar format, the system checks whether the package contains a basic information folder based on the names of all folders contained within it. Tar format is another mainstream packaging format for third-party Python packages, and its extension is tar; therefore, a Tar format package can also be called a tar archive. Since a tar archive may not have been compiled, when the package to be analyzed is a tar archive, the system can first obtain the names of all folders contained within it, and then check whether the package contains a basic information folder based on the obtained folder names.

[0070] Optionally, the names of all folders contained in the package to be analyzed can be obtained using the os.listdir function, which returns a list of filenames and directory names. Of course, in other embodiments, the names of all folders contained in the package to be analyzed can also be obtained using other methods, such as an Abstract Syntax Tree (AST), and this application does not impose any limitations on this.

[0071] Specifically, when the package to be analyzed is a tar archive, this step may include: obtaining all folder names contained within the package; if all folder names contain a folder name with the extension 'dist-info', then it is determined that the package contains a basic information folder. In other words, after obtaining all folder names contained within the package, it is possible to determine whether the package contains a basic information folder by querying whether any of these folder names contain a folder name with the extension 'dist-info'. Thus, by utilizing the name characteristics of the basic information folder, the detection of whether the package contains a basic information folder is achieved.

[0072] In step 102, if the package to be analyzed contains a basic information folder, the module name corresponding to the package to be analyzed is obtained by reading a specified file in the basic information folder;

[0073] Since the basic information folder records various basic information about the package, for a package with a basic information folder, the module name corresponding to that package can be obtained by reading a specified file in the basic information folder. This specified file can be the top-level information storage file, i.e., the `top_level.txt` file, which records the names of all modules that will be written to the `site-packages` folder. Therefore, by decompressing and reading this specified file, the corresponding module name can be quickly obtained.

[0074] In step 103, if the package to be analyzed does not contain a basic information folder, obtain the package configuration parameters and obtain the module name corresponding to the package to be analyzed based on the package configuration parameters;

[0075] In Python, package configuration parameters refer to the `packages` parameter. During the packaging process of third-party Python packages, package information can be specified through the configuration of the `packages` parameter. In this embodiment, for packages without a basic information folder, the package configuration parameters can be obtained, and then the module name corresponding to the package can be obtained based on the package configuration parameters. In some embodiments, the package configuration parameters can be obtained through an abstract syntax tree (AST). An abstract syntax tree, also simply called a syntax tree, is an abstract representation of the syntactic structure of source code. Therefore, each node of the AST of the package to be analyzed represents a structure in the source code of the package, and the package configuration parameters correspond to one of the nodes in the AST. Specifically, the package configuration parameters can be obtained from the installation guide file, i.e., the `setup.py` file, within the package to be analyzed through the AST.

[0076] In some embodiments, the abstract syntax tree (AST) can be obtained by: decompressing the package to be analyzed and obtaining the source code of the package from the decompressed contents; and then converting the source code into an AST using an AST module. That is, after decompressing the Python package, its source code can be accessed, and then the AST module provided by Python can be used to convert the source code into an AST structure, thereby obtaining the necessary information. Of course, in other embodiments, the AST of the package to be analyzed can also be generated by converting the source code of the package to be analyzed using other compilers; this application does not limit this.

[0077] Of course, in other embodiments, the package configuration parameters can also be obtained in other ways, such as by using a Python package management tool to simulate running the setup.py file, or by using regular expressions to match the target string constructed to search for the values ​​of the package configuration parameters, etc. This application does not limit this.

[0078] In some embodiments, obtaining the module name corresponding to the package to be analyzed based on the package configuration parameters mentioned in this step may include: if the value of the package configuration parameter is a function, determining all folder names contained within the package to be analyzed as the module name corresponding to the package; if the value of the package configuration parameter is a list, determining the names recorded in the list as the module name corresponding to the package. Based on the preceding content, all folder names contained within the package to be analyzed can be obtained through the `os.listdir` function. Since some of these folder names may not be module names, if the value of the package configuration parameter is a package configuration search function (e.g., the `find_packages` function, which is typically used to extract all folder names in a directory), then the folder names obtained through the `os.listdir` function are all module names. Conversely, if the value of the package configuration parameter is a list, then not all folder names obtained through the `os.listdir` function are module names, but the names in the list represent all module names. In this way, Python third-party packages can be analyzed systematically and automatically, thereby quickly obtaining the corresponding module names.

[0079] Building on the previous examples, if the package to be analyzed is a .whl file, it can be directly decompressed and the `top_level.txt` file within the package can be read to obtain the module name corresponding to the package. If the package to be analyzed is a .tar file, the package configuration parameters can be obtained through the abstract syntax tree, and then the module name corresponding to the package can be obtained based on the package configuration parameters. In this way, by taking appropriate processing measures according to the packaging format of the package to be analyzed, the analysis process is kept on an optimal processing path, achieving rapid extraction of the module name corresponding to the package to be analyzed.

[0080] In step 104, the correspondence between the package name and module name of the package to be analyzed is recorded.

[0081] This step refers to: after extracting the module name corresponding to the package to be analyzed, constructing and recording the correspondence between package names and module names based on the package name of the package to be analyzed and the extracted module names. Optionally, the recording method can be to create an index table, which indicates the correspondence between package names and module names. Users can retrieve the module name corresponding to a specified package name, or the package name corresponding to a specified module name, from the index table by searching for keywords.

[0082] In addition, after recording the correspondence between package names and module names, the recorded correspondence can also be visualized through graphs, tables, etc., so that users can quickly find the package name corresponding to the module they need to reference when developing Python projects.

[0083] Furthermore, in some embodiments, the method may further include: when a module import error is detected, obtaining the package name corresponding to the module with the error based on the recorded correspondence, and installing the corresponding third-party package based on the package name. When a Python third-party package imports other modules, but the package corresponding to those modules is not installed on the host, executing the code of that Python third-party package will result in an error. In this embodiment, when this situation occurs, the host knows the module name of the module with the error, and can obtain the package name corresponding to the module with the error based on the recorded correspondence, and then automatically install the corresponding third-party package based on that package name. This helps users quickly and accurately find the required third-party packages, improving their development efficiency.

[0084] In this embodiment, for packages to be analyzed that contain a basic information folder, the corresponding module name is obtained by reading a specified file within the basic information folder. For packages to be analyzed that do not contain a basic information folder, package configuration parameters are obtained, and then the corresponding module name is obtained based on these parameters. The correspondence between package names and module names is then recorded to facilitate user development. This automatic extraction of module names from Python third-party packages helps users accurately identify the package names of modules that a package depends on, thereby improving development efficiency.

[0085] To provide a more detailed explanation of the solution in this application, a specific embodiment is described below:

[0086] In this embodiment, the user develops a Python project on the host machine. In related technologies, users often need to guess the name of the PyPI package corresponding to a referenced module based on usage habits, or search for documentation provided by the package author. However, not all package authors provide documentation, which can lead to users being unable to use third-party packages. In this embodiment, the host machine can automatically extract the module name corresponding to the third-party package, thereby helping the user accurately find the package name corresponding to the module they need to reference.

[0087] In this embodiment, the host's workflow for processing PyPI packets is as follows: Figure 2 As shown, it includes:

[0088] S201. Unzip the PyPI package to be processed and check the packaging format of the PyPI package. If the PyPI package is a whl package, execute S202. If the PyPI package is a tar package, execute S203.

[0089] S202: Read the top_level.txt file in the basic information folder to obtain the module name corresponding to the PyPI package, and then execute S208.

[0090] S203. Use the os.listdir() function to get the names of all folders contained in the PyPI package;

[0091] S204. Based on all the obtained folder names, determine whether there is a basic information folder. If yes, return to S02; otherwise, execute S205.

[0092] S205. Obtain the packages parameter from the setup.py file through the abstract syntax tree. If the result is the find_packages() function, execute S206. If the result is a list, execute S207.

[0093] S206. Determine all the folder names obtained in S204 as the module names corresponding to the PyPI package, and then execute S208.

[0094] S207. Determine all names in the list as the module names corresponding to the PyPI package, and then execute S208.

[0095] S08. Based on the package name of the PyPI package and the extracted module name, construct the correspondence between the package name and the module name.

[0096] It should be noted that the two packaging formats mentioned above are the mainstream packaging formats for Python third-party packages. The solution in this embodiment is also applicable to other packaging formats. For example, for a package in Egg format, the host can process it using the same procedures as for whl packages.

[0097] Through the above steps, the host can help users accurately locate the required third-party packages. For example, when a user receives a third-party package, such as package 1, if package 1 imports module A, but the host does not have the corresponding third-party package installed, the host will report an error when executing the code in package 1. However, through the correspondence constructed in this embodiment, the host can directly provide the package name corresponding to module A, such as the name of package 2, and automatically download and install package 2 from PyPI based on that package name. In this way, the host can successfully execute the code in package 1. Therefore, the solution in this embodiment has at least the following effects: enabling users to accurately identify the third-party package names corresponding to modules that a package depends on, thus improving the user's development efficiency.

[0098] Corresponding to the embodiments of the aforementioned methods, this application also provides embodiments of a Python third-party package processing device and a terminal for its application:

[0099] like Figure 3 As shown, Figure 3 This is a block diagram of a Python third-party package processing device provided in an embodiment of this application. The device includes:

[0100] Detection module 31 is used to detect whether the package to be analyzed contains a basic information folder;

[0101] The first acquisition module 32 is used to obtain the module name corresponding to the package to be analyzed by reading a specified file in the basic information folder if the package to be analyzed contains a basic information folder;

[0102] The second acquisition module 33 is used to acquire package configuration parameters if the package to be analyzed does not contain a basic information folder, and to acquire the module name corresponding to the package to be analyzed based on the package configuration parameters.

[0103] The recording module 34 is used to record the correspondence between the package name and the module name of the package to be analyzed.

[0104] The specific implementation process of the functions and roles of each module in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.

[0105] This application also provides an electronic device, please refer to [link to application]. Figure 4 , Figure 4This is a structural block diagram of an electronic device provided in an embodiment of this application. The electronic device may include a processor 410, a communication interface 420, a memory 430, and at least one communication bus 440. The communication bus 440 is used to enable direct communication between these components. In this embodiment, the communication interface 420 of the electronic device is used for signaling or data communication with other node devices. The processor 410 may be an integrated circuit chip with signal processing capabilities.

[0106] The processor 410 described above can 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), an off-the-shelf programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor, or the processor 410 can be any conventional processor.

[0107] The memory 430 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc. The memory 430 stores computer-readable instructions. When these computer-readable instructions are executed by the processor 410, the electronic device can perform the aforementioned operations. Figures 1 to 2 The various steps involved in the method implementation examples.

[0108] Alternatively, the electronic device may also include a storage controller and an input / output unit.

[0109] The memory 430, storage controller, processor 410, peripheral interface, and input / output unit are electrically connected directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses 440. The processor 410 is used to execute executable modules stored in the memory 430, such as software function modules or computer programs included in electronic devices.

[0110] The input / output unit is used to provide users with the ability to create tasks and to set optional start periods or preset execution times for those tasks, thereby enabling user-server interaction. The input / output unit may be, but is not limited to, a mouse and keyboard.

[0111] Understandable. Figure 4 The structure shown is for illustrative purposes only; the electronic device may also include components that are more advanced than those shown. Figure 4 The more or fewer components shown, or having the same Figure 4 The different configurations shown. Figure 4 The components shown can be implemented using hardware, software, or a combination thereof.

[0112] This application also provides a storage medium storing instructions. When the instructions are run on a computer, the computer program is executed by a processor to implement the method described in the method embodiment. To avoid repetition, the method will not be described again here.

[0113] This application also provides a computer program product that, when run on a computer, causes the computer to perform the method described in the method embodiment.

[0114] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0115] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.

[0116] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0117] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application. It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.

[0118] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

[0119] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

Claims

1. A method for processing third-party Python packages, characterized in that, include: Check if the package to be analyzed contains a basic information folder; If the package to be analyzed contains a basic information folder, the module name corresponding to the package to be analyzed is obtained by reading a specified file in the basic information folder; If the package to be analyzed does not contain a basic information folder, obtain the package configuration parameters, and obtain the module name corresponding to the package to be analyzed based on the package configuration parameters; Record the correspondence between the package name and module name of the package to be analyzed; The acquisition of package configuration parameters includes: Package configuration parameters are obtained through an abstract syntax tree; each node of the abstract syntax tree represents a structure in the source code of the package to be analyzed; the package configuration parameters correspond to one of the nodes of the abstract syntax tree; The step of obtaining the module name corresponding to the package to be analyzed based on the package configuration parameters includes: If the value of the package configuration parameter is a package configuration search function, then all folder names are determined as the module names corresponding to the package to be analyzed; If the value of the package configuration parameter is a list, the name recorded in the list is determined as the module name corresponding to the package to be analyzed.

2. The method according to claim 1, characterized in that, The abstract syntax tree is obtained based on the following method: The package to be analyzed is decompressed, and the source code of the package to be analyzed is obtained from the decompressed contents; The source code is converted into an abstract syntax tree using the AST module.

3. The method according to claim 1, characterized in that, The detection of whether the package to be analyzed contains a basic information folder includes: Detect the packaging format of the package to be analyzed; If the package to be analyzed is in Wheel format, it is determined that the package to be analyzed contains a basic information folder.

4. The method according to claim 3, characterized in that If the package to be analyzed is in Tar format, the system checks whether the package contains a basic information folder based on the names of all the folders contained within it.

5. The method according to claim 4, characterized in that, The names of all folders contained in the package to be analyzed are obtained using the os.listdir function.

6. The method according to claim 4, characterized in that, The detection of whether the package to be analyzed contains a basic information folder includes: Obtain the names of all folders contained within the package to be analyzed; If all the folder names contain a folder name with the extension dist-info, it is determined that the package to be analyzed contains a basic information folder.

7. The method according to claim 1, characterized in that, The method further includes: The correspondence between records can be visualized using diagrams or tables.

8. The method according to claim 1, characterized in that The method further includes: When a module import error is detected, the package name corresponding to the module with the error is obtained according to the recorded correspondence, and the corresponding third-party package is installed according to the package name.

9. A Python third-party package processing device, characterized in that, include: The detection module is used to detect whether the package to be analyzed contains a basic information folder; The first acquisition module is used to obtain the module name corresponding to the package to be analyzed by reading a specified file in the basic information folder if the package to be analyzed contains a basic information folder; The second acquisition module is used to acquire package configuration parameters if the package to be analyzed does not contain a basic information folder, and to acquire the module name corresponding to the package to be analyzed based on the package configuration parameters. The recording module is used to record the correspondence between the package name and the module name of the package to be analyzed; The second acquisition module is specifically used to: acquire package configuration parameters through an abstract syntax tree; each node of the abstract syntax tree represents a structure in the source code of the package to be analyzed; the package configuration parameter corresponds to one of the nodes of the abstract syntax tree; If the value of the package configuration parameter is a package configuration search function, all folder names are determined as the module names corresponding to the package to be analyzed; if the value of the package configuration parameter is a list, the names recorded in the list are determined as the module names corresponding to the package to be analyzed.

10. A computer-readable storage medium, characterized in that, It stores a computer program thereon, which, when executed by a processor, implements the method as described in any one of claims 1 to 8.

11. An electronic device, characterized in that, It includes a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method as described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • Service environment modification method and device

    CN104657162A

  • Code checking method and device

    CN106371997A