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

Fixed anutils.get_module_name #82

Open charmoniumQ opened 2 years ago

charmoniumQ commented 2 years ago

Before this commit, I would get the following error:

Traceback (most recent call last):
  File "/home/sam/.local/share/virtualenvs/.repos-OcsR-W1w/bin/pyan3", line 33, in <module>
    sys.exit(load_entry_point('pyan3', 'console_scripts', 'pyan3')())
  File "/home/sam/box/charmonium.cache/benchmark/.repos/pyan/pyan/main.py", line 206, in main
    v = CallGraphVisitor(filenames, logger=logger, root=root)
  File "/home/sam/box/charmonium.cache/benchmark/.repos/pyan/pyan/analyzer.py", line 60, in __init__
    mod_name = get_module_name(filename)
  File "/home/sam/box/charmonium.cache/benchmark/.repos/pyan/pyan/anutils.py", line 43, 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: ''

because directories[0][0] was:

./pudl/src/pudl/cli.py None
./pudl/src/pudl
./pudl/src
./pudl
.

After this commit, the code works as expected, because the loop stops when it finds the root.

lofidevops commented 1 year ago

@Technologicat @jdb78 Tested this via the https://github.com/aurelg/pyan/commits/master fork and can confirm it is working.