fiatjaf / module-linker

browse modules by clicking directly on "import" statements on GitHub
https://module-linker.fiatjaf.com/
MIT License
251 stars 20 forks source link

Relative upper-level imports are improperly linked [python] #36

Open webknjaz opened 6 years ago

webknjaz commented 6 years ago

Consider this code:

from ..models.alphaname import Alphaname
from ..forms.alphaname import AlphanameForm

from ..tasks import submitAlphanameInstantly

Module Linker creates references to:

instead of referring upper-level packages/modules.

However it successfully recognises same-package imports, like:

from .models.campaign import Campaign
from .models.task import Task
from .models.alphaname import Alphaname
from .models.message import Message
fiatjaf commented 6 years ago

Ok, I guess there's no support for double dots. Are there more than 2 dots in Python relative imports anywhere?

webknjaz commented 6 years ago

Short answer is yes, it's been copied from the working code.

One can import from higher-level packages provided that the current package is not the root. This can depend on PYTHONPATH and __init__.py.

webknjaz commented 6 years ago

Oh, I misread your question :)

No, three dots is not supported. It's like in relative paths in fs: two dots is a parent dir, single dot is current dir.

webknjaz commented 6 years ago

Looking at https://github.com/fiatjaf/module-linker/blob/d8e2601/languages/python.js#L62-L80 I'd say it should support two dots, meaning there's a bug somewhere. I've checked that regexps above work well.

webknjaz commented 6 years ago

Also, this https://github.com/fiatjaf/module-linker/blob/d8e2601/languages/python.js#L36-L39 condition looks invalid: it's never true, the code checks that the string is both empty and starts with a dot.

fiatjaf commented 6 years ago

Thank you very much for the effort, @webknjaz. I'm a little embarrassed by that never-true condition, but anyway, I'll try to fix this as soon as possible.

klntsky commented 5 years ago

Same issue with nix, see https://github.com/shlevy/nix-adt/blob/dd04b5d08eed65ecd73aafde56a78078e09f1c74/source-example.nix#L94