Mirror Elixir env vars into os.environ on initialization#43
Mirror Elixir env vars into os.environ on initialization#43jonatanklosko wants to merge 4 commits intomainfrom
Conversation
| > Also note that contrarily to Elixir, changes to `os.environ` are | ||
| > automatically mirrored to the OS process environment. |
There was a problem hiding this comment.
As a consequence, if we do System.put_env("FOO", "bar"), and then we call Pythonx.uv_init(...), this will set env var "FOO" in the OS process environ. I don't think it's an issue though. @josevalim any objections?
There was a problem hiding this comment.
I think you can argue both ways: copy the Elixir env vars or keep it as is. However, given that setting the Python env vars also affect the OS ones, then there is a larger side-effect here is that initing Python changes the OS env vars, which I am not sure we should do. So I actually think we should document Python only inherits the process env vars and any other need to be copied explicitly?
There was a problem hiding this comment.
Yeah, fair enough.
c_src/pythonx.cpp
Outdated
| auto py_os_environ_clear = PyObject_GetAttrString(py_os_environ, "clear"); | ||
| raise_if_failed(env, py_os_environ_clear); | ||
| auto py_os_environ_clear_guard = PyDecRefGuard(py_os_environ_clear); | ||
| auto result = PyObject_CallNoArgs(py_os_environ_clear); | ||
| raise_if_failed(env, result); |
There was a problem hiding this comment.
Gah, we cannot call os.environ.clear() and just set everything from scratch, because Windows has env var keys like =D:, which we can read, but we cannot set 😂 So we need to diff both ways.
Closes #42.