Transform shell code that invokes python scripts to Visual Studio Code debug configurations.
Use the package manager pip to install shell2launch.
pip install shell2launchshell2launch helps you to quickly convert shell code that calls a Python script with additional arguments into a vscode debug configuration that can be copied and pasted into launch.json files.
For Python projects that provide shell scripts with dozens of arguments, starting a debug run in vscode can be annoying, as the debug configuration expects arguments in a different format than shell code.
Run shell2launch with the path to your shell script to print the debug configuration to your console.
shell2launch path/to/your/shellscript.sh--args_only
Setting this flag limits the output to the "args": [...] part of the debug configuration. This might be sufficient, if you want to set the other configuration attributes manually.
-o, --output_filepath path/to/your/output.txtAllows you to provide a filepath to store the output. shell2launch will create the file at the specified location and writes the same output that gets printed to the console.
./testing/ contains a python script example.py and a corresponding shell script example.sh that invokes the python script with arguments.
To start a debug run of example.py with the same arguments as in the shell script, follow these steps:
-
Open the Run and Debug view (Ctrl + Shift + D), click create a
launch.jsonfile, and select the Python Debugger and the Python File configuration. This creates.vscode/launch.json. The contents should look something like this:{ "version": "0.2.0", "configurations": [ { "name": "Python Debugger: Current File", "type": "debugpy", "request": "launch", "program": "${file}", "console": "integratedTerminal" } ] } -
Run shell2launch on the shell script.
shell2launch testing/example.sh
-
Copy the console output and append it to the list of configurations in
.vscode/launch.json. It should now look like this:{ "version": "0.2.0", "configurations": [ { "name": "Python Debugger: Current File", "type": "debugpy", "request": "launch", "program": "${file}", "console": "integratedTerminal" }, { "name": "Python Debugger: testing/example.py with Arguments", "type": "debugpy", "request": "launch", "program": "testing/example.py", "console": "integratedTerminal", "args": [ "positional", "--store_true", "--no_val", "--single_val", "1", "--list_val", "1", "2", "3", "4", "-s", "short", "--path", "dir/dir/file.txt", ] } ] } -
In the RUN AND DEBUG dropdown select the new option Python Debugger: testing/example.py with Arguments and hit the play button (F5). Usually, this should print the following to your vscode terminal:
{'list_val': ['1', '2', '3', '4'], 'no_val': None, 'path': 'dir/dir/file.txt', 'positional': 'positional', 'short': 'short', 'single_val': '1', 'store_true': True}
Clone this repository.
git clone https://github.com/jjaju/shell2launch.gitNavigate to the cloned repository.
cd shell2launchInstall dev dependencies.
pip install -r requirements_dev.txtInstall shell2launch in "editable" mode.
pip install -e .Automatically run pytest, mypy, ruff, and coverage
tox -p