Skip to content

rex environment lookups do not respect platform case-sensitivity rules #2089

@nrusch

Description

@nrusch

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)

  1. 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
  1. From a shell, set SomeVariable to a value (e.g., from pwsh, $env:SomeVariable = "1").
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions