@icyfenix-dmla/cli 2026.5.24-2045 → 2026.5.25-736
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -225,12 +225,25 @@ def run_code(code: str, timeout: int = DEFAULT_TIMEOUT, stream: bool = False) ->
|
|
|
225
225
|
restore_stdout()
|
|
226
226
|
log_debug('stdout restored for code execution')
|
|
227
227
|
|
|
228
|
-
# 3.
|
|
229
|
-
log_debug('Injecting global variables and matplotlib config')
|
|
228
|
+
# 3. 注入全局变量、数据路径和 sys.path 配置
|
|
229
|
+
log_debug('Injecting global variables, sys.path and matplotlib config')
|
|
230
|
+
# 从 PYTHONPATH 环境变量读取共享模块和服务器路径,注入 kernel 的 sys.path
|
|
231
|
+
python_path_env = os.environ.get('PYTHONPATH', '')
|
|
232
|
+
path_separator = ';' if os.name == 'nt' else ':'
|
|
233
|
+
python_path_entries = [p for p in python_path_env.split(path_separator) if p]
|
|
234
|
+
|
|
230
235
|
setup_code = '''
|
|
231
236
|
import os
|
|
237
|
+
import sys
|
|
238
|
+
|
|
232
239
|
DATA_DIR = os.environ.get('DMLA_DATA_PATH', '/data')
|
|
233
240
|
|
|
241
|
+
# 将 PYTHONPATH 中的路径注入 sys.path(IPython kernel 可能不会自动继承)
|
|
242
|
+
_python_path_entries = ''' + repr(python_path_entries) + '''
|
|
243
|
+
for _p in _python_path_entries:
|
|
244
|
+
if _p not in sys.path:
|
|
245
|
+
sys.path.insert(0, _p)
|
|
246
|
+
|
|
234
247
|
# 配置 matplotlib inline 后端(在用户 import matplotlib 之前设置)
|
|
235
248
|
import matplotlib
|
|
236
249
|
matplotlib.use('module://matplotlib_inline.backend_inline')
|
|
@@ -28,7 +28,8 @@ const SOFT_DEPS = [
|
|
|
28
28
|
'requests',
|
|
29
29
|
'transformers',
|
|
30
30
|
'tokenizers',
|
|
31
|
-
'datasets'
|
|
31
|
+
'datasets',
|
|
32
|
+
'ipywidgets'
|
|
32
33
|
]
|
|
33
34
|
|
|
34
35
|
// 环境检测结果缓存
|
|
@@ -562,7 +563,7 @@ export function getSharedModulesPath() {
|
|
|
562
563
|
|
|
563
564
|
// 检测运行模式
|
|
564
565
|
// 源码目录运行: local-server/src/ -> shared 在 local-server/shared/
|
|
565
|
-
// CLI 包运行: packages/cli/src/server/ -> shared 在 packages/cli/shared/
|
|
566
|
+
// CLI 包运行: packages/cli/src/server/ -> shared 在 packages/cli/shared/ 或 shared_modules/
|
|
566
567
|
const currentDir = __dirname
|
|
567
568
|
|
|
568
569
|
// 检查是否为源码目录运行(local-server/src/)
|
|
@@ -571,8 +572,13 @@ export function getSharedModulesPath() {
|
|
|
571
572
|
return path.resolve(currentDir, '../shared')
|
|
572
573
|
}
|
|
573
574
|
|
|
574
|
-
// CLI 包运行:
|
|
575
|
-
|
|
575
|
+
// CLI 包运行: 优先查找 shared/,回退到 shared_modules/(兼容旧版 npm 包)
|
|
576
|
+
const sharedPath = path.resolve(currentDir, '../../shared')
|
|
577
|
+
if (fs.existsSync(sharedPath)) {
|
|
578
|
+
return sharedPath
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
return path.resolve(currentDir, '../../shared_modules')
|
|
576
582
|
}
|
|
577
583
|
|
|
578
584
|
/**
|
|
@@ -146,10 +146,12 @@ export async function runPythonCodeNative(code, useGpu = false, timeoutOverride
|
|
|
146
146
|
log(`Executing code (length=${code.length}, timeout=${timeoutSeconds}s, useGpu=${useGpu})`)
|
|
147
147
|
|
|
148
148
|
// 构建环境变量
|
|
149
|
-
// PYTHONPATH 包含
|
|
149
|
+
// PYTHONPATH 包含 shared 包的父目录和 server src 目录(跨平台路径分隔符)
|
|
150
|
+
// 注意: shared 包的父目录才能让 `import shared.xxx` 正确解析,
|
|
151
|
+
// 如果指向 shared/ 目录本身,Python 会在该路径下找 shared/shared/ 而失败
|
|
150
152
|
const pythonPathSeparator = process.platform === 'win32' ? ';' : ':'
|
|
151
153
|
const pythonPath = [
|
|
152
|
-
getSharedModulesPath(),
|
|
154
|
+
path.dirname(getSharedModulesPath()),
|
|
153
155
|
getServerPythonPath()
|
|
154
156
|
].join(pythonPathSeparator)
|
|
155
157
|
|
|
@@ -411,10 +413,12 @@ export async function runPythonCodeStreamingNative(code, useGpu = false, res, ti
|
|
|
411
413
|
const timeoutSeconds = timeoutOverride === null ? 86400 : (timeoutOverride || DEFAULT_TIMEOUT)
|
|
412
414
|
|
|
413
415
|
// 构建环境变量
|
|
414
|
-
// PYTHONPATH 包含
|
|
416
|
+
// PYTHONPATH 包含 shared 包的父目录和 server src 目录(跨平台路径分隔符)
|
|
417
|
+
// 注意: shared 包的父目录才能让 `import shared.xxx` 正确解析,
|
|
418
|
+
// 如果指向 shared/ 目录本身,Python 会在该路径下找 shared/shared/ 而失败
|
|
415
419
|
const pythonPathSeparator = process.platform === 'win32' ? ';' : ':'
|
|
416
420
|
const pythonPath = [
|
|
417
|
-
getSharedModulesPath(),
|
|
421
|
+
path.dirname(getSharedModulesPath()),
|
|
418
422
|
getServerPythonPath()
|
|
419
423
|
].join(pythonPathSeparator)
|
|
420
424
|
|
package/version.json
CHANGED