Technologicat / pyan

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

Relative imports crash pyan #5

Closed Technologicat closed 3 years ago

Technologicat commented 6 years ago

Pyan does not currently support from . import foo, and crashes when it sees one.

For relative imports, the module attribute of the ImportFrom node is None.

We need to detect this case, and then also handle the level attribute, and actually figure out the correct absolute module path (at least as far as Pyan can reasonably detect) based on the relative one.

See GTS on imports.

Technologicat commented 6 years ago

Oh dear.

This is almost impossible to fix correctly given what Pyan currently knows about the code it is reading. Going for a quick hack now, to sort of support from . import foo. Maybe revisit this later.

Technologicat commented 6 years ago

Partly fixed in https://github.com/Technologicat/pyan/commit/2446676829f465ee4de1921242a9590e12d4bda5 but needs major changes for a proper fix. Leaving open for now.

Technologicat commented 4 years ago

The module dependency visualizer modvis.py (which will be packaged into an upcoming Pyan release) has preliminary support for the most common case (using the directory containing the module as the base of the relative import).

At least in my use cases it seems to work fine...

Maybe port that logic to Pyan's analyzer.py for the next release.

Technologicat commented 3 years ago

This will be fixed once we merge in #31.

Technologicat commented 3 years ago

PyPI package pyan3 updated. This should be resolved in the new 1.1.1.