Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrectly attaching dependency with relative imports in submodules #162

Open
admuresan opened this issue Nov 25, 2022 · 1 comment
Open

Comments

@admuresan
Copy link

This is an issue I noticed if for example I have a sub module that imports form its relative namespace without going global.

Take for example the following module structure:

main
   |-- __init__.py
   |-- sub_modulue
       |-- __init__.py
       |-- file.py

If file.py has a line like:
from . import x

where x is defined in the __init__.py of sub_module, then the dependency solver claims that file imports the __init__.py of main not of its relative submodule.

If I change the line in file.py to:
from ..sub_module import x
it seems to correctly identify the dependency.

I like using the less specific notation since it lets me reorganize without any changes to code, but it's not a major inconvenience to change.

Great tool. I use to get an ordered list of the files in my module based on inheritance.

@thebjorn
Copy link
Owner

Hi @admuresan and thank you for your interest in pydeps.

I think there might be something else going on, although I'm not entirely sure what.

I've created a tool that converts directories to yaml and back again, which pydeps uses internally for testing, but is also great for communicating test-cases. It's available from PyPI (pip install yamldirs).

If I understand you correctly, you have this structure:

mypkg:
  __init__.py: ''
  sub_module:
    __init__.py: x = 42
    fname.py: |
      from . import x

(save it as fname.yaml and run yamldirs fname.yaml and it will extract the file structure).

I would guess that it could be related to the dummy python file that pydeps creates when running to have a starting point for analyzing your module (you can find the contents by running pydeps with the -LDEBUG flag if you're really interested..)

Could you create a yamldirs snippet that demonstrates your problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants