PyCG
1.0.0
PYCG使用靜態分析生成Python代碼的呼叫圖。它有效地支持
您可以閱讀ICSE 2021論文的完整方法以及完整的評估。
您可以如下引用PYCG。 Vitalis Salis,Thodoris Sotiropoulos,Panos Louridas,Diomidis spinellis和Dimitris Mitropoulos。 PYCG:Python中實用的呼叫圖生成。在第43屆國際軟件工程會議上,ICSE '21 ,25-28 2021年5月25日。
PYCG已存檔。由於可用性有限,因此沒有計劃進一步改進。樂於幫助任何想要創建叉子繼續開發的人。
PYCG在Python3中實施,需要Python版本3.4或更高版本。它也沒有依賴關係。簡單地:
pip install pycg
~ >>> pycg -h
usage: __main__.py [-h] [--package PACKAGE] [--fasten] [--product PRODUCT]
[--forge FORGE] [--version VERSION] [--timestamp TIMESTAMP]
[--max-iter MAX_ITER] [--operation {call-graph,key-error}]
[--as-graph-output AS_GRAPH_OUTPUT] [-o OUTPUT]
[entry_point ...]
positional arguments:
entry_point Entry points to be processed
optional arguments:
-h, --help show this help message and exit
--package PACKAGE Package containing the code to be analyzed
--fasten Produce call graph using the FASTEN format
--product PRODUCT Package name
--forge FORGE Source the product was downloaded from
--version VERSION Version of the product
--timestamp TIMESTAMP
Timestamp of the package's version
--max-iter MAX_ITER Maximum number of iterations through source code. If not specified a fix-point iteration will be performed.
--operation {call-graph,key-error}
Operation to perform. Choose call-graph for call graph generation (default) or key-error for key error detection on dictionaries.
--as-graph-output AS_GRAPH_OUTPUT
Output for the assignment graph
-o OUTPUT, --output OUTPUT
Output path
以下命令行參數僅在證明--fasten時才應使用:
--product :包裝的名稱。--forge :來源該軟件包已從中下載。--version :軟件包的版本。--timestamp :包裝版本的時間戳。呼叫邊緣處於鄰接列表的形式,其中邊緣(src, dst)表示為dst在分配給密鑰src列表中的條目:
{
"node1": ["node2", "node3"],
"node2": ["node3"],
"node3": []
}
有關固定格式的最新描述,請參閱固定Wiki。
目前,我們正在嘗試識別Python詞典(關鍵錯誤)上潛在的無效詞典訪問。關鍵錯誤的輸出格式是包含以下字典的列表:
[{
"filename": "mod.py",
"lineno": 2,
"namespace": "mod.<dict1>",
"key": "key2"
},
{
"filename": "mod.py",
"lineno": 8,
"namespace": "mod.<dict1>",
"key": "nokey"
}]
所有入口點都是已知的,我們想要簡單的JSON格式
~ >>> pycg --package pkg_root pkg_root/module1.py pkg_root/subpackage/module2.py -o cg.json
所有入口點尚不清楚,我們想要簡單的JSON格式
~ >>> pycg --package django $(find django -type f -name "*.py") -o django.json
我們想要固定格式:
~ >>> pycg --package pypi_pkg --fasten --product "pypipkg" --forge "PyPI"
--version "0.1" --timestamp 42
pypi_pkg/module1.py pkg_root/subpackage/module2.py -o cg.json
從根目錄中,首先安裝模擬軟件包:
pip3 install mock
告訴,只需執行:
make test