-
Notifications
You must be signed in to change notification settings - Fork 957
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
Don't uppercase Windows environment variables #16122
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I understand the intent, I am concerned about the usage of import nt
conans/util/windows.py
Outdated
@@ -1,3 +1,4 @@ | |||
import nt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is mostly a private Python implementation detail, I am concerned about using this directly, as this is not public documented Python library: https://docs.python.org/3/library/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've found the recommendation here: https://stackoverflow.com/questions/19023238/why-python-uppercases-all-environment-variables-in-windows
nt
module is also mentioned here: https://www.oreilly.com/library/view/python-standard-library/0596000960/ch12s12.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be necessary to illustrate with a failing test what is the behavior that we want to fix. Because independently of what it is being done here, Python os.environ
will still be uppercase later, because this is how Python environment works in Windows, as environment vars in Windows are case-insensitive.
Yes, and from the link you shared:
|
Yor need a real problem or just a test case? Suppose you run a bash script under Cygwin that reads |
A test case that illustrate and captures the essence of the real problem. It doesn't need to be the full real problem, but the closest it is, the better. |
Yes, but it's exactly that rare case where |
In this case, that function is just modifying the |
The real problem: I'm trying to package https://github.com/ocaml/opam. I do: def build_requirements(self):
if self.settings.os == "Windows":
self.tool_requires("cygwin_installer/2.9.0")
def build(self):
port = "OCAML_PORT=msvc" if is_msvc(self) else ""
arch = "64" if self.arch = "x86_64" else ""
self.run(f"make compiler {port}{arch}", env="conanbuild")
self.run("make lib-pkg", env="conanbuild")
self.run("sh -c ./configure", env="conanbuild") and the last command fails. I spent enough time until I found that https://github.com/ocaml/opam/blob/master/shell/msvs-detect was sensible to the environment variables case. If it is really necessary, I can dig further and find out what exactly is failing. But IMHO preserving the case is generally better than changing it. |
I think it sounds more like a limitation of that script that is failing to acknowledge/implement the fact that env-vars in Windows are case-insensitive. But I agree it might be not necessary to investigate it further, and I agree that it is better if Conan doesn't do always a full restoration of the environment for just computing the Conan user home, so my above hints could be a viable solution without needing to use the |
OK, I agree not to use Lines 24 to 26 in a91972c
|
That is the thing, it is only I think this code is mostly copy & paste legacy of environment manipulation, generic way to make sure the env is restored. But for this specific case, it seems it can be greatly optimized while removing the issue of the forced uppercase. |
I see, thanks. The current implementation seems to contain another error: if |
I am not aware of this issue. When does it raise? I haven't seen anything related to this, is it possible to reproduce it? and to cover it with a test? |
https://docs.python.org/3/library/os.path.html
|
I think that "characters or bytes unrepresentable at the OS level" are hardly possible here, but then try block is just not necessary, right? |
@memsharded Can you please look at the last variant? I left try/finally for now, but if you like I can remove them completely. It would be great to have this included in 2.3.0 :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets merge it, the code is relatively straightforward, and the test looks it would be too ugly (like needing to access nt
again)
Changelog: Omit
Docs: Omit
Fix: Don't uppercase Windows environment variables
Due to manipulations with
os.environ
Conan currently uppercases all Windows environment variables. I stumbled upon a situation where this breaks a Conan-run bash script. This PR should fix that.