diff --git a/crates/bashkit/src/builtins/python.rs b/crates/bashkit/src/builtins/python.rs index f7166cd2..82a13343 100644 --- a/crates/bashkit/src/builtins/python.rs +++ b/crates/bashkit/src/builtins/python.rs @@ -256,12 +256,17 @@ impl Builtin for Python { )); }; + // Merge env and variables so exported vars (set via `export`) are visible + // to Python's os.getenv(). Variables override env (bash semantics). + let mut merged_env = ctx.env.clone(); + merged_env.extend(ctx.variables.iter().map(|(k, v)| (k.clone(), v.clone()))); + run_python( &code, &filename, ctx.fs.clone(), ctx.cwd, - ctx.env, + &merged_env, &self.limits, ) .await diff --git a/crates/bashkit/tests/spec_cases/python/python.test.sh b/crates/bashkit/tests/spec_cases/python/python.test.sh index 6a61b3be..f518af26 100644 --- a/crates/bashkit/tests/spec_cases/python/python.test.sh +++ b/crates/bashkit/tests/spec_cases/python/python.test.sh @@ -409,7 +409,6 @@ print(a, b, c)" ### end ### python3_nested_dict_access -### skip: Monty dict literal in bash quoting needs single-quote support # Nested data structures python3 -c "data = {'users': [{'name': 'Alice'}]} print(data['users'][0]['name'])" @@ -511,7 +510,6 @@ print(count)" ### end ### python3_vfs_getenv -### skip: export propagation to ctx.env may not work in spec test runner # Read environment variables from Python export MY_TEST_VAR=hello_from_env python3 -c "import os