A Python project dependency conflict detection and resolution method and device
By constructing a multi-source knowledge graph and applying a graph search algorithm, the problem of insufficient knowledge data and information association in the Python library dependency conflict detection method is solved, and the rapid and accurate detection and resolution of Python project dependency conflicts is achieved, improving research efficiency and project stability. sex.
Patent Information
- Application Number
- CN202411009376.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2044-07-26
AI Technical Summary
Existing Python library dependency conflict detection methods cannot comprehensively detect and resolve undocumented version restrictions or problems involving other components, resulting in poor detection results and inability to effectively improve the stability and maintainability of Python projects.
By building a multi-source knowledge graph containing library and version information, combined with the T5 model and Neo4j technology, we analyze the library dependencies and version compatibility of Python projects, and apply graph search algorithms to recommend solutions to achieve rapid and accurate detection of dependency conflicts in Python projects. and resolve.
This method can more comprehensively understand the dependencies of Python projects, improve the accuracy of conflict detection and resolution, save researchers time, improve research efficiency, and promote the development of the field.
Smart Images

Figure CN118550546B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of Python dependency conflict detection and resolution, and in particular to a Python project dependency conflict detection and resolution method and device. Background Art
[0002] With the continuous development of the Python ecosystem, the widespread use of third-party libraries has made the dependencies between projects more and more complex. This not only increases the maintenance cost of the project, but also may lead to dependency conflicts. Dependency conflicts refer to version incompatibility issues between different libraries or modules in a project, which causes the project to fail to run properly. Solving dependency conflicts is a huge challenge for developers and requires a lot of time and effort. In order to solve this problem, developers need to have a deep understanding of the dependencies and version compatibility of the library and take relevant measures to avoid conflicts. Therefore, detecting and resolving Python dependency conflicts has become a task that urgently requires the attention of developers. Only by deeply understanding the dependencies of Python third-party libraries, adopting appropriate dependency management strategies, and applying advanced and efficient tools and technologies can this problem be effectively solved and the stability and maintainability of Python projects be improved.
[0003] At present, researchers mainly use two methods in the research process of Python library dependency conflict detection and resolution: one method is to build a relational dependency graph of Python libraries containing library and version information, detect potential dependency conflict problems by analyzing the dependency graph, and convert the version constraint problem into a logical expression. Then use the SMT solver to check the satisfiability of the logical expression, and find one of the feasible solutions in a set of constraints to determine the available version allocation for each library. Another method is to develop a domain-specific knowledge graph for third-party libraries in the PyPI official website, and then build a runtime environment for new Python projects based on the knowledge graph and assist in dependency problem detection. However, existing technologies are limited to obtaining knowledge from PyPI, and these technologies cannot detect and resolve Python library dependency conflicts without documented version restrictions or problems involving other components. In response to these problems, further research and improved methods are needed to improve the effectiveness of Python library dependency conflict detection and resolution. Summary of the invention
[0004] In view of the knowledge model of Python dependency libraries constructed in the prior art, there are problems such as incomplete coverage of the considered knowledge sources and information association of each component module. A Python project dependency conflict detection and solution method and device are provided, aiming to improve the existing Python library dependency conflict detection and solution method. By establishing a multi-source knowledge graph containing library and version information, the relationship and version compatibility of libraries in Python projects can be quickly and accurately captured and analyzed, the dependency relationship in Python projects can be more comprehensively understood, and accurate conflict detection and solutions can be provided.
[0005] To achieve the above-mentioned purpose, the present invention provides the following scheme: a Python project dependency conflict detection and resolution method, the method comprising: building a knowledge graph based on collecting Python library and version information from the PyPI official website and open source platform.
[0006] Parse the target Python project to be analyzed and obtain its dependencies.
[0007] According to the library component dependencies and the dependencies in the local Python environment, the knowledge graph is applied to detect the library dependency conflicts of the target Python project to be analyzed to obtain a detection result; the detection result includes the existence of library dependency conflicts and the non-existence of library dependency conflicts.
[0008] When the detection result is that there is a library dependency conflict, a graph search algorithm is applied to the library component dependencies and the dependencies that have the library dependency conflict in the target Python project to be analyzed, and a recommended Python version and a corresponding component version are output.
[0009] Optionally, the specific process of constructing the knowledge graph includes: downloading metadata of the open source Python package from the PyPI official website.
[0010] The metadata of the Python package is parsed to obtain detailed information of the Python package; the detailed information includes the Python version, operating environment and dependencies.
[0011] Get information about library dependencies in open source platforms.
[0012] The T5 model is applied to perform compatibility judgment on the information of the library dependent components in the open source platform to obtain compatibility information; the T5 model is trained with the names and version information of two known components as input and the corresponding compatibility information as output; the compatibility information includes compatibility and incompatibility.
[0013] According to the detailed information of the Python package, the information of the library dependency components in the open source platform and the corresponding compatibility information, Neo4j is used to build a knowledge graph.
[0014] Optionally, the knowledge graph includes Python nodes, OS nodes, library nodes, driver nodes, hardware nodes and work_with relationships.
[0015] Each of the Python nodes represents a Python version and stores the name and version of the Python package as attributes; each of the OS nodes stores the name and version of the operating system as attributes; each of the library nodes stores the name and version of the Python third-party library as attributes; each of the driver nodes stores the name and version of the driver as attributes; each of the hardware nodes stores the name and version of the hardware as attributes; and each of the work_with relationships includes compatibility information and information sources.
[0016] Optionally, the open source platform includes GitHub and Stack Overflow.
[0017] Optionally, parsing the target Python project to be analyzed specifically includes: applying a dependency configuration file parsing technology to obtain a dependency library required by the target Python project to be analyzed, and obtaining a first dependency item.
[0018] An abstract syntax tree is applied to parse the source code of the target Python project to be analyzed, a second dependency is obtained, and the first dependency and the second dependency are used as dependencies of the target Python project to be analyzed.
[0019] Optionally, for the library component dependencies and the dependencies with library dependency conflicts in the target Python project to be analyzed, a graph search algorithm is applied to output a recommended Python version and a corresponding component version, specifically including: converting the library component dependencies and the dependencies with library dependency conflicts in the target Python project to be analyzed into a graph search problem.
[0020] Apply the depth-first traversal method to determine the recommended Python version and the corresponding component version.
[0021] A computer device comprises: 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 any of the above-mentioned Python project dependency conflict detection and resolution methods.
[0022] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects: The present invention discloses a knowledge-based Python project dependency conflict detection and resolution method, which can integrate knowledge from multiple sources for scientific and unified management by establishing a knowledge graph in the field of Python library dependency and converting the dependency conflict problem into a dependency graph search problem for resolution, and well solves the problems of small amount of knowledge data and small scope of information association of various component modules in the field of Python project dependency conflict research, which can save researchers time and improve research efficiency, thereby further promoting the development of this research field. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0024] Figure 1 A flowchart of a Python project dependency conflict detection and resolution method provided in Example 1 of the present invention.
[0025] Figure 2 A structural diagram of the Python project dependency conflict detection and resolution method provided in Example 1 of the present invention.
[0026] Figure 3 This is an example diagram of the ontology design of the knowledge graph of the present invention. DETAILED DESCRIPTION
[0027] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0028] The purpose of the present invention is to provide a Python project dependency conflict detection and solution method and device, aiming to improve the effect of Python library dependency conflict detection and resolution.
[0029] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0030] Example 1: Figure 1 and Figure 2As shown, the Python project dependency conflict detection and resolution method in this embodiment includes steps S1 to S4.
[0031] Step S1: Construct a knowledge graph based on collecting Python library and version information from the PyPI official website and open source platforms.
[0032] For step S1, the specific process of constructing the knowledge graph includes steps S11 to S15.
[0033] Step S11: Download metadata of the open source Python package from the PyPI official website.
[0034] Step S12: Parse the metadata of the Python package to obtain detailed information of the Python package; the detailed information includes the Python version, operating environment and dependencies.
[0035] Step S13: Obtain information about library-dependent components in the open source platform.
[0036] Step S14: Apply the T5 model to perform compatibility judgment on the information of the library dependent components in the open source platform to obtain compatibility information; the T5 model is trained with the names and version information of two known components as input and the corresponding compatibility information as output; the compatibility information includes compatibility and incompatibility.
[0037] Step S15: According to the detailed information of the Python package, the information of the library dependency components in the open source platform and the corresponding compatibility information, Neo4j is used to construct a knowledge graph.
[0038] Furthermore, the knowledge graph includes Python nodes, OS nodes, library nodes, driver nodes, hardware nodes and work_with relationships; each of the Python nodes represents a Python version, and stores the name and version of the Python package as attributes; each of the OS nodes stores the name and version of the operating system as attributes; each of the library nodes stores the name and version of the Python third-party library as attributes; each of the driver nodes stores the name and version of the driver as attributes; each of the hardware nodes stores the name and version of the hardware as attributes; and each of the work_with relationships includes compatibility information and information sources.
[0039] The open source platforms include GitHub and Stack Overflow.
[0040] In actual applications, we collect Python library and version information from multiple data sources such as the PyPI official website and open source platforms, and use graph technology to integrate this information into a unified library and component data model to establish the relationship between libraries and version compatibility. For details, see steps 1.1 to 1.4.
[0041] Step 1.1: Get the metadata of the open source package P by visiting https: / / pypi.org / pypi / P / json / , parse and store the detailed information of package P, such as version, operating environment, and dependencies, etc. Package P refers to the name of the Python package. For example, if the name of the package is pandas, then "P" is "pandas".
[0042] Step 1.2: Collect dependency-related issues from two data sources: GitHub and Stack Overflow.
[0043] 1): For GitHub projects that use Stars as the basis for popularity, we first select the top 200 most popular GitHub projects, and limit the number of forks and issues to be greater than 1,000, and issues must have a "close" label to ensure the integrity and goodness of the project; then, we manually filter the collected problem reports using the keywords "dependency conflict" and "dependency bug" to finally obtain dependency-related issues.
[0044] 2): For the Stack Overflow website, first preliminarily filter out the websites that contain Python in the tag (i.e. Tags=" <python>") is used as a candidate corpus. In addition, in order to ensure the quality and reliability of the research question posts, they are screened according to the following rules: first, the question posts with accepted answers and open discussions are extracted, and then the posts marked as acceptable answers with voting scores greater than 5 are retained; secondly, the titles or texts of the articles are screened to contain at least one of the four keywords: compatibility, version, dependency, and conflict. Obtain dependency-related question posts. Finally, information from library dependency components in the two open source platforms is obtained.
[0045] Step 1.3: In the process of extracting dependency-related components from question posts in the open source platform, you need to use prompts to determine whether the Python components are compatible. This component will accept parameters of the name and version information of the two components. After obtaining this information, you need to build a compatibility query prompt: "Is component X version Y compatible with component Z version W?". The T5 model can complete the task of converting question and answer expressions into text to text. The T5 model (Text-to-Text Transfer Transformer) is a pre-trained language model based on the Transformer architecture. The core idea of the model is to uniformly convert all text processing tasks into text-to-text conversion problems. This unified text representation method enables the T5 model to be flexibly applied to a variety of natural language processing tasks, such as text classification, named entity recognition, machine translation, dialogue generation, etc. In the knowledge question and answer task, the T5 model can provide support through its powerful language understanding and generation capabilities. Specifically, the T5 model accepts the names and version information of two components as input, trains the model through pre-training and fine-tuning, and outputs the final decision information about component compatibility. For example, the input of the knowledge question answering model (the names and version information of the two components): python3.6.5 and ubuntu16.04.4, the final output is: yes, the decision information is the yes judged by the knowledge question answering model, which also means that the two are compatible (python3.6.5, ubuntu16.04.4, compatible).
[0046] Step 1.4: According to Figure 3 The Python library dependency component knowledge graph design ontology includes Python version, third-party libraries, operating system and other components. For the acquisition and storage of multi-source data, Neo4j is used as a unified knowledge modeling tool to extract entities, relationships, attributes and rules of the knowledge graph from the processed data, and then realize knowledge fusion to build the knowledge graph. Among them, multi-source data refers to data from multiple data sources (Python official website, GitHub and Stack Overflow information).
[0047] Step S2: Parse the target Python project to be analyzed to obtain dependencies.
[0048] With respect to step S2, parsing the target Python project to be analyzed specifically includes steps S21 to S22.
[0049] Step S21: Apply dependency configuration file parsing technology to obtain the dependency libraries required in the target Python project to be analyzed, and obtain the first dependency item.
[0050] Step S22: applying an abstract syntax tree to parse the source code of the target Python project to be analyzed, obtaining a second dependency, and using the first dependency and the second dependency as dependencies of the target Python project to be analyzed.
[0051] In actual applications, the required dependency libraries in the Python project are obtained by using the technology of parsing the dependency configuration file; at the same time, the source code of the Python project is parsed using the abstract syntax tree (AST) to obtain the dependencies in the project; by executing the above steps, the dependencies in the Python project can be fully obtained, providing the necessary basis for subsequent conflict detection and repair. Specifically, as described in steps 2.1 to 2.2.
[0052] Step 2.1: When targeting a specific Python project, first analyze the two common dependency configuration files of the project: requirements.txt and setup.py.
[0053] 1): For the requirements.txt file, read the version constraints of each line of directly dependent libraries, ignore the dependencies commented with "#", and then use the library of the Python package packaging.requirements to create a Requirement class representing a specific dependency to check the version restrictions of the requirements, and finally get the corresponding library and version constraints.
[0054] 2): For the extraction of dependencies in the setup.py file, a function identical to setuptools is inserted to detect setup.py. The values of parameters such as install_requires and extra_requires are installed and printed. By dynamically executing this inserted function, the original setuptools function is intercepted, so that the version constraints of the dependent libraries can be obtained well.
[0055] Step 2.2: Considering the two main versions of Python programming language, Python2 and Python3, call the ast27 and ast libraries in Python respectively for module parsing, that is, parse the Python project source code library through the abstract syntax tree: first get the file with the suffix .py to determine whether the source code contains child nodes, then access all methods recursively access all child nodes to determine whether it is an import statement or a from...import statement, that is, use the isinstance() function to make a judgment, and finally get all imported libraries.
[0056] Step S3: Based on the library component dependencies and the dependencies in the local Python environment, the knowledge graph is applied to detect the library dependency conflicts of the target Python project to be analyzed to obtain detection results; the detection results include the existence of library dependency conflicts and the absence of library dependency conflicts.
[0057] In actual applications, the library dependency information obtained through project analysis is combined with the library component dependencies extracted from the local environment, and the knowledge graph is used for auxiliary query to detect and determine whether there is a library dependency conflict in the project. Specifically, as described in steps 3.1 to 3.2.
[0058] Step 3.1: Developers usually deploy a given Python project in a local Python environment, so it is also necessary to analyze the library dependencies in the local environment, mainly collecting version constraints such as related dependent libraries and components from the following five aspects.
[0059] 1): Third-party libraries: The local environment needs to recursively install Python third-party libraries through the default package manager pip, and collect locally installed Python packages and their versions through the use of the "pip freeze" command.
[0060] 2): Python: The Python project obtains version information by calling the "python --version" command to parse the output.
[0061] 3): Driver: Directly call the corresponding commands of each application component to collect version information of the hardware driver and toolkit, such as running the command "nvcc -v" to obtain the CUDA version.
[0062] 4): Operating system: Get the name, version, and release of the operating system by using the os.name, os.version, and os.release attributes in the Python os module. These attributes provide information about the operating system platform on which the Python code is running.
[0063] 5): Hardware: Collect hardware information by parsing the output of system commands, such as "uname -a" for CPU architecture and "nvidia -smi" for Nvidia GPU model.
[0064] Step 3.2: Based on the dependencies in the given Python project obtained in step S2 and the library component dependencies in the above local environment, query the Python project by querying the information in the knowledge graph to detect and determine whether there is a library dependency conflict problem.
[0065] In the present invention, the configuration files requirements.txt and setup.py extract other Python (package) libraries and version constraints that the Python project depends on. Taking requirements.txt as an example, the file content is: chardet==3.0.4, cycler==0.10.0, then the project dependencies are chardet 3.0.4, cycler 0.10.0.
[0066] Step S4: When the detection result is that there is a library dependency conflict, a graph search algorithm is applied to the library component dependencies and the dependencies in the target Python project to be analyzed that have library dependency conflicts, and a recommended Python version and a corresponding component version are output.
[0067] S4 specifically includes step S41 to step S42.
[0068] Step S41: converting the library component dependencies and the dependencies that have library dependency conflicts in the target Python project to be analyzed into a graph search problem.
[0069] Step S42: Apply a depth-first traversal method to determine the recommended Python version and the corresponding component version.
[0070] In actual applications, for detected library dependency conflicts, by solving the dependency library graph search problem, corresponding detection or repair suggestions are made according to the specific situation of the project with the dependency library. These suggestions may include updating the version of certain libraries or adjusting the configuration of dependency relationships. For details, see steps 4.1 to 4.2.
[0071] Step 4.1: Through the above steps, query the Python project, local environment, and the Python library component version involved in the auxiliary query in the knowledge graph to compare the version compatibility. If the dependencies of the Python project and the local environment are within the scope provided by the knowledge graph, there is no conflict. Otherwise, dependency conflicts are likely to occur.
[0072] Step 4.2: For dependency conflicts, convert the version dependency characteristics of the Python libraries and components involved into a graph search problem. If the versions are compatible, there are associated edges between them. Then, recursively search for the nearest version for comparison through depth-first traversal, select the fully connected path, and finally provide the recommended Python version and the suggestions for the component version updates involved to the developer.
[0073] Knowledge graph technology can structure heterogeneous knowledge and facilitate the construction of knowledge associations. By using a graph-based data model to capture knowledge from different data sources, it can capture information such as the topological structure and version of dependencies between software in multiple programming language ecosystems in real time. The specific process of constructing a knowledge graph in the present invention is as follows:
[0074] 1. As Figure 3 As shown, based on the node and relationship diagram designed by the ontology, the nodes and relationships are further described.
[0075] 1): Node type and attributes.
[0076] Python nodes: Each node represents a Python version and stores the name and version of the Python package as attributes.
[0077] OS Node (Operating System Node): Each node contains the name and version of the operating system stored as attributes.
[0078] Library nodes: Each node contains the name and version of a Python third-party library stored as attributes.
[0079] Driver nodes: Each node contains the name and version of the driver stored as attributes.
[0080] hardware node: Each node contains the name and version of the hardware stored as attributes.
[0081] 2): Relationship type and attributes.
[0082] work_with relationships (compatible relationships): Each relationship includes compatible information (yes / no) and information source (if it is GitHub or Stack Overflow, the source link of the post where the information was extracted) attributes.
[0083] 2. Knowledge acquisition and knowledge processing.
[0084] According to the description of step 1.1 and step 1.2, component_node.csv is the node information of two components; component_node.csv is the information of the relationship between the work_with.csv components. The key function code contents involved include:
[0085] 1): filter_knowledge(knowledge_list), the purpose of this function is to clean the knowledge list and ensure that each knowledge item in the list is in order and the version number is processed. For each knowledge item in the list, split the entity and version number into separate strings. Replace the entity name, standardize or replace the entity name with a unified format. Use the check_version function to process the version number, which may involve removing unnecessary prefixes or suffixes and keeping only the main part of the version number. Compare the names of two entities and make sure that the name of the first entity is less than the name of the second entity. If not, swap their positions. If the names of two entities are the same, an exception is thrown because they are considered to be the same entity. Return a new list containing the processed knowledge points.
[0086] 2): remove_duplicate(knowledge_list), this function is used to remove duplicates from the knowledge list. Considering the three attributes of knowledge: entity 1, entity 2, and relationship, the following operations are performed:
[0087] Create an empty list res and a list check for checking. Traverse the original knowledge list, and for each knowledge, create a tuple (knowledge[0], knowledge[1], knowledge[2]) to represent the key part of the knowledge. Return a new knowledge list without duplicates.
[0088] 3): conflict_solve(knowledge_list), this function is used to resolve conflicts in the knowledge list. Check whether there are different relationships between the same entity pairs, and perform the following operations:
[0089] Create an empty list res and a list of tuples check for checking. Traverse the original knowledge list and check if the entity pair of each knowledge point is already in check. If the entity pair is not in check, add it to check and res. If the entity pair is already in check but has the same relationship as the knowledge point in res, throw an exception because it means there is a conflict. Return a knowledge list after resolving the conflict.
[0090] 3. Knowledge fusion, integration and optimization of knowledge base.
[0091] 1): Clean the knowledge entries: Clean the merged list by calling the filter_knowledge function, including normalizing the version number and entity name, and sorting the entity name.
[0092] 2): Remove duplicates: Use the remove_duplicate function to remove duplicate entries from the cleaned knowledge list.
[0093] 3): Resolve knowledge conflicts: Call the conflict_solve function to resolve knowledge conflicts between the same entity pairs in the list, ensuring that each entity pair has only the most reliable knowledge entries.
[0094] 4): Return the integrated knowledge: Return the knowledge list final_lib_knowledge after cleaning, deduplication and conflict resolution.
[0095] 4. Knowledge storage: stored in Neo4j to facilitate subsequent dependency conflict knowledge queries.
[0096] The present invention first collects Python libraries and version information from multiple data sources such as PyPI and open source platforms to build a knowledge graph. Then, dependency configuration file parsing and AST source code parsing are used to obtain the dependency libraries required by the Python project. The library dependency information parsed by the project is combined with the library component dependencies extracted from the local environment, and the knowledge graph is used to assist in the query to detect and determine whether there is a library dependency conflict problem in the project. For the detected library dependency conflict problem, by solving the dependency library graph search problem, corresponding detection or repair suggestions are made according to the specific situation of the dependency library. These suggestions involve updating the versions of certain libraries or adjusting the configuration of dependencies. The method implements a mechanism for automatically detecting and solving dependency conflict problems in Python projects, which helps to improve development efficiency and project quality.
[0097] Embodiment 2: A computer device comprises: 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 Python project dependency conflict detection and resolution method in Embodiment 1.
[0098] It should be noted that the object information (including but not limited to object device information, object personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the present invention are all information and data authorized by the object or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0099] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided by the present invention can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided by the present invention may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided by the present invention may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0100] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0101] The principles and implementation methods of the present invention are described in this article using specific examples. The description of the above embodiments is only used to help understand the method and core idea of the present invention. At the same time, for those skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.< / python>
Claims
1. A Python project dependency conflict detection and resolution method, characterized in that: The method comprises: Build a knowledge graph by collecting Python library and version information from the PyPI official website and open source platforms; Parse the target Python project to be analyzed and obtain dependencies, including: Apply dependency configuration file parsing technology to obtain the dependency library required in the target Python project to be analyzed, and obtain the first dependency item; the dependency configuration file includes requirements.txt and setup.py; Applying an abstract syntax tree to parse the source code of the target Python project to be analyzed, obtaining a second dependency, and using the first dependency and the second dependency as dependencies of the target Python project to be analyzed; According to the library component dependencies and the dependencies in the local Python environment, the knowledge graph is applied to detect the library dependency conflicts of the target Python project to be analyzed to obtain a detection result; the detection result includes whether there is a library dependency conflict or not; When the detection result is that there is a library dependency conflict, a graph search algorithm is applied to the library component dependencies and the dependencies that have the library dependency conflict in the target Python project to be analyzed, and a recommended Python version and a corresponding component version are output.
2. The Python project dependency conflict detection and resolution method according to claim 1, characterized in that: The specific process of building a knowledge graph includes: Download the metadata of the open source Python package from the PyPI official website; Parsing the metadata of the Python package to obtain detailed information of the Python package; the detailed information includes Python version, operating environment and dependencies; Get information about library dependencies in open source platforms; Applying the T5 model to perform compatibility judgment on the information of the library dependent components in the open source platform to obtain compatibility information; the T5 model is trained by taking the names and version information of two known components as input and the corresponding compatibility information as output; the compatibility information includes compatibility and incompatibility; According to the detailed information of the Python package, the information of the library dependency components in the open source platform and the corresponding compatibility information, Neo4j is used to build a knowledge graph.
3. The Python project dependency conflict detection and resolution method according to claim 1, characterized in that: The knowledge graph includes Python nodes, OS nodes, library nodes, driver nodes, hardware nodes and work_with relationships; Each of the Python nodes represents a Python version and stores the name and version of the Python package as attributes; Each of the OS nodes stores the name and version of the operating system as attributes; Each of the library nodes stores the name and version of the Python third-party library as attributes; Each of the driver nodes stores the driver name and version as attributes; Each of the hardware nodes stores the name and version of the hardware as attributes; each of the work_with relations includes compatibility information and information source.
4. The Python project dependency conflict detection and resolution method according to claim 1, characterized in that: The open source platforms include GitHub and Stack Overflow.
5. The Python project dependency conflict detection and resolution method according to claim 1, characterized in that: For the library component dependencies and the dependencies that have library dependency conflicts in the target Python project to be analyzed, a graph search algorithm is applied to output the recommended Python version and the corresponding component version, specifically including: Converting the library component dependencies and the dependencies in the target Python project to be analyzed that have library dependency conflicts into a graph search problem; Apply the depth-first traversal method to determine the recommended Python version and the corresponding component version.
6. A computer device comprising: 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 Python project dependency conflict detection and resolution method described in any one of claims 1-5.
