On Windows, environment variable keys are case-insensitive for lookup and assignment; Python's wrapper for os.environ hides this away behind a Mapping interface that normalizes keys to uppercase internally.
However, the rex bindings that expose the environment to packages do not handle a provided parent_environ dict in a similarly case-insensitive way on Windows. Thus, if a case-sensitive mapping is provided for parent_environ (e.g. by copying and modifying os.environ), and a package tries to look up an environment variable that is present in parent_environ but uses a different casing than parent_environ's entry, it will error similarly to:
Error in commands in package '...':
Referenced undefined environment variable: SomeVariable
This error does not occur when a parent_environ override is not provided, as rex will fall back to binding os.environ, and thus lookups will be appropriately case-insensitive on Windows.
Environment
- Windows 10
- Rez 3.3.0+ (dev build)
- Rez python 3.11.9
To Reproduce (Windows)
- Create and install a package whose
commands tries to access an environment variable using a TitleCase name, e.g:
name = "env_test"
build_command = False
def commands():
some_value = env.SomeVariable
- From a shell, set
SomeVariable to a value (e.g., from pwsh, $env:SomeVariable = "1").
- Using
rez-python, use the rez API to create a ResolvedContext using the test package and get its environment, passing a dict copy of os.environ as parent_environ:
import os
from rez.resolved_context import ResolvedContext
ctx = ResolvedContext(["env_test"], caching=False, add_implicit_packages=False)
ctx.get_environ(parent_environ=dict(os.environ))
If you instead omit parent_environ or pass an explicit reference to os.environ, it will work fine due to the underlying case-insensitive lookup.
On Windows, environment variable keys are case-insensitive for lookup and assignment; Python's wrapper for
os.environhides this away behind aMappinginterface that normalizes keys to uppercase internally.However, the
rexbindings that expose the environment to packages do not handle a providedparent_environdict in a similarly case-insensitive way on Windows. Thus, if a case-sensitive mapping is provided forparent_environ(e.g. by copying and modifyingos.environ), and a package tries to look up an environment variable that is present inparent_environbut uses a different casing thanparent_environ's entry, it will error similarly to:This error does not occur when a
parent_environoverride is not provided, asrexwill fall back to bindingos.environ, and thus lookups will be appropriately case-insensitive on Windows.Environment
To Reproduce (Windows)
commandstries to access an environment variable using a TitleCase name, e.g:SomeVariableto a value (e.g., from pwsh,$env:SomeVariable = "1").rez-python, use therezAPI to create aResolvedContextusing the test package and get its environment, passing adictcopy ofos.environasparent_environ:If you instead omit
parent_environor pass an explicit reference toos.environ, it will work fine due to the underlying case-insensitive lookup.