Best way to import a module from python macro

Hi!
I am trying to launch a python macro from a button. But then this macro loads another py module.
The problem is that the second module has not access to XSCRIPTCONTEXT.

Right now I have 2 workarounds:

Workaround 1:
Using this in 1st module:

sys.modules['XSCRIPTCONTEXT'] = XSCRIPTCONTEXT

and this in 2nd module:

XSCRIPTCONTEXT = sys.modules.get('XSCRIPTCONTEXT')

Workaround 2:
Using this in 1st module:

imported_module.set_context(XSCRIPTCONTEXT)

and this in 2nd module:

def set_context(context):
	global XSCRIPTCONTEXT
	XSCRIPTCONTEXT = context

They both work. But is there a better and more direct and simpler way of doing this? What is the right way?
Thank you very much!

Why do you need XSCRIPTCONTEXT in the second module?

What do you “really” want to do?

Hi elmau
My intention is to be able to make modularly reusable libraries.
I give you an example, in the second module there could be:

def msg(message, title="LibreOffice", buttons=BUTTONS_OK, msg_type=MESSAGEBOX):
    doc = XSCRIPTCONTEXT.getDocument()
    parent = doc.CurrentController.Frame.ContainerWindow
    toolkit = parent.getToolkit()
    box = toolkit.createMessageBox(parent, msg_type, buttons, title, message)
    result = box.execute()
    return result

The idea is to be able to use functions like this one or more complex ones without rewriting the functions in each .py
Thank you!