Skip to content

Fix resetenv() calls to not crash - #2070

Open
czerouni wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
czerouni:issue_2068_cz
Open

czerouni wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
czerouni:issue_2068_cz

Conversation

@czerouni

@czerouni czerouni commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #2068

While trying to document resetenv() (which had a TODO in the docs) I noticed that Rez would always generate a python traceback when resetenv() was called.

The reason for this turns out to be that it is creating a "command" that is None because it is adding a line that is the return value of setenv. But that is always None. In any case, it doesn't do what rezconfig.py suggests it might. And it has a "friends" parameter that isn't used and whose purpose I couldn't guess at.

This PR "fixes" that by just having calls to resetenv() defer to setenv() since that is all that would currently happen even if it worked. As an aside, I think that resetenv should either be removed, or implemented as rezconfig.py implies.

@czerouni
czerouni requested a review from a team as a code owner January 12, 2026 15:40

@maxnbk maxnbk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall the fix is correct and minimal, and addresses the crash.

Biggest issue is just a lack of tests, so that we don't regress, and so that if, hypothetically, setenv ever returned something, this issue wouldn't reappear.

Something as simple of this might work?

def test_resetenv(self) -> None:
    """Test that resetenv doesn't crash and sets the variable."""
    r = ResolvedContext(["hello_world"])
    # This would crash with TypeError before the fix
    environ = r.get_environ()

Though better yet, a unit test in text_rex.py that called resetenv on a python interpreter (which would run everywhere and be independent of shell support) and verifies no crash, followed by an integration test in test_shells.py that calls resetenv through an actual shell and verifies the output doesn't contain None.

Other than that it just needs a rebase (sorry for not getting to review this sooner).

@czerouni , if you don't think you'll have the time to work on tests for this, I would not mind working on top of your branch to add some. LMK either way, but I won't unless noted.

@czerouni

czerouni commented Aug 2, 2026 via email •

Copy link
Copy Markdown
Contributor Author

@codecov

codecov Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.68%. Comparing base (c463aab) to head (c60abb6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2070      +/-   ##
==========================================
+ Coverage   62.64%   62.68%   +0.03%     
==========================================
  Files         165      165              
  Lines       20792    20792              
  Branches     3621     3621              
==========================================
+ Hits        13026    13034       +8     
+ Misses       6886     6878       -8     
  Partials      880      880              

☔ 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.

@czerouni

czerouni commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

I think this is ready, but I have a question: how are you running the ruff checks locally? There is no ruff.toml file, the tox.ini file doesn't mention it. What setup are you (plural) using to work in this codebase?

@czerouni
czerouni requested a review from maxnbk August 6, 2026 21:27
@maxnbk

maxnbk commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

I think this is ready, but I have a question: how are you running the ruff checks locally? There is no ruff.toml file, the tox.ini file doesn't mention it. What setup are you (plural) using to work in this codebase?

The ruff setup is pretty brand-new, so I don't think it's been fully worked out. To do my own ruff checks, I had to uv tool install ruff to my local system and use it that way. The setup seems to have been done entirely with CI in mind and took for granted that someone sets up a local tool. It might be that one other other in-flight ruff PRs does some more work on it, but I haven't looked yet. A tad troublesome, I agree.

@maxnbk maxnbk self-assigned this Nov 14, 2026
@maxnbk maxnbk added this to the 3.5.1 milestone Nov 14, 2026
resetenv() appended the return value of setenv() to the shell script -
which is always None - producing a 'None' command line and a traceback
whenever resetenv() was used (AcademySoftwareFoundation#2068). Since the current behaviour of a
working resetenv() is identical to setenv(), resetenv() now simply
defers to setenv().

Adds tests: a Resetenv action in the rex round-trip tests (test_rex.py)
and a per-shell output test that resetenv does not crash
(test_shells.py).

The unused 'friends' parameter is retained as-is; whether resetenv()
should be fully implemented per the rezconfig.py description or removed
is left as a design question for review.

Signed-off-by: Craig Zerouni <czerouni@gmail.com>
@maxnbk

maxnbk commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

This issue should probably be followed-up by a deprecation-level design decision of "Should resetenv be removed or actually-fully-implemented", but this PR will serve as a fix-PR to remove the crashing behavior, which is the scope for this PR. Leaving this comment as a reminder for me to create an issue for it before merging/discarding.

This branch has not been deployed

No deployments
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.

resetenv() always crashes

2 participants