PCART  v1.4
Automated Repair of Python API Parameter Compatibility Issues
Classes | Functions
getDef Namespace Reference

Extract API definitions from lib source code. More...

Classes

class  RegexMatch
 Regular expression match class 正则表达式匹配类 More...
 

Functions

def getAssign (root_node)
 Extract all assign node from a .py file's AST 通过AST获取.py文件的Assign语句 More...
 
def getClass (lst, root, prefix, fileDict, pyiFlag=0, importCache=None)
 Extract class method definitions from a give class. More...
 
def getDefFunction (args)
 Extract all lib API definitions from a specified version 抽取给定版本的库API定义 More...
 
def getPublicAliasLine (line, sourceRoot, publicRoot)
 Return a public alias line for source-root API lines 为源码根路径API行生成公开路径别名 More...
 
def shortenPath (lst, fileDict, importCache=None)
 Shorten the API path based on init.py and import alias 通过解析__init__.py和import别名,把源码中的部分API路径缩短 More...
 
def task (codeText, libApi, prefix, fileDict, pyiFlag=0, importCache=None)
 Extract all lib API definitions from a source file 抽取库源码API定义任务 More...
 
def writeApiLine (fw, line, sourceRoot='', publicRoot='')
 Write one lib API line and its public alias if needed 写出一行库API,并按需写出公开路径别名 More...
 

Detailed Description

Extract API definitions from lib source code.

Extracts API definitions from library source files by parsing AST for class definitions, function definitions, and init.py assignment aliases. Handles .py/.pyi deduplication and API path shortening via init.py imports. 通过解析AST提取库源码中的类定义、函数定义和__init__.py赋值别名。处理.py/.pyi 去重,通过__init__.py导入缩短API路径。

Function Documentation

◆ getAssign()

def getDef.getAssign (   root_node)

Extract all assign node from a .py file's AST 通过AST获取.py文件的Assign语句

Parameters
root_nodeThe ast node of the .py file

Definition at line 68 of file getDef.py.

Here is the caller graph for this function:

◆ getClass()

def getDef.getClass (   lst,
  root,
  prefix,
  fileDict,
  pyiFlag = 0,
  importCache = None 
)

Extract class method definitions from a give class.

抽取类中方法定义。递归访问类中所有节点,主要解决嵌套类的问题

Parameters
lstList of lib API definitions extracted from a lib source file
rootThe class type ast node
prefixThe fully qualified name of a source file. For example, the prefix for lib/a/b/c.py is lib.a.b.c.
fileDictA file with a dictionary format {absolute path of the file: relative path of the file}. The relative path begins with the lib name, separated by "/", e.g., lib/a/b/c.py
pyiFlagA flag denotes whether the Python source file is .pyi file.
importCacheCache of init.py import mappings used to shorten API paths.

Definition at line 165 of file getDef.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDefFunction()

def getDef.getDefFunction (   args)

Extract all lib API definitions from a specified version 抽取给定版本的库API定义

Parameters
argsThe arguments include the lib name, lib version, and the lib path

Definition at line 319 of file getDef.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPublicAliasLine()

def getDef.getPublicAliasLine (   line,
  sourceRoot,
  publicRoot 
)

Return a public alias line for source-root API lines 为源码根路径API行生成公开路径别名

Parameters
lineA lib API output line
sourceRootThe source package root name, e.g., tensorflow_core
publicRootThe public package root name, e.g., tensorflow

Definition at line 285 of file getDef.py.

Here is the caller graph for this function:

◆ shortenPath()

def getDef.shortenPath (   lst,
  fileDict,
  importCache = None 
)

Shorten the API path based on init.py and import alias 通过解析__init__.py和import别名,把源码中的部分API路径缩短

缩短API路径可能会将不同文件中的API还原成相同的形式,比如A.b.f,A.c.f都还原成A.f

Parameters
lstAn API path. Initially, lst is the fully qualified API name.
fileDictA file with a dictionary format {absolute path of the file: relative path of the file}. The relative path begins with the lib name, separated by "/", e.g., lib/a/b/c.py
importCacheCache of init.py import mappings, keyed by (init path, current level).

Definition at line 104 of file getDef.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ task()

def getDef.task (   codeText,
  libApi,
  prefix,
  fileDict,
  pyiFlag = 0,
  importCache = None 
)

Extract all lib API definitions from a source file 抽取库源码API定义任务

Parameters
codeTextThe code text of a source file, read by f.read()
libApiList of lib API definitions extracted from a lib source file
prefixThe fully qualified name of a source file. For example, the prefix for lib/a/b/c.py is lib.a.b.c.
fileDictA file with a dictionary format {absolute path of the file: relative path of the file}. The relative path begins with the lib name, separated by "/", e.g., lib/a/b/c.py
pyiFlagA flag denotes whether the Python source file is .pyi file.
importCacheCache of init.py import mappings used to shorten API paths.

Definition at line 246 of file getDef.py.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writeApiLine()

def getDef.writeApiLine (   fw,
  line,
  sourceRoot = '',
  publicRoot = '' 
)

Write one lib API line and its public alias if needed 写出一行库API,并按需写出公开路径别名

Parameters
fwOutput file object
lineA lib API output line
sourceRootThe source package root name
publicRootThe public package root name

Definition at line 307 of file getDef.py.

Here is the call graph for this function:
Here is the caller graph for this function: