I have the following application structure
/application
app.py
/decorators
queryAccessory.py
/auth
__init__.py
dao.py
/controllers
login.py
register.py
/models
user.py
get_user_response.py
/tests
__init__.py
dao.py
/controllers
get_tests.py
/models
test.py
get_tests_response.py
Blueprints are declared in the init.py files of the auth and tests packages.
from flask import Blueprint, request
tayyariAuth = Blueprint('tayyariAuth', __name__)
from auth.controllers import register
from auth.controllers import login
and in tests/init.py as
from flask import Blueprint, request
tayyariTests = Blueprint('tayyariTests', __name__)
from tests.controllers import get_tests
Both blueprints are registered in app.py. The problem is that the application does not start up when both init.py files have imports at the end. If I remove the last import lines from any 1 of the files, the application starts up and the registered blueprints work just fine. However, I get the following errors when the imports are there in both the init.py files
File "app.py", line 8, in <module>
from auth import tayyariAuth
File "/Users/anuragjoshi/Work/Tayyari/tayyari/tayyari-rest/auth/__init__.py", line 5, in <module>
from auth.controllers import register
File "/Users/anuragjoshi/Work/Tayyari/tayyari/tayyari-rest/auth/controllers/register.py", line 1, in <module>
from auth import tayyariAuth, dao
File "/Users/anuragjoshi/Work/Tayyari/tayyari/tayyari-rest/auth/dao.py", line 1, in <module>
from decorators.queryAccessor import Query
File "/Users/anuragjoshi/Work/Tayyari/tayyari/tayyari-rest/decorators/queryAccessor.py", line 1, in <module>
from app import session
File "/Users/anuragjoshi/Work/Tayyari/tayyari/tayyari-rest/app.py", line 9, in <module>
from tests import tayyariTests
File "/Users/anuragjoshi/Work/Tayyari/tayyari/tayyari-rest/tests/__init__.py", line 5, in <module>
from tests.controllers import get_tests
File "/Users/anuragjoshi/Work/Tayyari/tayyari/tayyari-rest/tests/controllers/get_tests.py", line 1, in <module>
from tests import tayyariTests, request, dao, TayyariEncoder
File "/Users/anuragjoshi/Work/Tayyari/tayyari/tayyari-rest/tests/dao.py", line 1, in <module>
from decorators.queryAccessor import Query
ImportError: cannot import name 'Query' from 'decorators.queryAccessor' (/Users/anuragjoshi/Work/Tayyari/tayyari/tayyari-rest/decorators/queryAccessor.py)
Please help me understand what is going on here and how can I avoid this.
Thanks in advance.