beeware / beeware/toga

Improve debugging story for Toga apps.

Open
#1,922 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
5.4k
Forks
827
Avg merge
15h 39m
Merged PRs (30d)
40

Description

### Describe the bug

The standard python debugger `pdb` trows a bit of a fit when I try to use it on a Toga app. My specific app is a bit more complicated than my steps to reproduce, but the core problem is the same as the minimal case I describe below.

`pdb` would be really helpful in learning toga because it prevents me from having to stick a bunch of `print(dir(...))` and so on into my app when I'm just trying to learn basic toga functionality.

### Steps to reproduce

1. Start from really any app, but the simplest is probably the [tutorial 0 app](https://toga.readthedocs.io/en/stable/tutorial/tutorial-0.html).
2. Add a 1/0 somewhere in the business logic of the app (I put it in the `button_handler` function but really anywhere other than before `main_loop` is called seems to do it).
3. Start the app as `python -m pdb hello.py` (I realize it's supposed to me `python -m hello` but of course that's not compatible with `pdb`, and for these apps, at least, `python hello.py` works flawlessly.
4. That leads to a traceback:
```
Traceback (most recent call last):
File "/usr/lib/python3.10/pdb.py", line 1732, in main
pdb._runscript(mainpyfile)
File "/usr/lib/python3.10/pdb.py", line 1592, in _runscript
self.run(statement)
File "/usr/lib/python3.10/bdb.py", line 597, in run
exec(cmd, globals, locals)
File "", line 1, in
File "/hello.py", line 25, in
main().main_loop()
File "/hello.py", line 21, in main
return toga.App("First App", "org.beeware.helloworld", startup=build)
File "/venv/lib/python3.10/site-packages/toga/app.py", line 227, in __init__
main_module_pkg = sys.modules["__main__"].__package__
AttributeError: module '__main__' has no attribute '__package__'

```

### Expected behavior

I expected it to give me a traceback where I put the `1/0` so I could explore live objects in the debugger to fix my buisness logic.

### Screenshots

_No response_

### Environment

- Operating System: Arch Linux
- Python version: 3.10
- Software versions:
- Briefcase: N/A
- Toga: 0.3.1

### Logs

```

```

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with the tutorial 0 app and `python -m pdb hello.py`, then inspect the initialization path in `toga/app.py` alongside the reported `pdb.py` and `bdb.py` traceback. Done means a Toga app reaches the intentional `1/0` location under pdb and exposes the live objects for inspection.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
desktop, developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.