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

[Feature Request] Specify module name instead of filename #199

Open
furechan opened this issue Nov 3, 2023 · 4 comments
Open

[Feature Request] Specify module name instead of filename #199

furechan opened this issue Nov 3, 2023 · 4 comments

Comments

@furechan
Copy link

furechan commented Nov 3, 2023

Just been using this a while so it might already be possible but I couldn't find it anywhere ...

I'd like to run pydeps on some of my installed modules by specifying a module name instead of a file/folder name.

I suggest to add a flag like -m or --module to specify a module name instead of a file name. pydeps can use importlib.util.find_spec to locate the module and use this as filename.

Thanks for the great software!

@thebjorn
Copy link
Owner

thebjorn commented Nov 6, 2023

Is this just convenience functionality to not need to find the location of a module, or is there something special about modules found with find_spec?

@furechan
Copy link
Author

furechan commented Nov 7, 2023

Hi, yes it is mostly a convenience. If you have lots of packages installed, some editable some not editable, depending on which env, etc it can be a lot of work to seek them in the folder tree. Also if you want to automate some sort of reporting, it makes sense to have a central place to call pydeps independently of the location of the various project worspaces. I could create a custom wrapper around pydeps but I thought it'd more practical to have this builtin ...
Thank You

@Hnasar
Copy link

Hnasar commented Jan 19, 2024

Passing the filename can cause pydeps to incorrectly resolve imports.

If you have modules like:

a.b
a.c
c

and a/b.py has import c

then passing pydeps a/b.py --show-deps will show that import c is resolved to a/c.py which is incorrect.
(If a/b.py were to import a/c.py then it would need to do either import a.c or from . import c OR a/b.py must be run as a script (so that pythona adds a/ to sys.path)

But if we were able to run pydeps -m a.b then pydeps ought to know not to resolve import c to a/c.py.

edit: Oh I guess it resolves differently if a is a namespace package (i.e. if a/__init__.py exists or not)

@thebjorn
Copy link
Owner

Python seems to think that a/c.py is correct, ie.:

\tmp\pydeps199\src> yamldirs .
.:
  __init__.py: ''
  a:
    __init__.py: ''
    b.py: |
      print('a/b.py')
      import c
    c.py: print('a/c.py')
  c.py: print('/c.py')

Python:

\tmp\pydeps199\src> py -3.12 a\b.py
a/b.py
a/c.py

You might be running into the difference in import-behavior between scripts and imports..?

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

No branches or pull requests

3 participants