me.fier.python/example.py

36 lines
1.2 KiB
Python
Raw Permalink Normal View History

2022-12-19 07:01:04 +00:00
#!/usr/bin/env python3
def init(): pass
def main():
mfp.setProgramName("me.fier.example") # Your domain/username and the name of your program
# Some example code to test the functionality
testpy = mfp.require("test")
testpy.st = "Hello world"
2023-04-03 17:04:17 +00:00
testpy.echo() # "Hello world"
2022-12-19 07:01:04 +00:00
testpy["st"] = "Hello world 2"
2023-04-03 17:04:17 +00:00
testpy.echo() # "Hello world 2"
2022-12-19 07:01:04 +00:00
testpy = mfp.require("test")
2023-04-03 17:04:17 +00:00
testpy.echo() # Will still be "Hello world 2", since the library has been required before.
2022-12-19 11:32:53 +00:00
testpy = mfp.dofile(mfp.p(mfp.sd,"module","test.py")) # Same file as used for mfp.require
2023-04-03 17:04:17 +00:00
testpy.echo() # Will be None, as it's a new instance of the library (dofile does not care)
2022-12-19 07:01:04 +00:00
def bootstrap(name,modName):
if name in globals(): return
import sys, os, importlib
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
s = os.path.realpath(sys.executable)
else:
s = os.path.realpath(__file__)
2022-12-19 11:26:47 +00:00
if not os.path.join(os.path.dirname(s),"module","py") in sys.path:
sys.path = [os.path.join(os.path.dirname(s),"module","py")] + sys.path
2022-12-19 07:01:04 +00:00
mod = importlib.import_module(modName); modl = mod.Bunch()
mod.init(mod,modl,s,name)
globals()[name] = mod; globals()[name + "l"] = modl
bootstrap("mfp","me.fier.python")
init()
if __name__ == '__main__':
2023-04-03 17:04:17 +00:00
main()