feat: 解决python虚拟环境问题
This commit is contained in:
@@ -328,6 +328,16 @@ export function TaskEditorModal({
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
<Field
|
||||
label="虚拟环境目录 (可选)"
|
||||
hint="留空时自动从工作目录及上级目录探测 .venv、venv、env"
|
||||
>
|
||||
<input
|
||||
{...register('script.venv')}
|
||||
className="field-input mono"
|
||||
placeholder="例如:.venv"
|
||||
/>
|
||||
</Field>
|
||||
<Field
|
||||
label="脚本文件或相对路径"
|
||||
error={errors.script?.script?.message}
|
||||
@@ -402,6 +412,11 @@ export function TaskEditorModal({
|
||||
<span>Windows 原生环境</span>
|
||||
</div>
|
||||
<div className="cli-preview-body">
|
||||
{scriptPreview.venv.trim() ? (
|
||||
<div className="cli-line-env">
|
||||
set VIRTUAL_ENV={scriptPreview.venv.trim()}
|
||||
</div>
|
||||
) : null}
|
||||
{scriptPreview.env
|
||||
.filter((item) => item.key.trim())
|
||||
.map((item, index) => (
|
||||
@@ -416,7 +431,7 @@ export function TaskEditorModal({
|
||||
</div>
|
||||
))}
|
||||
<div className="cli-line-cmd">
|
||||
{scriptPreview.interpreter.trim() || 'python.exe'}{' '}
|
||||
{formatInterpreterPreview(scriptPreview)}{' '}
|
||||
{scriptPreview.script.trim() || 'main.py'}
|
||||
{formatArgumentPreview(scriptPreview.args)}
|
||||
</div>
|
||||
@@ -598,6 +613,15 @@ function formatArgumentPreview(argumentsList: KeyValueFormValue[]): string {
|
||||
return values.length ? ` ${values.join(' ')}` : ''
|
||||
}
|
||||
|
||||
function formatInterpreterPreview(
|
||||
script: TaskFormValues['script'],
|
||||
): string {
|
||||
if (script.venv.trim()) {
|
||||
return `${script.venv.trim().replace(/[\\/]+$/, '')}\\Scripts\\python.exe`
|
||||
}
|
||||
return script.interpreter.trim() || 'python.exe'
|
||||
}
|
||||
|
||||
function isSensitiveName(name: string): boolean {
|
||||
const normalized = name.toUpperCase()
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user