|
1 | | -# Python Tools for Visual Studio |
2 | | -# Copyright(c) Microsoft Corporation |
3 | | -# All rights reserved. |
4 | | -# |
5 | | -# Licensed under the Apache License, Version 2.0 (the License); you may not use |
6 | | -# this file except in compliance with the License. You may obtain a copy of the |
7 | | -# License at http://www.apache.org/licenses/LICENSE-2.0 |
8 | | -# |
9 | | -# THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS |
10 | | -# OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY |
11 | | -# IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, |
12 | | -# MERCHANTABLITY OR NON-INFRINGEMENT. |
13 | | -# |
14 | | -# See the Apache Version 2.0 License for specific language governing |
15 | | -# permissions and limitations under the License. |
16 | | - |
17 | | -# Source Copied from https://github.com/Microsoft/PTVS/blob/master/Python/Product/PythonTools/ptvsd_launcher.py |
18 | | -""" |
19 | | -Starts Debugging, expected to start with normal program |
20 | | -to start as first argument and directory to run from as |
21 | | -the second argument. |
22 | | -""" |
23 | | - |
24 | | -__author__ = "Microsoft Corporation <ptvshelp@microsoft.com>" |
25 | | -__version__ = "3.2.0.0" |
| 1 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +# Licensed under the MIT License. |
26 | 3 |
|
27 | 4 | import os |
28 | 5 | import os.path |
29 | 6 | import sys |
30 | 7 | import traceback |
31 | 8 |
|
32 | | -# Arguments are: |
33 | | -# 1. VS debugger port to connect to. |
34 | | -# 2. '-g' to use the installed ptvsd package, rather than bundled one. |
35 | | -# 3. '--nodebug' to launch without debugging. |
36 | | -# 4. '-m' or '-c' to override the default run-as mode. [optional] |
37 | | -# 5. Startup script name. |
38 | | -# 6. Script arguments. |
39 | | - |
40 | | -port_num = int(sys.argv[1]) |
41 | | -del sys.argv[0:2] |
42 | | - |
43 | | -# Use bundled ptvsd or not? |
44 | | -bundled_ptvsd = True |
45 | | -if sys.argv and sys.argv[0] == '-g': |
46 | | - bundled_ptvsd = False |
47 | | - del sys.argv[0] |
48 | | - |
49 | | -# Use bundled ptvsd or not? |
50 | | -no_debug = False |
51 | | -if sys.argv and sys.argv[0] == '--nodebug': |
52 | | - no_debug = True |
53 | | - del sys.argv[0] |
54 | | - |
55 | | -# set run_as mode appropriately |
56 | | -run_as = 'script' |
57 | | -if sys.argv and sys.argv[0] == '-m': |
58 | | - run_as = 'module' |
59 | | - del sys.argv[0] |
60 | | -if sys.argv and sys.argv[0] == '-c': |
61 | | - run_as = 'code' |
62 | | - del sys.argv[0] |
63 | | - |
64 | | -# preserve filename before we del sys |
65 | | -filename = sys.argv[0] |
66 | | - |
67 | | -# fix sys.path to be the script file dir |
68 | | -sys.path[0] = '' |
69 | | - |
70 | | -if not bundled_ptvsd and (sys.platform == 'cli' or sys.version_info < (2, 7) or |
71 | | - (sys.version_info >= (3, 0) and sys.version_info < (3, 4))): |
72 | | - # This is experimental debugger incompatibility. Exit immediately. |
73 | | - # This process will be killed by VS since it does not see a debugger |
74 | | - # connect to it. The exit code we will get there will be wrong. |
75 | | - # 687: ERROR_DLL_MIGHT_BE_INCOMPATIBLE |
76 | | - sys.exit(687) |
77 | | - |
78 | 9 | # Load the debugger package |
79 | 10 | try: |
80 | | - ptvs_lib_path = None |
81 | | - if bundled_ptvsd: |
82 | | - ptvs_lib_path = os.path.join(os.path.dirname(__file__), 'ptvsd') |
83 | | - sys.path.append(ptvs_lib_path) |
| 11 | + ptvs_lib_path = os.path.join(os.path.dirname(__file__), 'ptvsd') |
| 12 | + sys.path.append(ptvs_lib_path) |
84 | 13 | try: |
85 | 14 | import ptvsd |
86 | 15 | import ptvsd.debugger as vspd |
| 16 | + from ptvsd.__main__ import main |
87 | 17 | ptvsd_loaded = True |
88 | 18 | except ImportError: |
89 | 19 | ptvsd_loaded = False |
90 | 20 | raise |
91 | 21 | vspd.DONT_DEBUG.append(os.path.normcase(__file__)) |
92 | 22 | except: |
93 | 23 | traceback.print_exc() |
94 | | - if not bundled_ptvsd and not ptvsd_loaded: |
95 | | - # This is experimental debugger import error. Exit immediately. |
96 | | - # This process will be killed by VS since it does not see a debugger |
97 | | - # connect to it. The exit code we will get there will be wrong. |
98 | | - # 126 : ERROR_MOD_NOT_FOUND |
99 | | - sys.exit(126) |
100 | 24 | print(''' |
101 | 25 | Internal error detected. Please copy the above traceback and report at |
102 | 26 | https://github.com/Microsoft/vscode-python/issues/new |
|
111 | 35 | if ptvs_lib_path: |
112 | 36 | sys.path.remove(ptvs_lib_path) |
113 | 37 |
|
114 | | -if no_debug: |
115 | | - vspd.run(filename, port_num, run_as, *sys.argv[1:]) |
116 | | -else: |
117 | | - # and start debugging |
118 | | - vspd.debug(filename, port_num, '', '', run_as) |
| 38 | +main(sys.argv) |
0 commit comments