Skip to content

Add and use new EnvironDict class - #744

Merged
cottsay merged 1 commit into
masterfrom
cottsay/environ-dict
Sep 11, 2026
Merged

cottsay merged 1 commit into
masterfrom
cottsay/environ-dict

Conversation

@cottsay

@cottsay cottsay commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

On Win32, the os.environ mapping behaves in many case-insensitive ways. When we copy os.environ to a typical dict instance, we lose those behaviors.

This new class preserves the case insensitivity on Windows and behaves like a normal OrderedDict on non-Windows platforms.

In draft for now, because I'm still trying to understand the exact behaviors that Windows exhibits. In particular, it might be closer in behavior to just convert all keys to UPPERCASE before accessing the underlying dict.

Okay, from what I can tell, Python converts all keys in os.environ to UPPERCASE on Windows, but since colcon is capturing the environment variables using set, we don't see the same treatment. If the goal was to align EnvironDict with os.environ on Windows precisely, we'd want to convert everything to UPPERCASE as it seems to implicitly do. However, given that we want this class to be used on the variables we capture with set as well, I think we should just preserve the original case but make access case-insensitive.

Assisted-by: Gemini 3.5 Flash

Note

The Windows implementation of EnvironDict is a lot bigger than it should be. Implementing Mapping was a lot simpler, but the public colcon API specifically returns an instance of dict, so we need the new class to also inherit from dict to maintain compatibility.

@cottsay cottsay self-assigned this Aug 18, 2026
@cottsay
cottsay force-pushed the cottsay/environ-dict branch from ec349de to 9359153 Compare August 18, 2026 20:51
@codecov

codecov Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.17117% with 32 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.23%. Comparing base (6428dca) to head (c589bee).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
colcon_core/environment_variable.py 70.00% 23 Missing and 7 partials ⚠️
colcon_core/task/python/test/__init__.py 50.00% 1 Missing ⚠️
colcon_core/task/python/test/pytest.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #744      +/-   ##
==========================================
- Coverage   87.66%   87.23%   -0.43%     
==========================================
  Files          74       75       +1     
  Lines        4442     4686     +244     
  Branches      771      816      +45     
==========================================
+ Hits         3894     4088     +194     
- Misses        433      468      +35     
- Partials      115      130      +15     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cottsay
cottsay force-pushed the cottsay/environ-dict branch 3 times, most recently from d38796c to 6935571 Compare August 18, 2026 21:32
@cottsay
cottsay marked this pull request as ready for review August 18, 2026 21:46
@cottsay

cottsay commented Sep 1, 2026

Copy link
Copy Markdown
Member Author

Tapping Pepper for review here (via @claraberendsen)

@knmcguire knmcguire left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! and your explanation makes sense

The one thing perhaps to mention is that 'move_to_end()' from OrderedDict is not changed and can't handle the case-sensitive cases. It's not used anywhere though... so... I don't think it has consequences now?

fyi, did you use any agents here? It's not mentioned in the commits

Comment thread test/test_environment_variable.py Outdated
On Win32, the `os.environ` mapping behaves in many case-insensitive
ways. When we copy `os.environ` to a typical `dict` instance, we lose
those behaviors.

This new class preserves the case insensitivity on Windows and behaves
like a normal OrderedDict on non-Windows platforms.

Assisted-by: Gemini 3.5 Flash <gemini@google.com>
@cottsay
cottsay force-pushed the cottsay/environ-dict branch from 6935571 to c589bee Compare September 11, 2026 20:06
@cottsay

cottsay commented Sep 11, 2026

Copy link
Copy Markdown
Member Author

'move_to_end()' from OrderedDict is not changed

An oversight, addressed in the latest change.

did you use any agents here? It's not mentioned in the commits

I did and I definitely forgot to mention it. Good call out.

@cottsay
cottsay merged commit 98416ed into master Sep 11, 2026
46 checks passed
@cottsay
cottsay deleted the cottsay/environ-dict branch September 11, 2026 20:14
@cottsay cottsay added this to the 0.21.2 milestone Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants