Skip to content

Commit cf3b482

Browse files
committed
Use uv for venv setup; create workspace venv with pydantic automatically
1 parent d0e0728 commit cf3b482

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

codegen-llm/src/codegen.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,14 @@ function validatePrerequisites(opts: CodegenOptions): void {
160160
);
161161
}
162162

163-
// Check Python + pydantic are available. Not fatal — the Codex agent has
164-
// full access and can install pydantic itself during the run.
163+
// uv must be available (used to manage the workspace venv).
165164
try {
166-
const version = execSync(
167-
'python3 -c "import pydantic; print(pydantic.VERSION)"',
168-
{ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] },
169-
).trim();
170-
log(opts, `Found pydantic ${version}`);
165+
execSync("uv --version", {
166+
encoding: "utf8",
167+
stdio: ["pipe", "pipe", "pipe"],
168+
});
171169
} catch {
172-
console.warn(
173-
"Warning: pydantic not found on the host Python.\n" +
174-
"The Codex agent will attempt to install it, but you can also run:\n" +
175-
" pip install 'pydantic>=2.9.0'",
176-
);
170+
throw new Error("uv is required and was not found on PATH.");
177171
}
178172
}
179173

@@ -189,6 +183,23 @@ function setupWorkspace(workDir: string, opts: CodegenOptions): void {
189183
// Create the output directory the agent writes into
190184
fs.mkdirSync(path.join(workDir, "generated"), { recursive: true });
191185

186+
// Create a venv with pydantic via uv so that both the agent and our
187+
// host-side verification have a working Python regardless of whether
188+
// the system Python is Nix-managed / immutable.
189+
log(opts, "Creating Python venv with pydantic...");
190+
execSync("uv venv .venv", { cwd: workDir, stdio: "pipe" });
191+
execSync("uv pip install 'pydantic>=2.9.0'", {
192+
cwd: workDir,
193+
stdio: "pipe",
194+
timeout: 120_000,
195+
env: { ...process.env, VIRTUAL_ENV: `${workDir}/.venv` },
196+
});
197+
const version = execSync(
198+
'.venv/bin/python -c "import pydantic; print(pydantic.VERSION)"',
199+
{ cwd: workDir, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] },
200+
).trim();
201+
log(opts, `Installed pydantic ${version} in workspace venv`);
202+
192203
// Minimal git init so Codex is happy (belt-and-suspenders alongside
193204
// skipGitRepoCheck)
194205
try {
@@ -220,7 +231,7 @@ function runVerification(workDir: string): VerifyResult {
220231

221232
try {
222233
const output = execSync(
223-
"python3 verify_schema.py schema.json generated",
234+
".venv/bin/python verify_schema.py schema.json generated",
224235
{
225236
cwd: workDir,
226237
encoding: "utf8",

codegen-llm/src/prompts.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,10 @@ compare against the original.
179179
180180
After generating all files, run:
181181
182-
python verify_schema.py schema.json generated
182+
.venv/bin/python verify_schema.py schema.json generated
183+
184+
A Python venv with pydantic is already set up at \`.venv/\` in the workspace.
185+
Always use \`.venv/bin/python\` to run Python.
183186
184187
This script:
185188
1. Loads the original schema.json
@@ -194,9 +197,6 @@ This script:
194197
195198
## Process
196199
197-
0. First, make sure pydantic is installed:
198-
\`pip install 'pydantic>=2.9.0'\`
199-
(Skip if it's already available.)
200200
1. Start by reading the service registry in the TypeScript source to get the
201201
full list of services.
202202
2. Read the TypeScript source for a few representative services to understand
@@ -209,7 +209,7 @@ This script:
209209
for naming guidance.
210210
7. Generate \`_schema_map.py\`.
211211
8. Generate the top-level \`__init__.py\` with the \`${opts.clientName}\` client class.
212-
9. Run \`python verify_schema.py schema.json generated\`
212+
9. Run \`.venv/bin/python verify_schema.py schema.json generated\`
213213
10. Fix any errors and re-run until verification passes.
214214
215215
## Important notes
@@ -243,7 +243,7 @@ ${verificationOutput}
243243
Please read the error messages carefully, fix the generated Pydantic models
244244
to resolve every mismatch, and then re-run:
245245
246-
python verify_schema.py schema.json generated
246+
.venv/bin/python verify_schema.py schema.json generated
247247
248248
Keep fixing and re-running until verification passes.
249249
`.trim();

0 commit comments

Comments
 (0)