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

Circular Imports and Import Resolution Issue in Pneuma #1

Open
ogiorgil opened this issue Aug 14, 2024 · 0 comments
Open

Circular Imports and Import Resolution Issue in Pneuma #1

ogiorgil opened this issue Aug 14, 2024 · 0 comments

Comments

@ogiorgil
Copy link
Collaborator

I am encountering two main issues related to import management:

  1. Circular Import: I want to import from a sibling package. If I do from pneuma.utils.response import Response, ResponseStatus from registration.py and try to run the script directly, ModuleNotFoundError: No module named 'pneuma' occurs. Additionally, if pneuma.py is run, ImportError: cannot import name 'Registration' from partially initialized module 'registration.registration' (most likely due to a circular import) (xxx\Pneuma\pneuma\registration\registration.py) occurs.
  2. Relative import error: If I do from ..utils.response import Response, ResponseStatus instead, ImportError: attempted relative import with no known parent package occurs, both when running the scripts directly and running pneuma.py

Below is the current simplified project structure:

pneuma/
├── __init__.py
├── registration/
│   ├── __init__.py
│   ├── registration.py
│   └── helper.py
├── utils/
│   ├── __init__.py
│   ├── response.py
└── pneuma.py

Right now, the fix is doing sys.path.append(str(Path(__file__).resolve().parent.parent)) and importing with from utils.response import Response, ResponseStatus to import from sibling packages.

Request for help:

  • Suggestions for restructuring the code to avoid circular imports.
  • Best practices for import management in this project.
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

1 participant