Skip to content

Commit 58f4bfc

Browse files
committed
Assistant checkpoint: Fix circular import in app.py
Assistant generated file changes: - dashboard/app.py: Fix circular import by restructuring app.py --- User prompt: Running the code in my project results in the following: ``` shutdown complete. INFO: Finished server process [24838] Traceback (most recent call last): File "<string>", line 1, in <module> File "/nix/store/nb21sc3npfc8gvazwnrjxpvb5d48jysx-python3-3.12.7/lib/python3.12/multiprocessing/spawn.py", line 122, in spawn_main exitcode = _main(fd, parent_sentinel) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/nix/store/nb21sc3npfc8gvazwnrjxpvb5d48jysx-python3-3.12.7/lib/python3.12/multiprocessing/spawn.py", line 131, in _main prepare(preparation_data) File "/nix/store/nb21sc3npfc8gvazwnrjxpvb5d48jysx-python3-3.12.7/lib/python3.12/multiprocessing/spawn.py", line 246, in prepare _fixup_main_from_path(data['init_main_from_path']) File "/nix/store/nb21sc3npfc8gvazwnrjxpvb5d48jysx-python3-3.12.7/lib/python3.12/multiprocessing/spawn.py", line 297, in _fixup_main_from_path main_content = runpy.run_path(main_path, ^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen runpy>", line 287, in run_path File "<frozen runpy>", line 98, in _run_module_code File "<frozen runpy>", line 88, in _run_code File "/home/runner/workspace/dashboard/app.py", line 17, in <module> from routes import * File "/home/runner/workspace/dashboard/routes.py", line 11, in <module> from app import app, rt File "/home/runner/workspace/dashboard/app.py", line 23, in <module> app.mount("/static", StaticFiles(directory="dashboard/static"), name="static") ^^^ NameError: name 'app' is not defined ``` If applicable, propose a fix immediately. Replit-Commit-Author: Assistant Replit-Commit-Session-Id: 19ea1197-5675-46f3-a4db-16aabe4c4077
1 parent 5dc520d commit 58f4bfc

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

dashboard/app.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
"""
23
Anomstack Dashboard
34
@@ -12,16 +13,11 @@
1213
from fasthtml.common import *
1314
from monsterui.all import *
1415
from fasthtml.svg import *
15-
1616
from starlette.staticfiles import StaticFiles
17-
from routes import *
18-
from components import *
17+
1918
from constants import *
2019
from state import AppState
2120

22-
# Mount static files
23-
app.mount("/static", StaticFiles(directory="dashboard/static"), name="static")
24-
2521
# load the environment variables
2622
load_dotenv(override=True)
2723

@@ -43,6 +39,13 @@
4339
log=log,
4440
)
4541

42+
# Mount static files
43+
app.mount("/static", StaticFiles(directory="dashboard/static"), name="static")
44+
4645
app.state = AppState()
4746

48-
serve()
47+
# Import routes after app is defined
48+
from routes import *
49+
50+
if __name__ == "__main__":
51+
serve()

0 commit comments

Comments
 (0)