Technologicat / pyan

Static call graph generator. The official Python 3 version. Development repo.
GNU General Public License v2.0
323 stars 56 forks source link

Pyan crashes when i give filename or don't give #70

Open sunil-cred opened 3 years ago

sunil-cred commented 3 years ago
pyan *.py --uses --no-defines --colored --grouped --annotated --dot >myuses.dot
Traceback (most recent call last):
  File "/home/darknight/.local/bin/pyan", line 143, in <module>
    main()
  File "/home/darknight/.local/bin/pyan", line 115, in main
    v = CallGraphVisitor(filenames, logger)
  File "/home/darknight/.local/lib/python3.8/site-packages/pyan/analyzer.py", line 60, in __init__
    mod_name = get_module_name(filename)
  File "/home/darknight/.local/lib/python3.8/site-packages/pyan/anutils.py", line 40, in get_module_name
    is_root = any([f == "__init__.py" for f in os.listdir(potential_root)])
FileNotFoundError: [Errno 2] No such file or directory: ''
mbraakhekke commented 3 years ago

Same problem. Some investigation shows that it occurs when traversing up the path to search for the root. The problem is that os.path.dirname() returns an empty string for the top of a relative path (e.g. os.path.dirname("src")). It can be avoided by specifying an absolute path to a python file. However, this has the undesired effect that the full path is also shown when annotated=True.

luisfpereira commented 3 years ago

I've seen the bug was already corrected in master. Would it be possible to make a PyPI release with the correction (1.2.1)? I know it is a small bug, but it is a pain to have to install it through github (or at least it is a pain to tell people that's also a solution). Thank you!

ani-hovhannisyan commented 2 years ago

The bug still exists in this version: pip3 install git+https://github.com/Technologicat/pyan.git But passing absolute path for the python file solved the error.

lofidevops commented 1 year ago

This was solved for me by https://github.com/Technologicat/pyan/pull/74

To install it I used pip install git+https://github.com/maciejczyzewski/pyan