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

Provide utility functions for API strings, parameters and artifact file names. More...

Functions

def departAPI (s)
 Split API call string based on parameter passing 根据参数传递拆分API调用字符串 More...
 
def departAPI2 (s, separator='.')
 Split API call string based on separator "." 根据"."拆分API调用字符串 More...
 
def getArtifactDisplayName (artifactId)
 Return readable artifact display name 返回可读运行产物展示名 More...
 
def getArtifactHash (artifactId)
 Return artifact hash from an artifact id 从运行产物id中提取hash. More...
 
def getFileName (fileName, extension)
 Normalize and sanitize file name 规范化并清理文件名 More...
 
def getLastAPIParameter (apiStr)
 Get parameter(s) of the last API from the API call string 获取最后一个API参数 More...
 
def getParameter (p_string, separator=',', space=1)
 Split parameter string into list of separated parameters 将参数字符串拆分成单个的参数 More...
 
def removeParameter (s, flag=0)
 Remove parameter(s) from API call string 去掉API中的参数部分 More...
 
def shortenArtifactFileName (fileName, extension)
 Shorten artifact file name while preserving full hash 缩短运行产物文件名并保留完整hash. More...
 

Variables

 ARTIFACT_HASH_PATTERN = re.compile(r'(?:^|__)([0-9a-f]{64})$')
 

Detailed Description

Provide utility functions for API strings, parameters and artifact file names.

Provides API string splitting, parameter extraction, artifact hash extraction and file name normalization. 提供API字符串拆分、参数提取、运行产物hash提取和文件名规范化的工具函数。

Function Documentation

◆ departAPI()

def codeUtils.departAPI (   s)

Split API call string based on parameter passing 根据参数传递拆分API调用字符串

For example, a.b(x).c(y).d(z) --> ['a.b(x)', 'a.b(x).c(y)', 'a.b(x).c(y).d(z)'] 比如a.b(x).c(y).d(z)拆成3个API,分别是['a.b(x)', 'a.b(x).c(y)', 'a.b(x).c(y).d(z)'] 还有特殊的调用形式a.b['x'](y)

Parameters
sThe API call string
Returns
ansLst The split result

Definition at line 143 of file codeUtils.py.

Here is the caller graph for this function:

◆ departAPI2()

def codeUtils.departAPI2 (   s,
  separator = '.' 
)

Split API call string based on separator "." 根据"."拆分API调用字符串

For example, a.b(x).c(y).d(z) --> ['a', 'b(x)', 'c(y)', 'd(z)'] 比如a.b(x).c(y).d(z)拆成4个API,分别是['a', 'b(x)', 'c(y)', 'd(z)']

Parameters
sThe API call string
separatorThe separator symbol: .
Returns
ansLst The split result

Definition at line 190 of file codeUtils.py.

Here is the caller graph for this function:

◆ getArtifactDisplayName()

def codeUtils.getArtifactDisplayName (   artifactId)

Return readable artifact display name 返回可读运行产物展示名

Parameters
artifactIdThe artifact id
Returns
display name

Definition at line 33 of file codeUtils.py.

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

◆ getArtifactHash()

def codeUtils.getArtifactHash (   artifactId)

Return artifact hash from an artifact id 从运行产物id中提取hash.

Parameters
artifactIdThe artifact id
Returns
artifact hash or empty string

Definition at line 21 of file codeUtils.py.

Here is the caller graph for this function:

◆ getFileName()

def codeUtils.getFileName (   fileName,
  extension 
)

Normalize and sanitize file name 规范化并清理文件名

Parameters
fileNameTypically, the API call string or callsite artifact id is input as the file name
extensionThe extension of the file
Returns
fileName The normalized file name

Definition at line 66 of file codeUtils.py.

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

◆ getLastAPIParameter()

def codeUtils.getLastAPIParameter (   apiStr)

Get parameter(s) of the last API from the API call string 获取最后一个API参数

For example, a(x).b(x=c.d(1),y=b((1,2),5),w).c(1,2,3,4) --> 1,2,3,4 比如,a(x).b(x=c.d(1),y=b((1,2),5),w).c(1,2,3,4),获取c的参数1,2,3,4

Parameters
apiStrThe API call string
Returns
ans The parameter(s) of the last API

Definition at line 334 of file codeUtils.py.

Here is the caller graph for this function:

◆ getParameter()

def codeUtils.getParameter (   p_string,
  separator = ',',
  space = 1 
)

Split parameter string into list of separated parameters 将参数字符串拆分成单个的参数

apiName(x,y="<bold>Hello, World!</bold>",z:int,w=(p1,p2={1,(1m,23)}),device: Union[Device, int] = None, abbreviated: bool ={'a','b'}) -> str 默认按逗号进行拆分,也可按'.'进行拆分,比如a.b.c 拆分参数的时候没有考虑到x="hello,world"带冒号的情况,会错误拆成两个

Parameters
p_stringParameter string
separatorThe separator, ',' is the default value
spaceDetermine whether to remove the space in the parameter string
Returns
parameters List of separated parameters

Definition at line 244 of file codeUtils.py.

Here is the caller graph for this function:

◆ removeParameter()

def codeUtils.removeParameter (   s,
  flag = 0 
)

Remove parameter(s) from API call string 去掉API中的参数部分

For example, a.b(x,y(2)).c(z=1).d(w=[(1,2)]) --> a.b.c.d 比如a.b(x,y(2)).c(z=1).d(w=[(1,2)])变成a.b.c.d

Parameters
sThe API call string
flagDetermine remove all parameters or the last parameter for the input API call: 0 for all parameters; 1 for the last parameters
Returns
ans The API call string without parameter(s)

Definition at line 90 of file codeUtils.py.

Here is the caller graph for this function:

◆ shortenArtifactFileName()

def codeUtils.shortenArtifactFileName (   fileName,
  extension 
)

Shorten artifact file name while preserving full hash 缩短运行产物文件名并保留完整hash.

Parameters
fileNameThe artifact file stem
extensionThe extension of the file
Returns
fileName The shortened file name

Definition at line 47 of file codeUtils.py.

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

Variable Documentation

◆ ARTIFACT_HASH_PATTERN

ARTIFACT_HASH_PATTERN = re.compile(r'(?:^|__)([0-9a-f]{64})$')

Definition at line 13 of file codeUtils.py.