Python - Use Python Editable Packages=auto reload on change

   934   1   1
User Avatar
Member
5 posts
Joined: Feb. 2021
Online
Greetings,

I know this is an old one but,
I am developing python packages to use in Houdini for my nodes.
But when I update my scripts, the python modules do not reload automatically.
How can i make sure to install an editable python package without the need to restart houdini?

I tried the following things:

- in 456.py:
import importlib
importlib.reload(module_name)
- hython -m pip install -e
- in 456.py:
import site
site.addsitedir(package_folder)
-in 456.py: use os.path and append the package_folder
- setting PYTHONDEVMODE=1
- Modify PYTHONPATH
...

I do not want to reload manually... This is very frustrating for development.
Is there a way to do this?
Edited by BenjaminYdeVintecc - Oct. 10, 2023 15:57:02
User Avatar
Member
313 posts
Joined: Oct. 2016
Offline
Hi, not sure if it helps. I use this in my shelves.

# import generic
from os.path import join
from sys import path
from importlib import reload

myModuleDir = join( '/home','username', 'houdini19.5', 'RnD', 'generic hpy' )
path.append( myModuleDir )

import generic
hou.session.generic = generic

reload(generic)
hou.session.generic.setExternalEditor()

The shelf button will both reload the module and run the fumction setExternalEditor() with one click.

If you really want this to reload on change you can make a while loop that uses wait until the file timestamp is changed. It is in the HOM and can also work.

waitUntil(condition_callback)
Edited by SWest - Oct. 11, 2023 01:28:25
Interested in character concepts, modeling, rigging, and animation. Related tool dev with Py and VEX.
  • Quick Links