ScriptEditor Development Mode

I click this button hundred of times a day:

Because I change code in vscode my of a locally installed package that is in constant development.

@eirannejad is it possible to force reloading packages for development every time I hit run button?
Any hacky way is ok…

Have you tried importlib.reload()?
importlib — The implementation of import — Python 3.13.2 documentation

That usually solves this type of issue for me. Haven’t tested it myself in Rhino though.

1 Like

This does nothing in ScriptEditor. We need @eirannejad who knows what is behind reload button.

Add # flags: python.reloadEngine to the top of your script and see if that helps

1 Like

Hi,

No, it does not work neither :slight_smile:

What does this do?

import importlib
import your_module
importlib.reload(your_module)

# reimport
import your_module

Reload does not do anything, but I tried again after restarting Rhino:
# flags: python.reloadEngine seems to work.

Is there any documentation for the flags?

Not at the moment. That’s the only one really :smiley:

1 Like

@eirannejad

# flags: python.reloadEngine
Does not work when you create a new method or a class in module. Only when you are editing existing method. Only reload engine toolbar button works.

Do you think it would be possible also to include in script editor a boolean toggle in the reload python engine?

In reality you most often are going through all the commands and scripts not just a single file.

Last week there was compas dev meeting, and I see this option would be useful to many more developers using ScriptEditor in rhino and also grasshopper. We most often work in VScode or other editors for main libraries (for the reasons of copilot, any other extensions or just being too comfortable with vscode), and when we want to integrate our code to rhino user interface we constantly work in both systems: vscode for the main library and rhino script editor. But not for a single file, most commonly for the whole one specific python library that is constantly being edited.

1 Like

Okay I made this ticket to look into this and see if I can improve the reloading. It’s quite complicated how reloading works but I took some notes based on your input. If you can provide any sort of specific examples that would be great.

RH-86250 Improve module reloading in pythons

1 Like

Hi,

Infact even calling a method in class constructor does not reload, also importlib does not do anything neither. I think what is under reload button completely different thing than this soft reload.

I prepared completely empty python project for you to test.
Also I recorded video below.

my_library.zip (4.7 KB)

1 Like