Skip to content

Commit 6490a87

Browse files
authored
Add pre-import keyword to IPython command (#251)
1 parent b1c893d commit 6490a87

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

example_pkg/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ package = 'example_pkg'
5353

5454
[tool.spin.kwargs]
5555
".spin/cmds.py:example" = {"test" = "default override", "default_kwd" = 3}
56+
"spin.cmds.meson.ipython" = {"pre_import" = '''import example_pkg as ep; print(f'\nPreimported example_pkg {ep.__version__} as ep')'''}

spin/cmds/meson.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ def gdb(ctx, *, code, gdb_args, build_dir):
692692
@click.argument("ipython_args", nargs=-1)
693693
@build_dir_option
694694
@click.pass_context
695-
def ipython(ctx, *, ipython_args, build_dir):
695+
def ipython(ctx, *, ipython_args, build_dir, pre_import=""):
696696
"""💻 Launch IPython shell with PYTHONPATH set
697697
698698
IPYTHON_ARGS are passed through directly to IPython, e.g.:
@@ -702,13 +702,15 @@ def ipython(ctx, *, ipython_args, build_dir):
702702
build_cmd = _get_configured_command("build")
703703
if build_cmd:
704704
click.secho(
705-
"Invoking `build` prior to invoking ipython:", bold=True, fg="bright_green"
705+
"Invoking `build` prior to launching ipython:", bold=True, fg="bright_green"
706706
)
707707
ctx.invoke(build_cmd, build_dir=build_dir)
708708

709709
p = _set_pythonpath(build_dir)
710710
if p:
711711
print(f'💻 Launching IPython with PYTHONPATH="{p}"')
712+
if pre_import:
713+
ipython_args = (f"--TerminalIPythonApp.exec_lines={pre_import}",) + ipython_args
712714
_run(["ipython", "--ignore-cwd"] + list(ipython_args), replace=True)
713715

714716

0 commit comments

Comments
 (0)