Skip to content

Commit 15e88e0

Browse files
chaliyclaude
andauthored
fix(builtins): make exported variables visible to Python's os.getenv (#486)
## Summary - Merged `ctx.variables` into env when running Python code so `export VAR=val` is visible to `os.getenv()` - Unskipped two Python spec tests: `python3_vfs_getenv` and `python3_nested_dict_access` Closes #316 ## Test plan - [x] python3_vfs_getenv spec test now passes - [x] python3_nested_dict_access spec test now passes - [x] All existing Python tests pass Co-authored-by: Claude <noreply@anthropic.com>
1 parent de0b714 commit 15e88e0

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

crates/bashkit/src/builtins/python.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,17 @@ impl Builtin for Python {
256256
));
257257
};
258258

259+
// Merge env and variables so exported vars (set via `export`) are visible
260+
// to Python's os.getenv(). Variables override env (bash semantics).
261+
let mut merged_env = ctx.env.clone();
262+
merged_env.extend(ctx.variables.iter().map(|(k, v)| (k.clone(), v.clone())));
263+
259264
run_python(
260265
&code,
261266
&filename,
262267
ctx.fs.clone(),
263268
ctx.cwd,
264-
ctx.env,
269+
&merged_env,
265270
&self.limits,
266271
)
267272
.await

crates/bashkit/tests/spec_cases/python/python.test.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ print(a, b, c)"
409409
### end
410410

411411
### python3_nested_dict_access
412-
### skip: Monty dict literal in bash quoting needs single-quote support
413412
# Nested data structures
414413
python3 -c "data = {'users': [{'name': 'Alice'}]}
415414
print(data['users'][0]['name'])"
@@ -511,7 +510,6 @@ print(count)"
511510
### end
512511

513512
### python3_vfs_getenv
514-
### skip: export propagation to ctx.env may not work in spec test runner
515513
# Read environment variables from Python
516514
export MY_TEST_VAR=hello_from_env
517515
python3 -c "import os

0 commit comments

Comments
 (0)