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

pipx.util circular import #1333

Open
adamjorr opened this issue Apr 8, 2024 · 2 comments
Open

pipx.util circular import #1333

adamjorr opened this issue Apr 8, 2024 · 2 comments

Comments

@adamjorr
Copy link

adamjorr commented Apr 8, 2024

Importing from pipx.util fails due to circular dependency unless pipx.paths is imported first. It seems pipx.util became dependent on pipx.paths in #1281. pipx.paths then tries to import pipx_wrap from pipx.util and fails.

script to repro:

import pipx.util

if __name__ == "__main__":
    print("Success!")
Traceback (most recent call last):
  File "/Users/aorr1/Library/Application Support/JetBrains/PyCharm2023.3/scratches/scratch_19.py", line 1, in <module>
    import pipx.util
  File "/Users/aorr1/Library/Caches/pypoetry/virtualenvs/project-dJ3m09UH-py3.11/lib/python3.11/site-packages/pipx/util.py", line 24, in <module>
    from pipx import paths
  File "/Users/aorr1/Library/Caches/pypoetry/virtualenvs/project-dJ3m09UH-py3.11/lib/python3.11/site-packages/pipx/paths.py", line 10, in <module>
    from pipx.util import pipx_wrap
ImportError: cannot import name 'pipx_wrap' from partially initialized module 'pipx.util' (most likely due to a circular import) (/Users/aorr1/Library/Caches/pypoetry/virtualenvs/project-dJ3m09UH-py3.11/lib/python3.11/site-packages/pipx/util.py)

Expected behavior

import succeeds

@JamesParrott
Copy link

A circular import's not ideal, but removing it probably requires refactoring.

In the mean time, is this work around not suitable?

import pipx
import pipx.util

@adamjorr
Copy link
Author

adamjorr commented Apr 9, 2024

I think import pipx still runs into the issue. import pipx.paths before import pipx.util does help.

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