diff --git a/ChangeLog.md b/ChangeLog.md index 8d4f32e5228..19e2bc6dc96 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,10 +1,14 @@ # Change Log -### 2020-xx-xx - 5.3.6 +### 2020-xx-xx - 5.4.0 Autorest core version: 3.0.6318 Modelerfour version: 4.15.421 +**New Features** + +- Add support for `--python.debugger`. With this flag, you can start debugging using VS Code. Make sure to still set up your [debugging configuration](https://github.com/Azure/autorest.python/wiki/Autorest-v3-based-generator-cheatsheet#vscode-debug) #790 + **Bug Fixes** - Correctly handling inheritance of class properties for inheritance chains > 3 levels #795 diff --git a/autorest/jsonrpc/server.py b/autorest/jsonrpc/server.py index 0875acc654e..dddc9aae8dc 100644 --- a/autorest/jsonrpc/server.py +++ b/autorest/jsonrpc/server.py @@ -5,6 +5,7 @@ # -------------------------------------------------------------------------- import contextlib import os +import sys import logging from jsonrpc import dispatcher, JSONRPCResponseManager @@ -53,7 +54,9 @@ def Process(plugin_name: str, session_id: str) -> bool: def main() -> None: - if os.environ.get("AUTOREST_PYTHON_ATTACH_VSCODE_DEBUG", False): + # If --python.debugger is specified on the command line, we call the server.py file internally + # with flag --debug. + if '--debug' in sys.argv or os.environ.get("AUTOREST_PYTHON_ATTACH_VSCODE_DEBUG", False): try: import ptvsd # pylint: disable=import-outside-toplevel except ImportError: diff --git a/package.json b/package.json index c5c7ddbf99a..12d34724313 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "scripts": { "prepare": "node run-python3.js prepare.py", "start": "node run-python3.js start.py", - "install": "node run-python3.js install.py" + "install": "node run-python3.js install.py", + "debug": "node run-python3.js start.py --debug" }, "repository": { "type": "git", diff --git a/run-python3.js b/run-python3.js index f9d6ee99a11..556dd47d923 100644 --- a/run-python3.js +++ b/run-python3.js @@ -9,15 +9,15 @@ const cp = require("child_process"); const extension = require("@azure-tools/extension"); -async function runPython3(scriptName) { - const command = ["python"]; +async function runPython3(scriptName, debug = "") { + const command = ["python", scriptName, debug]; await extension.updatePythonPath(command); - cp.execSync(command[0] + " " + scriptName, { + cp.execSync(command.join(" "), { stdio: [0, 1, 2] }); } -runPython3(process.argv[2]).catch(err => { +runPython3(...process.argv.slice(2)).catch(err => { const error = err.toString(); // Python script errors are already written out via stderr so don't diff --git a/start.py b/start.py index b4e778cba8b..cd12fef54d8 100644 --- a/start.py +++ b/start.py @@ -25,8 +25,7 @@ def main(): env_builder = venv.EnvBuilder(with_pip=True) venv_context = env_builder.ensure_directories(venv_path) - - python_run(venv_context, "autorest.jsonrpc.server") + python_run(venv_context, "autorest.jsonrpc.server", *sys.argv[1:]) if __name__ == "__main__": main()