forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.ts
More file actions
67 lines (56 loc) · 1.98 KB
/
Copy pathsetup.ts
File metadata and controls
67 lines (56 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { checkSubprocess, runSubprocessCapture } from '../../../lib';
export type PythonSetupStatus = 'success' | 'uv_not_found' | 'venv_failed' | 'install_failed';
export interface PythonSetupResult {
status: PythonSetupStatus;
error?: string;
}
export interface PythonSetupOptions {
projectDir: string;
venvName?: string;
}
/**
* Check if uv is available on the system.
*/
export async function checkUvAvailable(): Promise<boolean> {
return checkSubprocess('uv', ['--version']);
}
/**
* Create a Python virtual environment using uv.
*/
export async function createVenv(projectDir: string, venvName = '.venv'): Promise<PythonSetupResult> {
const result = await runSubprocessCapture('uv', ['venv', venvName], { cwd: projectDir });
if (result.code === 0) {
return { status: 'success' };
}
return { status: 'venv_failed', error: result.stderr || result.stdout };
}
/**
* Install dependencies using uv sync.
*/
export async function installDependencies(projectDir: string): Promise<PythonSetupResult> {
const result = await runSubprocessCapture('uv', ['sync'], { cwd: projectDir });
if (result.code === 0) {
return { status: 'success' };
}
return { status: 'install_failed', error: result.stderr || result.stdout };
}
/**
* Set up a Python project: create venv and install dependencies.
* Returns a result with status and optional error details.
*/
export async function setupPythonProject(options: PythonSetupOptions): Promise<PythonSetupResult> {
if (process.env.AGENTCORE_SKIP_INSTALL) return { status: 'success' };
const { projectDir, venvName = '.venv' } = options;
const uvAvailable = await checkUvAvailable();
if (!uvAvailable) {
return {
status: 'uv_not_found',
error: 'uv command not found. Install it with: curl -LsSf https://astral.sh/uv/install.sh | sh',
};
}
const venvResult = await createVenv(projectDir, venvName);
if (venvResult.status !== 'success') {
return venvResult;
}
return installDependencies(projectDir);
}