Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
- name: Install system dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install -y gdb
- name: Install
run: |
pip install -e .
Expand All @@ -38,7 +42,9 @@ jobs:
shell: 'script -q -e -c "bash --noprofile --norc -eo pipefail {0}"'
env:
TERM: xterm-256color
run: source .github/workflows/test.sh
run: |
source .github/workflows/test.sh
spin gdb -c 'import example_pkg; example_pkg.echo("hi")' -- --eval "run" --batch

- name: Functional tests (MacOS)
if: matrix.os == 'macos-latest'
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ python -m spin
test 🔧 Run pytest
run 🏁 Run a shell command with PYTHONPATH set
docs 📖 Build Sphinx documentation
gdb 👾 Execute a Python snippet with GDB
```

### [Build](https://pypa-build.readthedocs.io/en/stable/) (PEP 517 builder)
Expand Down
3 changes: 3 additions & 0 deletions example_pkg/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ package = 'example_pkg'
"spin.cmds.meson.python",
"spin.cmds.meson.run"
]
"Debug" = [
"spin.cmds.meson.gdb"
]
"Extensions" = [".spin/cmds.py:example"]
45 changes: 45 additions & 0 deletions spin/cmds/meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,51 @@ def test(ctx, pytest_args, coverage=False):
)


@click.command()
@click.option("--code", "-c", help="Python program passed in as a string")
@click.argument("gdb_args", nargs=-1)
def gdb(code, gdb_args):
"""👾 Execute a Python snippet with GDB

spin gdb -c 'import numpy as np; print(np.__version__)'

Or pass arguments to gdb:

spin gdb -c 'import numpy as np; print(np.__version__)' -- --fullname

Or run another program, they way you normally would with gdb:

\b
spin gdb ls
spin gdb -- --args ls -al

You can also run Python programs:

\b
spin gdb my_tests.py
spin gdb -- my_tests.py --mytest-flag
"""
_set_pythonpath()
gdb_args = list(gdb_args)

if gdb_args and gdb_args[0].endswith(".py"):
gdb_args = ["--args", sys.executable] + gdb_args

if sys.version_info[:2] >= (3, 11):
PYTHON_FLAGS = ["-P"]
code_prefix = ""
else:
PYTHON_FLAGS = []
code_prefix = "import sys; sys.path.pop(0); "

if code:
PYTHON_ARGS = ["-c", code_prefix + code]
gdb_args += ["--args", sys.executable] + PYTHON_FLAGS + PYTHON_ARGS

gdb_cmd = ["gdb", "-ex", "set detach-on-fork on"] + gdb_args
_run(gdb_cmd, replace=True)


@click.command()
@click.argument("ipython_args", nargs=-1)
def ipython(ipython_args):
Expand Down