Fix rex parent_environ case sensitivity on Windows#2098
Open
thc1006 wants to merge 1 commit into
Open
Conversation
|
|
Author
|
Closing+reopening to retrigger Read the Docs (initial build failed during clone, 2s duration, generic clone error — fork branch is public and accessible). |
On Windows env-var keys are case-insensitive natively. os.environ preserves that contract via os._Environ, but a plain dict copy of it (or any user-built dict) does not. Until now, ActionManager consumed whatever Mapping the caller passed as-is, so a package commands() that referenced env.SomeVariable against a parent_environ holding the same key under a different case raised RexUndefinedVariableError. Wrap the caller-supplied parent_environ in a small read-only case-insensitive proxy on the Windows path only. The proxy is module private; the wrapping is gated on platform_.name == "windows" and is idempotent so re-entering the gate is a no-op. Linux and macOS take the existing identity assignment unchanged. Also adds a Windows-only regression test that mirrors the issue reproducer and asserts both direct lookup and end-to-end rex code paths against a mixed-case parent_environ. Closes AcademySoftwareFoundation#2089 Reported by @nrusch. Signed-off-by: thc1006 <84045975+thc1006@users.noreply.github.com>
f3db9fb to
fa436d7
Compare
Author
|
Status note for reviewers:
Local pre-push validation: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Windows, environment variable keys are case-insensitive natively.
os.environpreserves that contract through Python'sos._Environwrapper, but a plaindictcopy of it (or any user-built dict) does not. Until now,ActionManagerconsumed whateverMappingthe caller passed as-is, so a package whosecommands()referencedenv.SomeVariableagainst aparent_environthat held the same variable under a different casing would raise:Issue #2089 has a clean reproducer that follows exactly this shape:
dict(os.environ)is passed toResolvedContext.get_environ, and a package looks upenv.SomeVariablewhile the dict only hasSOMEVARIABLE.The fix wraps a caller-supplied
parent_environin a small read-only case-insensitive proxy, gated onplatform_.name == "windows". On Linux and macOS the assignment reduces to the existing identity passthrough, so non-Windows is byte-for-byte unchanged. The proxy is a 5-methodMappingprivate torex.py; keys are upper-cased once at construction time so iteration matches whatos.environalready yields on Windows, and last-write-wins on case collisions matches howos.environitself collapses duplicates. Thenot isinstance(...)guard in the gate keeps wrapping idempotent.The new
test_parent_environ_case_insensitive_on_windowsmirrors the issue's reproducer through_create_executor, asserting both directparent_environ[...]lookup across casings and an end-to-endgetenv("SOMEVARIABLE")/setenv("RESULT", ...)flow against a{"SomeVariable": ...}dict. It skips on non-Windows since the wrapping is a no-op there.Verified locally:
pytest src/rez/tests/test_rex.pyis green (15 pass + 1 skip on Linux), fullrez-selftestis green in a hermetic Python 3.11 container (Ran 259 tests in 24.997s, OK),flake8is clean, andmypy | mypy-baseline filterreports no new violations above the pinned baseline.Closes #2089
Reported by @nrusch. Independent diagnosis previously posted in #2093 (closed because the author could not satisfy the EasyCLA/DCO requirement, not for technical reasons).