diff --git a/shell/preload/sitecustomize.js b/shell/preload/sitecustomize.js index 7464483b90e..3cbe3aacca9 100644 --- a/shell/preload/sitecustomize.js +++ b/shell/preload/sitecustomize.js @@ -1,13 +1,5 @@ const { execSync } = require('child_process'); -const { sendNotify } = require('./notify.js'); require(`./env.js`); - -function initGlobal() { - global.QLAPI = { - notify: sendNotify, - }; -} - function expandRange(rangeStr, max) { const tempRangeStr = rangeStr .trim() @@ -76,8 +68,12 @@ function run() { } try { - initGlobal(); run(); + + const { sendNotify } = require('./notify.js'); + global.QLAPI = { + notify: sendNotify, + }; } catch (error) { console.log(`run builtin code error: `, error, '\n'); } diff --git a/shell/preload/sitecustomize.py b/shell/preload/sitecustomize.py index f9d426a94de..09eba43b514 100644 --- a/shell/preload/sitecustomize.py +++ b/shell/preload/sitecustomize.py @@ -5,17 +5,6 @@ import builtins import sys import env -from notify import send - - -class BaseApi: - def notify(self, *args, **kwargs): - return send(*args, **kwargs) - - -def init_global(): - QLAPI = BaseApi() - builtins.QLAPI = QLAPI def try_parse_int(value): @@ -92,7 +81,15 @@ def run(): try: - init_global() run() + + from notify import send + + class BaseApi: + def notify(self, *args, **kwargs): + return send(*args, **kwargs) + + QLAPI = BaseApi() + builtins.QLAPI = QLAPI except Exception as error: print(f"run builtin code error: {error}\n")