Bug 146498 - Python user macros do not refresh when code is edited in an imported module
Summary: Python user macros do not refresh when code is edited in an imported module
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
7.2.4.1 release
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-Python
  Show dependency treegraph
 
Reported: 2021-12-31 12:55 UTC by bjrawlinson
Modified: 2022-08-30 15:20 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bjrawlinson 2021-12-31 12:55:34 UTC
Description:
If I create a python macro in the user scripts directory that imports codefrom another module, the first time it is run I get the expected result.

However if I modify the referenced module's code the "old" code still runs; even if I delete the __pycache__ directory between running. I assume the code is being cached elsewhere?



Steps to Reproduce:
1. create a python file ~/config/libreoffice/4/user/Scripts/python/testmacro.py

import anothermodule

def set_some_text():
    doc = XSCRIPTCONTEXT.getDocument()
    oSheets = doc.getSheets()
    sSheet = doc.getCurrentController().getActiveSheet()
    activeCell = doc.getCurrentSelection()
    activeCell.setString(anothermodule.get_something())

2. create a python file ~/config/libreoffice/4/user/Scripts/python/pythonpath/anothermodule.py

def get_something():
    return "A"

3. Open Calc and run the macro "set_some_text". The letter A should appear.

4. Modify the anothermodule.py file and change to:

def get_something():
    return "B"

5. Open Calc and run the macro "set_some_text". I would expect the letter "B" to appear but it will instead set the cell to "A" still.





Actual Results:
"A" is set in the ActiveCell after changing anothermodule.py

Expected Results:
"B" is set in the ActiveCell


Reproducible: Always


User Profile Reset: Yes



Additional Info:
Version: 7.2.4.1
Build ID: 20(Build:1)
CPU threads: 16; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-GB (en_GB.UTF-8); UI: en-US
Calc: threaded
Comment 1 Roman Kuznetsov 2022-08-26 13:57:07 UTC
Alain, could you say your opinion please?
Comment 2 Alain Romedenne 2022-08-29 13:50:31 UTC
Modified imported Python modules require to restart LibO by design.
Imported modules remain in memory until the LibO client is closed.

Reflecting updates in imported modules requires to tweak your script using methods such as import.reload() or modules such as import-update.
Comment 3 Roman Kuznetsov 2022-08-30 08:33:56 UTC
Let's close as NAB by Comment 2
Comment 4 bjrawlinson 2022-08-30 15:20:05 UTC
Thanks Alain, Roman.

Working as expected now using reload(anothermodule)