Skip to content

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
devin/1778304462-web-interfacefrom
devin/1778438906-pycharm-run
Open

Add IDE-friendly entry point so PyCharm can run the app without CLI#2
devin-ai-integration[bot] wants to merge 2 commits into
devin/1778304462-web-interfacefrom
devin/1778438906-pycharm-run

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented May 10, 2026

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 to sys.path, imports app.main:app directly, and hands the FastAPI instance to uvicorn.run(...) so import resolution doesn't depend on PyCharm's working directory. Reads SCANNER_HOST, SCANNER_PORT, SCANNER_OPEN_BROWSER env 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 via webbrowser.open_new_tab.
  • .run/Scanner.run.xml — shared PyCharm run configuration that points at run.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 in pyproject.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.

Stacked on top of #1 (devin/1778304462-web-interface), so this PR's base is that branch, not main. Once PR #1 lands, GitHub will auto-retarget this to main.

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 to uvicorn.run made 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:

  1. Prepend Path(__file__).resolve().parent to sys.path before importing anything from app.
  2. Import app.main:app directly at module load time.
  3. Pass the FastAPI instance to uvicorn.run(app, ...) instead of the import string.

Smoke-tested locally by launching run.py from a different cwd (/tmp) — uvicorn now boots correctly regardless of the working directory.

Review & Testing Checklist for Human

  • Most important: open the project in a fresh PyCharm, point it at a Python 3.10+ interpreter, and confirm the bundled Scanner run configuration appears in the top-right dropdown and starts the app on click without the previous Could not import module "app.main" error. The run config uses IS_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".
  • Confirm PyCharm's "Install requirements" banner picks up requirements.txt automatically on first open and successfully installs the deps; if not, pip install -r requirements.txt should work as a manual fallback.
  • Verify the auto-opened browser tab actually loads the dashboard (the 1.5s warm-up delay is a guess — slow first-import machines may race).
  • Sanity-check that requirements.txt versions still satisfy pyproject.toml if/when the latter changes — they will drift over time since this isn't a lockfile export.

Notes

  • No app code (app/main.py, app/scanner.py, static files) was touched — the existing poetry run uvicorn app.main:app workflow is unchanged.
  • Existing GitHub Actions workflow is the blank blank.yml, so CI passing here proves nothing about the IDE flow specifically.
  • webbrowser.open_new_tab will silently no-op on headless systems; that's intentional (failure is caught and logged) so the server keeps running.
  • Switched from passing an import string to passing the FastAPI app instance, so reload=True is 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

- 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>
@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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>
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

Successfully merging this pull request may close these issues.

1 participant