Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

session.env['PATH'] no longer has default value #928

Closed
tgs opened this issue Feb 10, 2025 · 3 comments
Closed

session.env['PATH'] no longer has default value #928

tgs opened this issue Feb 10, 2025 · 3 comments
Labels

Comments

@tgs
Copy link

tgs commented Feb 10, 2025

Current Behavior

Hello, thanks for Nox! It's a really nice change from tox, it's helping a lot with a package I'm working on that has a complicated build. Things that feel like a hack in tox are straightforward in nox.

I have a build that's unfortunately parametrized on the version of GCC, so I need to modify the PATH in a parametrized session. I've been doing

session.env['PATH'] = gcc_path + ":" + session.env['PATH']

With nox 2025.2.9, this results in KeyError: 'PATH'

Expected Behavior

In nox 2024.10.9, this doesn't throw an error, and instead adds gcc_path to the front of the PATH in the session.

Steps To Reproduce

import nox

@nox.session
@nox.parametrize('gcc_path', ['/first/path', '/second/path'])
def build(session, gcc_path):
    session.env['PATH'] = gcc_path + ":" + session.env['PATH']
    # I would then run pyproject-build -w which would use the
    # GCC version from the PATH

Environment

- OS: AlmaLinux 8
- Python: 3.11
- Nox: 2024.10.9 vs 2025.2.9

Anything else?

Is there some other way that I should be doing this? Like should I copy os.environ['PATH'] in?

@tgs tgs added the bug label Feb 10, 2025
@tgs tgs changed the title session.env no longer has default value session.env['PATH'] no longer has default value Feb 10, 2025
@henryiii
Copy link
Collaborator

Unless I find a way to make the env dict smarter, session.env['PATH'] = gcc_path + ":" + os.environ['PATH'] should work. The bin paths will still be prepended when it runs correctly.

@henryiii
Copy link
Collaborator

henryiii commented Feb 11, 2025

The problem is that we support session.run(include_outer_env=False), and if the outer environment PATH is already present in the session, then how can you remove it when calling session.run? While if you know you aren't going to use this, then just accessing os.environ directly is safe. See #874.

@tgs
Copy link
Author

tgs commented Feb 18, 2025

OK, I'll do that then. Thank you!

@tgs tgs closed this as completed Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants