一句话:提出 PyCRE,利用领域知识图谱与冲突感知启发式依赖求解,自动推断 Python 兼容运行时环境。
开源 Python 代码数量庞大,但恢复可成功运行的运行时环境仍然困难。已有基于预构建知识库的依赖推断工作覆盖知识不足,且忽略推断依赖之间的潜在冲突,导致推断成功率偏低。本文提出 PyCRE:为 Python 第三方包设计领域本体,并为 Python 2 和 Python 3 中超过一万个热门包构建知识图谱;通过度量已知库与目标代码所用第三方资源的匹配程度来发现候选库;针对 NP 完全的依赖求解问题,提出启发式图遍历算法,以高效保证包与包之间的兼容性。在真实数据集上,PyCRE 取得优于先前方法的性能,并能多解决近一半的 import 错误。
Code sharing and reuse is a widespread use practice in software engineering. Although a vast amount of open-source Python code is accessible on many online platforms, programmers often find it difficult to restore a successful runtime environment. Previous studies validated automatic inference of Python dependencies using pre-built knowledge bases. However, these studies do not cover sufficient knowledge to accurately match the Python code and also ignore the potential conflicts between their inferred dependencies, thus resulting in a low success rate of inference. In this paper, we propose PyCRE, a new approach to automatically inferring Python compatible runtime environments with domain knowledge graph (KG). Specifically, we design a domain-specific ontology for Python third-party packages and construct KGs for over 10,000 popular packages in Python 2 and Python 3. PyCRE discovers candidate libraries by measuring the matching degree between the known libraries and the third-party resources used in target code. For the NP-complete problem of dependency solving, we propose a heuristic graph traversal algorithm to efficiently guarantee the compatibility between packages. PyCRE achieves superior performance on a real-world dataset and efficiently resolves nearly half more import errors than previous methods.