Add IDE-friendly entry point so PyCharm can run the app without CLI#2
Open
devin-ai-integration[bot] wants to merge 2 commits into
Open
Conversation
- run.py: starts uvicorn programmatically and opens a browser tab so the app can be launched with PyCharm's green Run button (no terminal). - .run/Scanner.run.xml: shared PyCharm run configuration pointing at run.py. - requirements.txt: pip-installable dependency list mirroring pyproject.toml for users who don't want to install Poetry. - README: documents the IDE-only workflow (Option A) alongside the existing CLI workflow (Option B). Co-Authored-By: harlequincariotta <harlequincariotta@wshu.net>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
PyCharm's run configurations can launch run.py with a working directory that doesn't put the project root on sys.path, which made uvicorn fail with 'Could not import module app.main'. Now run.py prepends the repo root to sys.path and passes the FastAPI instance to uvicorn directly, so the resolution doesn't depend on cwd. Co-Authored-By: harlequincariotta <harlequincariotta@wshu.net>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lets users start the scanner web app straight from PyCharm's green ▶ button — no terminal, no Poetry required.
run.py— programmatic uvicorn entry point. Prepends the repo root tosys.path, importsapp.main:appdirectly, and hands the FastAPI instance touvicorn.run(...)so import resolution doesn't depend on PyCharm's working directory. ReadsSCANNER_HOST,SCANNER_PORT,SCANNER_OPEN_BROWSERenv vars (defaults:127.0.0.1,8000, on). When the browser flag is on, a daemon thread waits ~1.5s for uvicorn to bind, then opens the dashboard tab viawebbrowser.open_new_tab..run/Scanner.run.xml— shared PyCharm run configuration that points atrun.py, so the Scanner entry shows up in the run-configurations dropdown immediately after the project is opened.requirements.txt— pip-installable mirror of the runtime deps inpyproject.toml(fastapi,uvicorn,httpx). Lets PyCharm's "Install all packages" prompt work for users who don't want to install Poetry.README.md— documents the new "Option A — From PyCharm" flow alongside the existing CLI flow.Updates since last revision
A user report on the first revision surfaced
ERROR: Error loading ASGI app. Could not import module "app.main".when launched from PyCharm. Root cause: passing the"app.main:app"import string touvicorn.runmade uvicorn re-resolve the module through its own import machinery, which fails when PyCharm's working directory or interpreter PYTHONPATH doesn't include the project root. Fix in this revision:Path(__file__).resolve().parenttosys.pathbefore importing anything fromapp.app.main:appdirectly at module load time.uvicorn.run(app, ...)instead of the import string.Smoke-tested locally by launching
run.pyfrom a different cwd (/tmp) — uvicorn now boots correctly regardless of the working directory.Review & Testing Checklist for Human
Could not import module "app.main"error. The run config usesIS_MODULE_SDK="true"and<module name="scanner" />— if PyCharm imports the project under a different module name, the SDK reference may not resolve and you may need to re-pick the interpreter under "Edit Configurations".requirements.txtautomatically on first open and successfully installs the deps; if not,pip install -r requirements.txtshould work as a manual fallback.requirements.txtversions still satisfypyproject.tomlif/when the latter changes — they will drift over time since this isn't a lockfile export.Notes
app/main.py,app/scanner.py, static files) was touched — the existingpoetry run uvicorn app.main:appworkflow is unchanged.blank.yml, so CI passing here proves nothing about the IDE flow specifically.webbrowser.open_new_tabwill silently no-op on headless systems; that's intentional (failure is caught and logged) so the server keeps running.reload=Trueis no longer applicable; this isn't an issue here because reload was already disabled.Link to Devin session: https://app.devin.ai/sessions/2eb7aa7344844b0a841c827cba7ab0fa
Requested by: @evgetos