Skip to content

Commit 668a344

Browse files
committed
feat(runtime): 支持共享 Demucs 运行时
1 parent e164ebb commit 668a344

7 files changed

Lines changed: 60 additions & 10 deletions

‎env.example‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
CLOUD_SYNC_BASE_URL_DEV=http://localhost:3001
2+
3+
# 可选:共享 Demucs runtime 根目录;未配置时使用本项目 vendor/demucs
4+
# FRKB_DEMUCS_ROOT=D:/playground/FRKB_Rapid-Audio-Organization-Tool/vendor/demucs
25
# 生产地址(一般不需要填写,通过 server.json 发现)
36
# CLOUD_SYNC_BASE_URL_PROD=
47

‎scripts/ensure-demucs-runtime.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dotenv/config'
12
import fs from 'node:fs'
23
import path from 'node:path'
34
import { spawnSync } from 'node:child_process'
@@ -56,7 +57,8 @@ const toShortText = (value, maxLen = 400) => {
5657
return text.slice(0, maxLen)
5758
}
5859

59-
const runtimeRootArg = getArgValue('--runtime-root', 'vendor/demucs')
60+
const configuredDemucsRoot = String(process.env.FRKB_DEMUCS_ROOT || '').trim()
61+
const runtimeRootArg = getArgValue('--runtime-root', configuredDemucsRoot || 'vendor/demucs')
6062
const platformArg = getArgValue('--platform', platformDefault)
6163
const profileArg = getArgValue('--profiles', '')
6264
const modelsArg = getArgValue('--models', '')

‎scripts/master-tempo-ab-benchmark.mjs‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dotenv/config'
12
import { spawnSync } from 'node:child_process'
23
import { createHash } from 'node:crypto'
34
import { createRequire } from 'node:module'
@@ -10,6 +11,14 @@ const repoRoot = path.resolve(scriptDir, '..')
1011
const require = createRequire(import.meta.url)
1112
const RUNNER_VERSION = 'master-tempo-ab-benchmark-v2'
1213

14+
const resolveManagedRuntimePython = () => {
15+
const configuredDemucsRoot = String(process.env.FRKB_DEMUCS_ROOT || '').trim()
16+
const demucsRoot = configuredDemucsRoot
17+
? path.resolve(configuredDemucsRoot)
18+
: path.join(repoRoot, 'vendor', 'demucs')
19+
return path.join(demucsRoot, 'win32-x64', 'runtime-cpu', 'python.exe')
20+
}
21+
1322
const parseArgs = (argv) => {
1423
const args = new Map()
1524
for (let index = 0; index < argv.length; index += 2) {
@@ -82,10 +91,10 @@ const resolvePython = () => {
8291
const configured = String(process.env.FRKB_MASTER_TEMPO_BENCHMARK_PYTHON || '').trim()
8392
const candidate = configured
8493
? path.resolve(configured)
85-
: path.join(repoRoot, 'vendor', 'demucs', 'win32-x64', 'runtime-cpu', 'python.exe')
94+
: resolveManagedRuntimePython()
8695
if (!fs.existsSync(candidate)) {
8796
throw new Error(
88-
'找不到 benchmark Python;请设置 FRKB_MASTER_TEMPO_BENCHMARK_PYTHON 指向项目受管 Python'
97+
'找不到 benchmark Python;请设置 FRKB_MASTER_TEMPO_BENCHMARK_PYTHON 或 FRKB_DEMUCS_ROOT'
8998
)
9099
}
91100
return candidate

‎scripts/package-demucs-runtime-assets.mjs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dotenv/config'
12
import fs from 'node:fs'
23
import path from 'node:path'
34
import crypto from 'node:crypto'
@@ -36,7 +37,9 @@ const platformDefault = (() => {
3637
return process.arch === 'arm64' ? 'linux-arm64' : 'linux-x64'
3738
})()
3839

39-
const runtimeRoot = path.resolve(getArgValue('--runtime-root', 'vendor/demucs'))
40+
const configuredDemucsRoot = String(process.env.FRKB_DEMUCS_ROOT || '').trim()
41+
const runtimeRootArg = getArgValue('--runtime-root', configuredDemucsRoot || 'vendor/demucs')
42+
const runtimeRoot = path.resolve(runtimeRootArg)
4043
const platformKey = getArgValue('--platform', platformDefault)
4144
const outputRoot = path.resolve(getArgValue('--output-root', 'dist/demucs-runtime-assets'))
4245
const releaseTag = getArgValue('--release-tag', 'demucs-runtime-assets')

‎scripts/prep_move_tracks_between_playlists.py‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import argparse
2323
import json
24+
import os
2425
import subprocess
2526
import sys
2627
import time
@@ -40,8 +41,40 @@
4041
pass
4142

4243
REPO_ROOT = Path(__file__).resolve().parents[1]
44+
45+
46+
def _read_project_env_value(name: str) -> str:
47+
configured = str(os.environ.get(name) or "").strip()
48+
if configured:
49+
return configured
50+
try:
51+
lines = (REPO_ROOT / ".env").read_text(encoding="utf-8").splitlines()
52+
except OSError:
53+
return ""
54+
for raw_line in lines:
55+
line = raw_line.strip()
56+
if not line or line.startswith("#") or "=" not in line:
57+
continue
58+
key, raw_value = line.split("=", 1)
59+
if key.strip() != name:
60+
continue
61+
value = raw_value.strip()
62+
if len(value) >= 2 and value[0] == value[-1] and value[0] in {"'", '"'}:
63+
value = value[1:-1]
64+
return value
65+
return ""
66+
67+
68+
def _resolve_demucs_root() -> Path:
69+
configured = _read_project_env_value("FRKB_DEMUCS_ROOT")
70+
if not configured:
71+
return REPO_ROOT / "vendor" / "demucs"
72+
candidate = Path(configured).expanduser()
73+
return candidate if candidate.is_absolute() else REPO_ROOT / candidate
74+
75+
4376
DEFAULT_RUNTIME_PYTHON = (
44-
REPO_ROOT / "vendor" / "demucs" / "win32-x64" / "runtime-cpu" / "python.exe"
77+
_resolve_demucs_root() / "win32-x64" / "runtime-cpu" / "python.exe"
4578
)
4679
DEFAULT_SEALED_SCRIPT = REPO_ROOT / "scripts" / "rkb_sealed_batch.py"
4780
DEFAULT_TRIAGE_SCRIPT = REPO_ROOT / "scripts" / "move_rekordbox_playlist_grid_diffs.py"

‎scripts/prepare-demucs-runtimes.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'dotenv/config'
12
import fs from 'node:fs'
23
import path from 'node:path'
34
import { spawnSync } from 'node:child_process'
@@ -30,7 +31,8 @@ const getArgValue = (flag, fallback = '') => {
3031

3132
const hasFlag = (flag) => args.includes(flag)
3233

33-
const runtimeRootArg = getArgValue('--runtime-root', 'vendor/demucs')
34+
const configuredDemucsRoot = String(process.env.FRKB_DEMUCS_ROOT || '').trim()
35+
const runtimeRootArg = getArgValue('--runtime-root', configuredDemucsRoot || 'vendor/demucs')
3436
const platformArg = getArgValue('--platform', platformDefault)
3537
const profileArg = getArgValue('--profiles', '')
3638
const pipExtraArg = getArgValue('--pip-extra', '')

‎scripts/test_prep_move_tracks_between_playlists.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,10 @@ def test_main_passes_explicit_workflow_overrides(self) -> None:
320320
self.assertEqual(triage.call_args.kwargs["dataset_registry"], Path("registry.json"))
321321
self.assertTrue(triage.call_args.kwargs["pre_review"])
322322

323-
def test_default_workflow_python_is_vendored_runtime(self) -> None:
323+
def test_default_workflow_python_uses_configured_demucs_root(self) -> None:
324324
self.assertEqual(
325325
prep.DEFAULT_RUNTIME_PYTHON,
326-
prep.REPO_ROOT
327-
/ "vendor"
328-
/ "demucs"
326+
prep._resolve_demucs_root()
329327
/ "win32-x64"
330328
/ "runtime-cpu"
331329
/ "python.exe",

0 commit comments

Comments
 (0)