briefcase
briefcase copied to clipboard
Document how to debug a Briefcase app with popular IDEs
What is the problem or limitation you are having?
briefcase dev
is the documented way to run a Briefcase app; however, the only way to debug an app with briefcase dev
is to set a breakpoint()
and use pdb. This is less than ideal, as modern IDEs provide built-in debuggers and test runners.
Describe the solution you'd like
Add documentation how to configure VSCode, PyCharm, and other common IDEs so that their native "run" and "test" mechanisms reproduce what briefcase dev
does.
The tl;dr is that you need to:
- Add every directory mentioned in
sources
to the PYTHONPATH - Set the working directory to the user's home directory
- Remove the project directory (the directory that contains pyproject.toml
from the PYTHONPATH (it's usually the first entry in
sys.path`) - Run the app name as a module (i.e., the equivalent of
python -m myapp
)
To run in test mode, you also need to add all the directories mentioned in test_sources
, plus change the runtime module to tests.myapp
.
Specifics can be found by reverse engineering src/briefcase/commands/dev.py
.
We should document the specific instructions for configuring common IDEs (at present, I'd say that means VSCode and PyCharm); but we should also document the generic requirements so that any other IDE user knows what is needed.
Describe alternatives you've considered
Continue to encourage briefcase dev
and breakpoint()
.
Additional context
Documenting manual configuration is a stop-gap measure. Longer term, it would be desirable to capture these instructions as a Briefcase plugin for VSCode and PyCharm.
Notes on PyCharm:
PyCharm has built in options for adding the content root (the "project" directory. . . usually) and the sources root to the path as part of its run function. Oddly, I cannot seem to disable the content root if I'm using the sources root. This might be a bug in pycharm.
The setting the working directory to the user's home is simple there's a field for it.
This also runs in the debugger without issue.
Testing configuration:
This was actually easier, I started with the default test runner configuration for pytest, and filled in the relevant fields. Here, the content root and sources root are actually separate check boxes and seem to work more reliably.
Anleitung für das Debugging einer BeeWare-Anwendung in Visual Studio Code:
-
Vorbereitung des Projekts:
- Stelle sicher, dass du das neueste BeeWare Briefcase und Visual Studio Code installiert hast.
- Öffne dein BeeWare-Projekt in VS Code.
-
Konfiguration der Debugging-Einstellungen:
- Gehe zu der Debug-Ansicht in VS Code (das Symbol, das wie ein Käfer aussieht, in der Sidebar).
- Erstelle eine neue
launch.json
-Datei oder bearbeite die vorhandene mit der folgenden Konfiguration:{ "version": "0.2.0", "configurations": [ { "name": "Python Debugger: Attach using Process Id", "type": "python", "request": "attach", "processId": "${command:pickProcess}", "justMyCode": true } ] }
-
Start des Debuggings:
- Gebe im integrierten Terminal von VS Code den Befehl
briefcase dev
ein, um deine BeeWare-Anwendung zu starten. - Sobald deine Anwendung läuft, drücke F5 oder klicke auf den grünen "Start Debugging"-Button in der Debug-Ansicht. Du wirst aufgefordert, den Prozess auszuwählen, den du debuggen möchtest – wähle deine BeeWare-Anwendung.
- Gebe im integrierten Terminal von VS Code den Befehl
-
Debugging:
- Nutze die Debugging-Werkzeuge von VS Code, wie Breakpoints, Schritt-für-Schritt-Execution, Variableninspektion etc., um deine Anwendung zu debuggen.
-
Beenden des Debuggings:
- Drücke Shift + F5 oder klicke auf den roten "Stop Debugging"-Button in der Debug-Ansicht, um den Debugging-Prozess zu beenden und zurück zur Entwicklungsumgebung zu gelangen.