ENB: Launching Leo inside IPython (Windows)

25 views
Skip to first unread message

Edward K. Ream

unread,
Oct 18, 2024, 4:53:31 AM10/18/24
to leo-editor
This Engineering Notebook post discusses running Leo, inside IPython, on Windows. This project is part of #4105: fix leoIPython.py.

This post is similar to a previous post: Launching Leo when SageMath starts (Ubuntu). The code is similar, but there are twists. Note: I did all my work from within IPython.

Running a custom startup script when IPython starts

By default, IPython will run any Python scripts in the default profile's startup directory, found in ~/.ipython/profile_default/startup.

I created init.py in that folder. This file contains:

# ~/.ipython/profile_default/startup/init.py
# IPython runs this code during startup.

import os
from subprocess import Popen

print('')
print('~/.ipython/profile_default/startup/init.py')

def load_leo():
print('loading leoPy.leo...')
command = 'ipython-init'
proc = Popen([command],
shell=True, stdin=None,
stdout=None, stderr=None, close_fds=True)

# Load leoPy.leo on startup?!?
# load_leo()

Because of strange problems relating to filenames, Popen doesn't execute Python code directly. Instead, it executes ipython-init.cmd:

@echo off
cd c:\Repos\leo-editor
python C:\Repos\leo-editor\launchLeo.py leo\core\leoPy.leo ^
--silent --no-splash --gui=qttabs

Now I run the ipython command from a console.

At any IPython prompt, entering load_leo() launches Leo without blocking IPython. As on Ubuntu, I must click the IPython console and hit return to see the IPython prompt.

Summary

It's easy to run any Python code while IPython starts.

Launching Leo from within IPython (on Windows) is similar to launching Leo from SageMath on Ubuntu.

An open question: how much of IPython can the "embedded" Leo access?

Edward
Reply all
Reply to author
Forward
0 new messages