On Wednesday, November 20, 2024 at 5:20:12 AM UTC-5 Edward K. Ream wrote:
On Tue, Nov 19, 2024 at 4:21 PM Thomas Passin wrote: I have tracked down what is happening but I don't know why. The problem is not with the restart command, it's with the runLeo.py module. It runs a different version of Leo, and even a different version of Python, depending on how it is invoked even though you would swear the results should be the same. Details are in the issue I just filed: https://github.com/leo-editor/leo-editor/issues/4199 The reason that this problem has been showing up with the restart-leo command is that the launch command that is captured by sys.argv is NOT always that same command that launched Leo in the first place. The case that occurs for me is that I launch Leo using py -m leo.core.runLeo Bingo! My *local* leo.cmd is: python C:\Repos\leo-editor\launchLeo.py %* This tells python *exactly* where to find Leo's repo. In contrast, py -m leo.core.runLeo does not. Unless I am mistaken, this difference explains: Not really. I usually run my git clone of Leo using a .cmd file that sets PYTHONPATH to the leo-editor directory, then runs py -m leo.core.runLeo. This script accomplished the same thing as yours. The restart-leo command succeeds when I launch the original Leo instance with this script. Using the script, the restart-leo command succeeds even when the working directory is leo-editor. The experiments I posted about above did not use that script. But the working directory was leo-editor. That *should* have caused Python to find the leo-editor files first, before the pip-installed ones. It did, but the restart-leo command manages to prevent Python using the leo-editor files even though the working directory is leo-editor. It sometimes even runs the wrong version of Python, apparently because it calls python.exe, which is incorrect. If one starts Leo with py -m leo.core.runLeo, without setting PYTHONPATH, one of two things should happen: 1. If the working directory is leo-editor, then the git repo's version of Leo will run. 2. If the working directory is not leo-editor, then the pip-installed version of Leo will run. And in fact both 1) and 2) happen, even if a venv is being used. In either case, the restart-leo command should work correctly. But it does not work right in case 1. Not working right is against all expectations of how Python should work, is non-intuitive and confusing, and it is impossible to know what will happen in advance unless one has tried all the various combinations and managed to remember them. - All the behaviour you describe. - The reason I have never seen the behaviors you describe. *Discussion* Using python -m is often correct, so *the choice will always be a tripper*. python -m should work when the initial working directory is leo-editor. Something in launchLeo.py is making an erroneous assumption or two. I use this *local* file, *run-installed-leo.cmd*, during testing, as discussed in the distribution checklist: rem Do **NOT** run this script from the leo-editor folder. rem pip must *not* find the leo-editor folder! cd c:\Repos call python -m leo-editor.leo.scripts.run_installed_leo cd c:\Repos\leo-editor In this script, *python -m* is correct. *A similar tripper?* I am having a devil of a time with #4179 <https://github.com/leo-editor/leo-editor/issues/4179>: use a dark theme for Leo's website. Single-stepping through the `*@button make-sphinx*` script in LeoDocs.leo showed mismatches between python.exe and the sphinx libs! I'm still investigating. As I wrote earlier, you cannot assume that "python.exe" will run the right version of python. What will happen will depend on your installation history, your file associations, and the path. That's why the "py" launcher is so useful. Even on Linux, "python" or "python3" may not run the desired version because they run the system's python installation. If you want to use another, you will be out of luck. For example, one of my VMs used python 3.8 for the system, and I wanted to run Leo with python 3.11, which was the latest version at that time. So I installed it outside of the distro's repo, since 3.11 wasn't offered yet. This worked but I had to run programs using "python3.11" instead of "python3". I did notice an unexpected venv folder in my python folder. I foolishly ignored that surprise at the time, but I'll get back to *that* mystery soon enough. *Summary* *py -m* may have unexpected consequences that will bite devs especially. HTH. Please let me know whether this post solves the mystery for you. No it doesn't. There is nothing wrong with using the py -m command. The root cause is that py -m leo.core.runLeo does not produce the same results as python leo\core\runLeo.py, at least when the working directory is leo-editor. This difference is totally unexpected and non-intuitive, and should be fixed. The restart-leo command constructs the command to be given to subprocess.run using sys.argv. Even when Leo was launched with py -m leo.core.runLeo, sys,argv will contain *leo\core\runLeo*. This causes the restart-leo command to run the wrong version of Leo when the working directory is leo-editor. -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/leo-editor/daa57e24-c20b-41df-8816-f5b71d707517n%40googlegroups.com.
