Package: brbug
brBugbrBugis a tool/library to debug android BeeWare apps on Android with ease.InstallationInstall using pip:pip install brbug.pipinstallbrbugIf you want therichversion of thebrbugCLI, you can also install it using:pip install brbug[rich]If you manage your briefcase dependencies usingpyproject.toml, addbrdebugto the apprequires.UsagebrBug contains two part: the toga part and the build part.At the build instead of running your android app with:briefcaserunandroid-u-ddevice_idyou can run it with:brbug-ddevice_id(or if you want you can also disable thebriefcase runcommand using-X, and just stay with the build step like thisbrbug -X -d device_id && briefcase run ...).After you can see that in youresourcesfolder there is a file called_brbug.tar.gz.Then in your toga app use it like this:importbrbug@brbug.catch_beeappclassYourTogaApp(toga.App):That's it.
Nowbrbugwill use the.tar.gzfile to create better traceback (usingfriendly-traceback).Here is an example of better traceback with brBug :W/python.stderr:Traceback(mostrecentcalllast):W/python.stderr:File"/data/data/com.matan_h.ipython.bee_ipython/files/chaquopy/AssetFinder/requirements/brbug/brbug.py",line146,inwrapperW/python.stderr:W/python.stderr:File"/data/data/com.matan_h.ipython.bee_ipython/files/chaquopy/AssetFinder/app/bee_ipython/app.py",line38,instartupW/python.stderr:nameerrorW/python.stderr:NameError:name'nameerror'isnotdefined.Didyoumean:'NameError'?W/python.stderr:W/python.stderr:A`NameError`exceptionindicatesthatavariableorW/python.stderr:functionnameisnotknowntoPython.W/python.stderr:Mostoften,thisisbecausethereisaspellingmistake.W/python.stderr:However,sometimesitisbecausethenameisusedW/python.stderr:beforebeingdefinedorgivenavalue.W/python.stderr:Didyoumean`NameError`?W/python.stderr:Inyourprogram,noobjectwiththename`nameerror`exists.W/python.stderr:ThePythonbuiltin`NameError`hasasimilarname.W/python.stderr:compare this to the default android python crash/traceback:E/AndroidRuntime:Causedby:com.chaquo.python.PyException:NameError:name'nameerror'isnotdefinedE/AndroidRuntime:at<python>.bee_ipython.app.startup(app.py:38)E/AndroidRuntime:at<python>.toga.app._startup(app.py:624)E/AndroidRuntime:at<python>.toga_android.app.create(app.py:179)E/AndroidRuntime:at<python>.toga_android.app.main_loop(app.py:199)E/AndroidRuntime:at<python>.toga.app.main_loop(app.py:663)E/AndroidRuntime:at<python>.__main__.<module>(__main__.py:3)E/AndroidRuntime:at<python>.runpy._run_code(<frozenrunpy>:88)Supported toolsbrBug modifies theexecutingengine to work on android using thetar.gzsource.That mean, by extension it supports most debugging tools:snoop- if you don't know this yet, highly recommended - it's awesome.python-devtools.friendly-traceback - this package already provide it by default.icecream(although it doesn't look good in the android logcat view - somehow each word is in different line)How its worksChaquopy/beeware python apps are in apycstate, which mean that no line information is stored.
That cause the normal python traceback/error to look like this:Thebuildside generate.tar.gzfile of all.pyfiles in your application directory, then thetogaside open it, find the python source and modifyexecutingto use it as source.Why I need this@brbug.catch_beeapp? It cannot just catch the errors automatically?The "normal" way to catch errors is to usesys.excepthook. Unfortunatelychaquopy doesn't support it. The other way is usetry/except. But thenexecutingcame acrossapp.mainloopit crashes, as It's pretty much a java method (executing.executing.NotOneValueFound). Maybe in the future I will create amrbug.automaticmodule which detect and catch the toga app automatically.what@brbug.catch_beeappdoes?It wraps every method you defined (And not the ones that are inherited) withtry/ except : print tracebackto make it able to print traceback when a function failsFAQWhat not supportedrich.traceback- it uses the traceback object instead ofexecutingorstack_data, so I cannot support it.How to report errors/problems/suggestionsplease open aGitHub issueWhy it's named 'brBug'It's likebriefcaseBugbut no one can spell it right, sobrBug.
it also sounds likemr. Bugwhich is nice.How can I donate youIf you found this tool/library useful, it would be great if you could buy me a coffee: