pyan icon indicating copy to clipboard operation
pyan copied to clipboard

Pyan crashes when i give filename or don't give

Open sunil-cred opened this issue 4 years ago • 4 comments

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: ''

sunil-cred avatar Mar 27 '21 10:03 sunil-cred

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.

mbraakhekke avatar May 01 '21 19:05 mbraakhekke

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!

luisfpereira avatar Jul 02 '21 14:07 luisfpereira

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.

ani-hovhannisyan avatar Oct 05 '21 02:10 ani-hovhannisyan

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

lofidevops avatar Feb 17 '23 15:02 lofidevops