Skip to content

Fixes env vars in languages other than Python #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
15cceb9
env var handling in languages other than python
mishushakov May 14, 2025
3d9cb5b
added bash to env var processing
mishushakov May 15, 2025
f34cf8f
reset env variables to global in case of override or delete them afte…
mishushakov May 21, 2025
cd0e3ef
Merge branch 'main' into environment-variables-are-not-accessible-whe…
mishushakov Jun 3, 2025
bcfba5d
moved kernel pre-init to lifespan
mishushakov Jun 3, 2025
f4a6584
removed unused 0001_envs.py
mishushakov Jun 3, 2025
872c426
Merge branch 'main' into environment-variables-are-not-accessible-whe…
jakubno Jun 6, 2025
ab53907
added tests
mishushakov Jun 6, 2025
60c1a06
changed logic for setting env vars like setting cwd
mishushakov Jun 6, 2025
b8f0f8e
print > logger
mishushakov Jun 6, 2025
5370c93
updated JS SDK tests for env vars
mishushakov Jun 6, 2025
fe6bd96
env vars tests for Python
mishushakov Jun 6, 2025
1ba8718
added env var tests for r
mishushakov Jun 6, 2025
ad92618
changed python env var setting using ipython syntax
mishushakov Jun 6, 2025
de3bb5d
fixed setting env vars in java
mishushakov Jun 6, 2025
1845152
fixes r
mishushakov Jun 6, 2025
45a18e0
updated tests (bash mostly)
mishushakov Jun 6, 2025
3bf7cdb
testing resetting to default in case of override
mishushakov Jun 6, 2025
7f9b10f
fix regression in python test
mishushakov Jun 6, 2025
76f15f8
async http client for requesting env vars
mishushakov Jun 6, 2025
ac16a84
updated tests - use correct template
mishushakov Jul 7, 2025
645f91d
fixes env vars in java
mishushakov Jul 8, 2025
2072a8e
set global envs on first execution
mishushakov Jul 8, 2025
02b4796
removed deno tests due timeout
mishushakov Jul 8, 2025
94804b4
fixes async python tests
mishushakov Jul 8, 2025
24eb4bd
fixes sync python tests
mishushakov Jul 8, 2025
7e93417
fixes r tests
mishushakov Jul 8, 2025
761d36c
small oversight in r async test
mishushakov Jul 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions template/server/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,21 +183,24 @@ async def execute(
async with self._lock:
if env_vars:
vars_to_set = {**global_env_vars, **env_vars}

# if there is an indent in the code, we need to add the env vars at the beginning of the code
lines = code.split("\n")
indent = 0
for i, line in enumerate(lines):
if line.strip() != "":
indent = len(line) - len(line.lstrip())
break
env_vars_snippet = ""

if self.language == "python":
code = (
indent * " "
+ f"os.environ.set_envs_for_execution({vars_to_set})\n"
+ code
)
env_vars_snippet = f"os.environ.set_envs_for_execution({vars_to_set})\n"
elif self.language in ["javascript", "typescript"]:
env_vars_snippet = "\n".join([f"process.env['{k}'] = '{v}';" for k, v in vars_to_set.items()])
elif self.language == "deno":
env_vars_snippet = "\n".join([f"Deno.env.set('{k}', '{v}');" for k, v in vars_to_set.items()])
elif self.language == "r":
env_vars_snippet = "\n".join([f"Sys.setenv('{k}' = '{v}')" for k, v in vars_to_set.items()])
elif self.language == "java":
env_vars_snippet = "\n".join([f"System.setProperty('{k}', '{v}');" for k, v in vars_to_set.items()])
else:
raise Exception(f"Unsupported language: {self.language}")

print(f"Setting env vars: {env_vars_snippet}")
request = self._get_execute_request(str(uuid.uuid4()), env_vars_snippet, False)
await self._ws.send(request)

if self.language == "typescript":
logger.info("Compiling TypeScript: %s", code)
Expand Down
Loading