# Buggy code
def bundle():
    clean()

    if MACOS:
        patch_dmgbuild()

    # smoke test, and build resources
    subprocess.check_call([sys.executable, "-m", APP, "--info"])
    patch_toml()

    # create
    cmd = ["briefcase", "create"] + (["--no-docker"] if LINUX else [])
    subprocess.check_call(cmd)

    time.sleep(0.5)

    add_site_packages_to_path()

    if WINDOWS:
        patch_wxs()

    # build
    cmd = ["briefcase", "build"] + (["--no-docker"] if LINUX else [])
    subprocess.check_call(cmd)

    # package
    cmd = ["briefcase", "package"]
    cmd += ["--no-sign"] if MACOS else (["--no-docker"] if LINUX else [])
    subprocess.check_call(cmd)

    # compress
    dest = make_zip()
    clean()

    with open(PYPROJECT_TOML, "w") as f:
        f.write(original_toml)

    return dest


# Traceback (RuntimeError)
C:\Users\rober>C:\Users\rober\AppData\Local\Programs\napari\python\python.exe -m napari
** On entry to DGEBAL parameter number  3 had an illegal value
** On entry to DGEHRD  parameter number  2 had an illegal value
** On entry to DORGHR DORGQR parameter number  2 had an illegal value
** On entry to DHSEQR parameter number  4 had an illegal value
** On entry to DGEBAL parameter number  3 had an illegal value
** On entry to DGEHRD  parameter number  2 had an illegal value
** On entry to DORGHR DORGQR parameter number  2 had an illegal value
** On entry to DHSEQR parameter number  4 had an illegal value
Traceback (most recent call last):
File "runpy.py", line 185, in _run_module_as_main
File "runpy.py", line 144, in _get_module_details
File "runpy.py", line 111, in _get_module_details
File "C:\Users\rober\AppData\Local\Programs\napari\\app\napari\__init__.py", line 48, in <module>
from vispy import app
File "C:\Users\rober\AppData\Local\Programs\napari\\app_packages\vispy\__init__.py", line 30, in <module>
from .util import config, set_log_level, keys, sys_info  # noqa
File "C:\Users\rober\AppData\Local\Programs\napari\\app_packages\vispy\util\__init__.py", line 9, in <module>
from .logs import logger, set_log_level, use_log_level  # noqa
File "C:\Users\rober\AppData\Local\Programs\napari\\app_packages\vispy\util\logs.py", line 14, in <module>
import numpy as np
File "C:\Users\rober\AppData\Local\Programs\napari\\app_packages\numpy\__init__.py", line 305, in <module>
_win_os_check()
File "C:\Users\rober\AppData\Local\Programs\napari\\app_packages\numpy\__init__.py", line 302, in _win_os_check
raise RuntimeError(msg.format(__file__)) from None
RuntimeError: The current Numpy installation ('C:\\Users\\rober\\AppData\\Local\\Programs\\napari\\\\app_packages\\numpy\\__init__.py') fails to pass a sanity check due to a bug in the windows runtime. See this issue for more information: https://tinyurl.com/y3dm3h86

# Fixed code
def bundle():
    clean()

    if MACOS:
        patch_dmgbuild()

    # smoke test, and build resources
    subprocess.check_call([sys.executable, "-m", APP, "--info"])

    with patched_toml():
        # create
        cmd = ["briefcase", "create"] + (["--no-docker"] if LINUX else [])
        subprocess.check_call(cmd)

        time.sleep(0.5)

        add_site_packages_to_path()

        if WINDOWS:
            patch_wxs()

    # build
    cmd = ["briefcase", "build"] + (["--no-docker"] if LINUX else [])
    subprocess.check_call(cmd)

    # package
    cmd = ["briefcase", "package"]
    cmd += ["--no-sign"] if MACOS else (["--no-docker"] if LINUX else [])
    subprocess.check_call(cmd)

    # compress
    dest = make_zip()
    clean()

    return dest