Reinstalling an addon in a zip package won't reload code changes #76248

Open
opened 2020-04-30 04:51:20 +02:00 by Leonardo Herrera · 7 comments

System Information
Operating system: Microsoft Windows 10 Pro - 10.0.18363 Build 18363 - x64-based PC
Graphics card:

Blender Version
Broken: 2.82 (sub 7), branch: master, commit date: 2020-03-12 05:06, hash: 375c7dc4caf4, type: Release

Short description of error

Reinstalling (remove and install again) an addon in a zip package (__init__.py plus some modules) won't reload code changes (errors in console will show the new code, but execute the old code).

Tried removing local __pycache__ contents to no avail.

Exact steps for others to reproduce the error

  • Install addon packaged as zip (with a couple of modules)
  • Uninstall it
  • Make some changes in the addon, repackage it
  • Install again

Changes in the addon won't reflect in Blender
Restarting blender will load the changes.

**System Information** Operating system: Microsoft Windows 10 Pro - 10.0.18363 Build 18363 - x64-based PC Graphics card: **Blender Version** Broken: 2.82 (sub 7), branch: master, commit date: 2020-03-12 05:06, hash: 375c7dc4caf4, type: Release **Short description of error** Reinstalling (remove and install again) an addon in a zip package (`__init__.py` plus some modules) won't reload code changes (errors in console will show the new code, but execute the old code). Tried removing local `__pycache__` contents to no avail. **Exact steps for others to reproduce the error** - Install addon packaged as zip (with a couple of modules) - Uninstall it - Make some changes in the addon, repackage it - Install again Changes in the addon won't reflect in Blender Restarting blender will load the changes.

Added subscriber: @leus

Added subscriber: @leus
Member

Added subscriber: @BrendonMurphy

Added subscriber: @BrendonMurphy
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Hi I'll triage this as a known issue.
It's been quite longstanding that reload scripts does not handle all cases well.
To correctly identify which cases are not handled will require some testing.
UI changes usually work, changes within classes when bug fixing sometimes work.
Restarting shows all changes, reload scripts can cause false results by "missing" certain changes.

Hi I'll triage this as a known issue. It's been quite longstanding that reload scripts does not handle all cases well. To correctly identify which cases are not handled will require some testing. UI changes usually work, changes within classes when bug fixing sometimes work. Restarting shows all changes, reload scripts can cause false results by "missing" certain changes.

Just in case some plugin developer wants to know, my current workflow is to execute a batch file that zips my project, copies it to the scripts folder, and starts Blender. It's actually quite fast.

Just in case some plugin developer wants to know, my current workflow is to execute a batch file that zips my project, copies it to the scripts folder, and starts Blender. It's actually quite fast.

Bumping this. Anybody looked at this in the last 3 years?

Seems an easy way to resolve this in source would be to track all paths for modules added, and simply delete those when deleting the addon after unregistering. Including any pycache files. Is that how it's already done?

Bumping this. Anybody looked at this in the last 3 years? Seems an easy way to resolve this in source would be to track all paths for modules added, and simply delete those when deleting the addon after unregistering. Including any pycache files. Is that how it's already done?

Hi I'll triage this as a known issue.
It's been quite longstanding that reload scripts does not handle all cases well.
To correctly identify which cases are not handled will require some testing.
UI changes usually work, changes within classes when bug fixing sometimes work.
Restarting shows all changes, reload scripts can cause false results by "missing" certain changes.

Hey there @BrendonMurphy just came across a solution that works for me in all my addons with tons of modules:

# To support reload properly, try to access a package var, if it's there, reload everything
def cleanse_modules():
    """search for your plugin modules in blender python sys.modules and remove them"""

    import sys

    all_modules = sys.modules 
    all_modules = dict(sorted(all_modules.items(),key= lambda x:x[0])) #sort them
   
    for k,v in all_modules.items():
        if k.startswith(__name__):
            del sys.modules[k]

    return None 



def unregister() -> None:
    # unregistration code here

    cleanse_modules()

Perhaps we can fold this into the unregister execution? Is there any reason this might be bad practice?

> Hi I'll triage this as a known issue. > It's been quite longstanding that reload scripts does not handle all cases well. > To correctly identify which cases are not handled will require some testing. > UI changes usually work, changes within classes when bug fixing sometimes work. > Restarting shows all changes, reload scripts can cause false results by "missing" certain changes. > Hey there @BrendonMurphy just came across a solution that works for me in all my addons with tons of modules: ``` # To support reload properly, try to access a package var, if it's there, reload everything def cleanse_modules(): """search for your plugin modules in blender python sys.modules and remove them""" import sys all_modules = sys.modules all_modules = dict(sorted(all_modules.items(),key= lambda x:x[0])) #sort them for k,v in all_modules.items(): if k.startswith(__name__): del sys.modules[k] return None def unregister() -> None: # unregistration code here cleanse_modules() ``` Perhaps we can fold this into the unregister execution? Is there any reason this might be bad practice?
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#76248
No description provided.