-
-
Notifications
You must be signed in to change notification settings - Fork 151
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
Enhance environment variables passing #652
Enhance environment variables passing #652
Conversation
6c03a6c
to
c7b41ee
Compare
nox/command.py
Outdated
# Ensure systemroot is passed down, otherwise Windows will explode. | ||
clean_env["SYSTEMROOT"] = os.environ.get("SYSTEMROOT", "") | ||
for var in _ENV_VARS_TO_ALWAYS_INCLUDE: | ||
if var in os.environ: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this has the potential to be a race as written (possible the environment var is there when checked on the first check, but not on assignment).
nox/sessions.py
Outdated
self, | ||
*args: str, | ||
env: dict[str, str] | None = None, | ||
include_invocation_env_vars: Iterable[str] | bool = True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this approach is worth discussing. In a way it is a subtle improvement over the suggestion in the bug thread (where passing an env var name with None as value meant "use the system". I also think it may more clear as it keeps this to just keys.
That said, I am not a huge fan of type of this var and that, in a way, it ends up overriding truthiness of the dict.
I think having the on/off makes a lot of sense, as this allows users of nox to control their sessions fully. If most folks are going to use this to bring 1-2 vars, it doesn't seem too overwhelming to need to do it via env:
result = session.run(
...
env={"SYSTEM_ROOT": os.environ["SYSTEM_ROOT"]},
...
)
That said, if it is more common for a user need many of them, this does cut down a bit on boilerplate. Though I can also imagine using a dict comp to do this in my code anyway:
env = {k: os.environ.get(k) for k in ["SYSTEM_ROOT", "LANGUAGE"]}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the switch by itself is a good idea, potentially a rename to something a bit easier e.g. include_outer
? But I agree on the type I think it should be just a bool on/off (with a default of True
so the current default behaviour does not change).
I think 90%+ people who have a need to define env vars will have only a few. And if not the dictionary comp above works well, could even use a .env
file or similar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also not a huge fan of maintaining a list of "special" env vars to always pass through, although I'm not entirely sure how else we'd do it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I agree that on/off is better, writing out the type annotation for that parameter also rubbed me the wrong way a bit, but wanted it to behave the way it was described in the issue. I guess it makes sense to just stick to on/off and keep the old behavior when we only care about passing SYSTEM_ROOT
on windows, when it comes to other env variables it is up to the user to include them when include_outer=False/include_invovation_env_vars=False
. WDYT?
6b3ea0e
to
7e9c83f
Compare
… enables a more granular control of the environment variables passing
7e9c83f
to
04e0d86
Compare
Thanks for doing the review! I agree @crwilcox's proposal. I think it addresses the original issue sufficiently, is clearer and easier to understand. This should be ready for another look. |
This looks great to me, merging. :) |
## [0.0.20](v0.0.19...v0.0.20) (2024-03-04) ### Chores * **deps:** bump wntrblm/nox from 2023.04.22 to 2024.03.02 ([#57](#57)) ([d177375](d177375)), closes [wntrblm/nox#762](wntrblm/nox#762) [wntrblm/nox#787](wntrblm/nox#787) [wntrblm/nox#730](wntrblm/nox#730) [wntrblm/nox#780](wntrblm/nox#780) [wntrblm/nox#770](wntrblm/nox#770) [wntrblm/nox#707](wntrblm/nox#707) [wntrblm/nox#687](wntrblm/nox#687) [wntrblm/nox#756](wntrblm/nox#756) [wntrblm/nox#652](wntrblm/nox#652) [wntrblm/nox#712](wntrblm/nox#712) [wntrblm/nox#781](wntrblm/nox#781) [wntrblm/nox#786](wntrblm/nox#786) [wntrblm/nox#684](wntrblm/nox#684) [wntrblm/nox#723](wntrblm/nox#723) [wntrblm/nox#725](wntrblm/nox#725) [wntrblm/nox#714](wntrblm/nox#714) [wntrblm/nox#715](wntrblm/nox#715) [wntrblm/nox#696](wntrblm/nox#696) [wntrblm/nox#774](wntrblm/nox#774) [wntrblm/nox#782](wntrblm/nox#782) [wntrblm/nox#722](wntrblm/nox#722) [wntrblm/nox#724](wntrblm/nox#724) [wntrblm/nox#721](wntrblm/nox#721) [wntrblm/nox#744](wntrblm/nox#744) [wntrblm/nox#738](wntrblm/nox#738) [wntrblm/nox#762](wntrblm/nox#762) [wntrblm/nox#787](wntrblm/nox#787) [wntrblm/nox#730](wntrblm/nox#730) [wntrblm/nox#780](wntrblm/nox#780) [wntrblm/nox#770](wntrblm/nox#770) [wntrblm/nox#707](wntrblm/nox#707) [wntrblm/nox#687](wntrblm/nox#687) [wntrblm/nox#756](wntrblm/nox#756) [wntrblm/nox#652](wntrblm/nox#652) [wntrblm/nox#712](wntrblm/nox#712) [wntrblm/nox#781](wntrblm/nox#781) [wntrblm/nox#786](wntrblm/nox#786) [wntrblm/nox#684](wntrblm/nox#684) [wntrblm/nox#723](wntrblm/nox#723) [wntrblm/nox#725](wntrblm/nox#725) [wntrblm/nox#714](wntrblm/nox#714) [wntrblm/nox#715](wntrblm/nox#715) [wntrblm/nox#696](wntrblm/nox#696) [wntrblm/nox#774](wntrblm/nox#774) [wntrblm/nox#782](wntrblm/nox#782) [wntrblm/nox#722](wntrblm/nox#722) [wntrblm/nox#724](wntrblm/nox#724) [wntrblm/nox#721](wntrblm/nox#721) [wntrblm/nox#744](wntrblm/nox#744) [#789](https://github.com/msclock/sphinx-deployment/issues/789) [#787](https://github.com/msclock/sphinx-deployment/issues/787) [#786](https://github.com/msclock/sphinx-deployment/issues/786) [#781](https://github.com/msclock/sphinx-deployment/issues/781) [#784](https://github.com/msclock/sphinx-deployment/issues/784) [#780](https://github.com/msclock/sphinx-deployment/issues/780) [#730](https://github.com/msclock/sphinx-deployment/issues/730) [#782](https://github.com/msclock/sphinx-deployment/issues/782) [#783](https://github.com/msclock/sphinx-deployment/issues/783) [#762](https://github.com/msclock/sphinx-deployment/issues/762) ### CI * set proper permission for preview job ([#56](#56)) ([d65e8a1](d65e8a1))
Closes #253
Introduced a new parameter
include_invocation_env_vars
to thesession.run
related methods. It can be a boolean or an iterable of vars that should be included from the nox invocation environment. Some env vars (inspired by tox are always passed in to ensure proper functionality of stdlib functions and pip.