briefcase-debugger 0.3.26__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- briefcase_debugger/__init__.py +44 -0
- briefcase_debugger/config.py +21 -0
- briefcase_debugger/debugpy.py +108 -0
- briefcase_debugger/pdb.py +44 -0
- briefcase_debugger-0.3.26.dist-info/METADATA +69 -0
- briefcase_debugger-0.3.26.dist-info/RECORD +10 -0
- briefcase_debugger-0.3.26.dist-info/WHEEL +5 -0
- briefcase_debugger-0.3.26.dist-info/licenses/LICENSE +27 -0
- briefcase_debugger-0.3.26.dist-info/top_level.txt +1 -0
- briefcase_debugger.pth +1 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
import traceback
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def start_remote_debugger():
|
|
8
|
+
try:
|
|
9
|
+
# check verbose output
|
|
10
|
+
verbose = os.environ.get("BRIEFCASE_DEBUG", "0") == "1"
|
|
11
|
+
|
|
12
|
+
# reading config
|
|
13
|
+
config_str = os.environ.get("BRIEFCASE_DEBUGGER", None)
|
|
14
|
+
|
|
15
|
+
# skip debugger if no config is set
|
|
16
|
+
if config_str is None:
|
|
17
|
+
if verbose:
|
|
18
|
+
print(
|
|
19
|
+
"No 'BRIEFCASE_DEBUGGER' environment variable found. Debugger not starting."
|
|
20
|
+
)
|
|
21
|
+
return # If BRIEFCASE_DEBUGGER is not set, this packages does nothing...
|
|
22
|
+
|
|
23
|
+
if verbose:
|
|
24
|
+
print(f"'BRIEFCASE_DEBUGGER'={config_str}")
|
|
25
|
+
|
|
26
|
+
# Parsing config json
|
|
27
|
+
config = json.loads(config_str)
|
|
28
|
+
|
|
29
|
+
# start debugger
|
|
30
|
+
print("Starting remote debugger...")
|
|
31
|
+
if config["debugger"] == "debugpy":
|
|
32
|
+
from briefcase_debugger.debugpy import start_debugpy
|
|
33
|
+
|
|
34
|
+
start_debugpy(config, verbose)
|
|
35
|
+
elif config["debugger"] == "pdb":
|
|
36
|
+
from briefcase_debugger.pdb import start_pdb
|
|
37
|
+
|
|
38
|
+
start_pdb(config, verbose)
|
|
39
|
+
else:
|
|
40
|
+
raise ValueError(f"Unknown debugger '{config['debugger']}'")
|
|
41
|
+
except Exception:
|
|
42
|
+
# Show exception and stop the whole application when an error occurs
|
|
43
|
+
print(traceback.format_exc())
|
|
44
|
+
sys.exit(-1)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from typing import TypedDict
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class AppPathMappings(TypedDict):
|
|
5
|
+
device_sys_path_regex: str
|
|
6
|
+
device_subfolders: list[str]
|
|
7
|
+
host_folders: list[str]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AppPackagesPathMappings(TypedDict):
|
|
11
|
+
sys_path_regex: str
|
|
12
|
+
host_folder: str
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DebuggerConfig(TypedDict):
|
|
16
|
+
debugger: str
|
|
17
|
+
host: str
|
|
18
|
+
port: int
|
|
19
|
+
host_os: str
|
|
20
|
+
app_path_mappings: AppPathMappings | None
|
|
21
|
+
app_packages_path_mappings: AppPackagesPathMappings | None
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import sys
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import debugpy
|
|
6
|
+
|
|
7
|
+
from briefcase_debugger.config import DebuggerConfig
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def find_first_matching_path(regex: str) -> str:
|
|
11
|
+
"""Returns the first element of sys.paths that matches regex, otherwise None."""
|
|
12
|
+
for path in sys.path:
|
|
13
|
+
if re.search(regex, path):
|
|
14
|
+
return path
|
|
15
|
+
raise ValueError(f"No sys.path entry matches regex '{regex}'")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def load_path_mappings(config: DebuggerConfig, verbose: bool) -> list[tuple[str, str]]:
|
|
19
|
+
app_path_mappings = config.get("app_path_mappings", None)
|
|
20
|
+
app_packages_path_mappings = config.get("app_packages_path_mappings", None)
|
|
21
|
+
|
|
22
|
+
mappings_list = []
|
|
23
|
+
if app_path_mappings:
|
|
24
|
+
device_app_folder = find_first_matching_path(
|
|
25
|
+
app_path_mappings["device_sys_path_regex"]
|
|
26
|
+
)
|
|
27
|
+
for app_subfolder_device, app_subfolder_host in zip(
|
|
28
|
+
app_path_mappings["device_subfolders"],
|
|
29
|
+
app_path_mappings["host_folders"],
|
|
30
|
+
strict=False,
|
|
31
|
+
):
|
|
32
|
+
mappings_list.append(
|
|
33
|
+
(
|
|
34
|
+
app_subfolder_host,
|
|
35
|
+
str(Path(device_app_folder) / app_subfolder_device),
|
|
36
|
+
)
|
|
37
|
+
)
|
|
38
|
+
if app_packages_path_mappings:
|
|
39
|
+
device_app_packages_folder = find_first_matching_path(
|
|
40
|
+
app_packages_path_mappings["sys_path_regex"]
|
|
41
|
+
)
|
|
42
|
+
mappings_list.append(
|
|
43
|
+
(
|
|
44
|
+
app_packages_path_mappings["host_folder"],
|
|
45
|
+
str(Path(device_app_packages_folder)),
|
|
46
|
+
)
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
if verbose:
|
|
50
|
+
print("Extracted path mappings:")
|
|
51
|
+
for idx, mapping in enumerate(mappings_list):
|
|
52
|
+
print(f"[{idx}] host = {mapping[0]}")
|
|
53
|
+
print(f"[{idx}] device = {mapping[1]}")
|
|
54
|
+
|
|
55
|
+
return mappings_list
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def start_debugpy(config: DebuggerConfig, verbose: bool):
|
|
59
|
+
host = config["host"]
|
|
60
|
+
port = config["port"]
|
|
61
|
+
path_mappings = load_path_mappings(config, verbose)
|
|
62
|
+
|
|
63
|
+
# Starting remote debugger...
|
|
64
|
+
print(f"Starting debugpy in server mode at {host}:{port}...")
|
|
65
|
+
debugpy.listen((host, port), in_process_debug_adapter=True)
|
|
66
|
+
|
|
67
|
+
if verbose:
|
|
68
|
+
# pydevd is dynamically loaded and only available after debugpy is started
|
|
69
|
+
import pydevd
|
|
70
|
+
|
|
71
|
+
pydevd.DebugInfoHolder.DEBUG_TRACE_LEVEL = 3
|
|
72
|
+
|
|
73
|
+
if len(path_mappings) > 0:
|
|
74
|
+
if verbose:
|
|
75
|
+
print("Adding path mappings...")
|
|
76
|
+
|
|
77
|
+
# pydevd is dynamically loaded and only available after a debugger has connected
|
|
78
|
+
import pydevd_file_utils
|
|
79
|
+
|
|
80
|
+
pydevd_file_utils.setup_client_server_paths(path_mappings)
|
|
81
|
+
|
|
82
|
+
print("The debugpy server started. Waiting for debugger to attach...")
|
|
83
|
+
print(
|
|
84
|
+
f"""
|
|
85
|
+
To connect to debugpy using VS Code add the following configuration to '.vscode/launch.json':
|
|
86
|
+
{{
|
|
87
|
+
"version": "0.2.0",
|
|
88
|
+
"configurations": [
|
|
89
|
+
{{
|
|
90
|
+
"name": "Briefcase: Attach (Connect)",
|
|
91
|
+
"type": "debugpy",
|
|
92
|
+
"request": "attach",
|
|
93
|
+
"connect": {{
|
|
94
|
+
"host": "{host}",
|
|
95
|
+
"port": {port}
|
|
96
|
+
}},
|
|
97
|
+
"justMyCode": false
|
|
98
|
+
}}
|
|
99
|
+
]
|
|
100
|
+
}}
|
|
101
|
+
|
|
102
|
+
For more information see: https://briefcase.beeware.org/en/stable/how-to/debugging/vscode/#bundled-app
|
|
103
|
+
"""
|
|
104
|
+
)
|
|
105
|
+
debugpy.wait_for_client()
|
|
106
|
+
|
|
107
|
+
print("Debugger attached.")
|
|
108
|
+
print("-" * 75)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
from remote_pdb import RemotePdb
|
|
4
|
+
|
|
5
|
+
from briefcase_debugger.config import DebuggerConfig
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def start_pdb(config: DebuggerConfig, verbose: bool):
|
|
9
|
+
"""Start remote PDB server."""
|
|
10
|
+
# Parsing host/port
|
|
11
|
+
host = config["host"]
|
|
12
|
+
port = config["port"]
|
|
13
|
+
|
|
14
|
+
# Print help message
|
|
15
|
+
host_os = config["host_os"]
|
|
16
|
+
telnet_cmd = f"telnet {host} {port}"
|
|
17
|
+
nc_cmd = f"nc {host} {port}"
|
|
18
|
+
if host_os == "Windows":
|
|
19
|
+
cmds_hint = f" {telnet_cmd}"
|
|
20
|
+
elif host_os in ("Linux", "Darwin"):
|
|
21
|
+
cmds_hint = f" {nc_cmd}"
|
|
22
|
+
else:
|
|
23
|
+
cmds_hint = f"""\
|
|
24
|
+
- {telnet_cmd}
|
|
25
|
+
- {nc_cmd}
|
|
26
|
+
"""
|
|
27
|
+
print(f"""
|
|
28
|
+
Remote PDB server opened at {host}:{port}.
|
|
29
|
+
Waiting for debugger to attach...
|
|
30
|
+
To connect to remote PDB use for example:
|
|
31
|
+
|
|
32
|
+
{cmds_hint}
|
|
33
|
+
|
|
34
|
+
For more information see: https://briefcase.beeware.org/en/stable/how-to/debugging/pdb/#bundled-app
|
|
35
|
+
""")
|
|
36
|
+
|
|
37
|
+
# Create a RemotePdb instance
|
|
38
|
+
remote_pdb = RemotePdb(host, port, quiet=True)
|
|
39
|
+
|
|
40
|
+
# Connect the remote PDB with the "breakpoint()" function
|
|
41
|
+
sys.breakpointhook = remote_pdb.set_trace
|
|
42
|
+
|
|
43
|
+
print("Debugger client attached.")
|
|
44
|
+
print("-" * 75)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: briefcase-debugger
|
|
3
|
+
Version: 0.3.26
|
|
4
|
+
Summary: A Briefcase plugin adding remote debugging support for PDB and Visual Studio Code.
|
|
5
|
+
License-Expression: BSD-3-Clause
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Provides-Extra: pdb
|
|
9
|
+
Requires-Dist: remote-pdb<3.0.0,>=2.1.0; extra == "pdb"
|
|
10
|
+
Provides-Extra: debugpy
|
|
11
|
+
Requires-Dist: debugpy<2.0.0,>=1.8.17; extra == "debugpy"
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# Briefcase Debugger Support
|
|
15
|
+
[](https://pypi.python.org/pypi/briefcase-debugger)
|
|
16
|
+
[](https://pypi.python.org/pypi/briefcase-debugger)
|
|
17
|
+
[](https://pypi.python.org/pypi/briefcase-debugger)
|
|
18
|
+
[](https://github.com/beeware/briefcase/blob/main/debugger/LICENSE)
|
|
19
|
+
[](https://github.com/beeware/briefcase/actions)
|
|
20
|
+
[](https://beeware.org/bee/chat/)
|
|
21
|
+
|
|
22
|
+
This package contains the debugger support package for the `pdb` and `debugpy` debuggers.
|
|
23
|
+
|
|
24
|
+
It starts the remote debugger automatically at startup through an .pth file, if a `BRIEFCASE_DEBUGGER` environment variable is set.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
As an end-user, you won't normally need to install this package. It will be installed automatically by Briefcase if you specify the `--debug=pdb` or `--debug=debugpy` option when running your application.
|
|
28
|
+
|
|
29
|
+
## Financial support
|
|
30
|
+
|
|
31
|
+
The BeeWare project would not be possible without the generous support
|
|
32
|
+
of our financial members:
|
|
33
|
+
|
|
34
|
+
[](https://anaconda.com/)
|
|
35
|
+
|
|
36
|
+
Anaconda Inc. - Advancing AI through open source.
|
|
37
|
+
|
|
38
|
+
Plus individual contributions from [users like
|
|
39
|
+
you](https://beeware.org/community/members/). If you find Briefcase, or
|
|
40
|
+
other BeeWare tools useful, please consider becoming a financial member.
|
|
41
|
+
|
|
42
|
+
## Documentation
|
|
43
|
+
|
|
44
|
+
Documentation for Briefcase can be found on [Read The
|
|
45
|
+
Docs](https://briefcase.readthedocs.io).
|
|
46
|
+
|
|
47
|
+
## Community
|
|
48
|
+
|
|
49
|
+
Briefcase is part of the [BeeWare suite](https://beeware.org). You can
|
|
50
|
+
talk to the community through:
|
|
51
|
+
|
|
52
|
+
- [@beeware@fosstodon.org on Mastodon](https://fosstodon.org/@beeware)
|
|
53
|
+
- [Discord](https://beeware.org/bee/chat/)
|
|
54
|
+
- The Briefcase [GitHub Discussions
|
|
55
|
+
forum](https://github.com/beeware/briefcase/discussions)
|
|
56
|
+
|
|
57
|
+
We foster a welcoming and respectful community as described in our
|
|
58
|
+
[BeeWare Community Code of
|
|
59
|
+
Conduct](https://beeware.org/community/behavior/).
|
|
60
|
+
|
|
61
|
+
## Contributing
|
|
62
|
+
|
|
63
|
+
If you experience problems with Briefcase, [log them on
|
|
64
|
+
GitHub](https://github.com/beeware/briefcase/issues).
|
|
65
|
+
|
|
66
|
+
If you'd like to contribute to Briefcase development, our [contribution
|
|
67
|
+
guide](https://briefcase.readthedocs.io/en/latest/how-to/contribute/index.html)
|
|
68
|
+
details how to set up a development environment, and other requirements
|
|
69
|
+
we have as part of our contribution process.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
briefcase_debugger.pth,sha256=UBmHy5Bj1sYg5ql0_tQ4bPwZIE9WGdbdi0cMhfFaBr4,70
|
|
2
|
+
briefcase_debugger/__init__.py,sha256=JGZqwgKxfLrordBpfUmGhXLdB_i3N4cboCGzsfGEk1I,1355
|
|
3
|
+
briefcase_debugger/config.py,sha256=F0c9bySVvNx7Hat-E_mu_L0v2t7UtVkq-7JrE2Bg0DA,453
|
|
4
|
+
briefcase_debugger/debugpy.py,sha256=APcpmcOSU6QWqME3JT2f4JBdReAoCtUrCPX9rQpmDeQ,3313
|
|
5
|
+
briefcase_debugger/pdb.py,sha256=9TnSB5Zx5OfQrrlLYe7KyPx6nMIODqB7D1X0vM9fJdY,1120
|
|
6
|
+
briefcase_debugger-0.3.26.dist-info/licenses/LICENSE,sha256=qRJk_D5ySIyUj3MPfDAN239NEM-LqvjBTIF1dqgAXEo,1534
|
|
7
|
+
briefcase_debugger-0.3.26.dist-info/METADATA,sha256=9C9eIoGob702SAtDnRiVInG_4kQ8j6U4CKzWENAbwqQ,3164
|
|
8
|
+
briefcase_debugger-0.3.26.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
+
briefcase_debugger-0.3.26.dist-info/top_level.txt,sha256=2teeJqa8nZbwTcxX91A3vAYIctgVfva3nGfAqvITQLY,19
|
|
10
|
+
briefcase_debugger-0.3.26.dist-info/RECORD,,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Copyright (c) 2015 Russell Keith-Magee.
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
5
|
+
are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
this list of conditions and the following disclaimer.
|
|
9
|
+
|
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
notice, this list of conditions and the following disclaimer in the
|
|
12
|
+
documentation and/or other materials provided with the distribution.
|
|
13
|
+
|
|
14
|
+
3. Neither the name of Briefcase-Debugger nor the names of its contributors may
|
|
15
|
+
be used to endorse or promote products derived from this software without
|
|
16
|
+
specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
19
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
20
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
22
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
23
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
24
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
25
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
27
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
briefcase_debugger
|
briefcase_debugger.pth
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import briefcase_debugger; briefcase_debugger.start_remote_debugger()
|