SMAT-Lab / Scalpel

Scalpel: The Python Static Analysis Framework
Apache License 2.0
286 stars 43 forks source link

Failed to run call graph analysis because of pycg. #26

Closed Vancir closed 2 years ago

Vancir commented 2 years ago

scalpel only supports pycg 0.0.3 version, but the latest version of pycg is 0.0.5,

as we can see in scalpel/call_graph/pycg.py, it imports the pycg from PyPi instead of the scalpel/pycg.

from pycg.pycg import CallGraphGenerator
from pycg import formats

I run the CallGraphGenerator as following:

$ ipy
Python 3.9.8 (main, Nov 10 2021, 03:48:35)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.29.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from scalpel.call_graph.pycg import CallGraphGenerator

In [2]: cg_generator = CallGraphGenerator(["__init__.py"], "bs4")
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-b5da871ecbc4> in <module>
----> 1 cg_generator = CallGraphGenerator(["__init__.py"], "bs4")

TypeError: __init__() missing 2 required positional arguments: 'max_iter' and 'operation'

I set the max_iter to the default value 1 and set the operation to call-graph. Then it will report a new error.

Traceback (most recent call last):
  File "/Users/vancir/Documents/GitHub/Scalpel/examples/cg_tutorial.py", line 12, in <module>
    f.write(json.dumps(formatter.generate()))
  File "/opt/homebrew/lib/python3.9/site-packages/pycg-0.0.3-py3.9.egg/pycg/formats/simple.py", line 28, in generate
    output = self.cg_generator.output()
AttributeError: 'dict' object has no attribute 'output'
Jarvx commented 2 years ago

Thanks for raising this issue. As stated in our documentation, we initially hoped to wrap pycg package for call graph generation. Now that the pycg is upgrading, we will soon support the new version and then close this issue.

billquan commented 2 years ago

Hi, Sorry for the delay. We have fixed the issue and now you should be able to use CallGraphGenerator as before or enjoy the new features that PyCG provided in their newer version by supplying 'max_iter' and 'operation'. PyCG has also adjust some other APIs, e.g. formats.Simple(). For those APIs, we choose not to adjust the wrapper but to update our documentation/tutorials. formats.Simple() now takes a CallGraphGenerator object as input. Thank you for raising the issue!

Vancir commented 2 years ago

Thanks for your great efforts in supporting it.