Skip to main content

Transform shell code that invokes python scripts to vscode debug configurations.

Project description

shell2launch

Pypi Status PyPI - Python Version GitHub Actions (Tests) Coverage

Transform shell code that invokes python scripts to Visual Studio Code debug configurations.

Installation

Use the package manager pip to install shell2launch.

pip install shell2launch

Usage

shell2launch 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

Optional Arguments

--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.txt

Allows 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.

Example

./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:

  1. Open the Run and Debug view (Ctrl + Shift + D), click create a launch.json file, 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"
            }
        ]
    }
    
  2. Run shell2launch on the shell script.

    shell2launch testing/example.sh
    
  3. 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",
                ]
            }
        ]
    }
    
  4. 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}
    

Development Setup

Clone this repository.

git clone https://github.com/jjaju/shell2launch.git

Navigate to the cloned repository.

cd shell2launch

Install dev dependencies.

pip install -r requirements_dev.txt

Install shell2launch in "editable" mode.

pip install -e .

Automatically run pytest, mypy, ruff, and coverage

tox -p

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shell2launch-0.0.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shell2launch-0.0.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file shell2launch-0.0.1.tar.gz.

File metadata

  • Download URL: shell2launch-0.0.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for shell2launch-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cbb38df542cd78dfa91e3ff88c9eab77c1359ca144349ccdb0d14bfc3a3afda5
MD5 3b109a8054a347e1146cf4d09c20c0d5
BLAKE2b-256 727289a55812a3b7a75c86481d43cc49c1dd7f9128852da4a096cedb58e01505

See more details on using hashes here.

Provenance

The following attestation bundles were made for shell2launch-0.0.1.tar.gz:

Publisher: publish.yaml on jjaju/shell2launch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file shell2launch-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: shell2launch-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for shell2launch-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d20a93e60a65b923c55fe791f203f59137878cd92c0885b13c3995815b1eb1a
MD5 761372d95991b9c394a9875f28381a77
BLAKE2b-256 30281fc88758b78e0ded4284106474d3caf6b33f48aff02fcb99e1022db8e9d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for shell2launch-0.0.1-py3-none-any.whl:

Publisher: publish.yaml on jjaju/shell2launch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page