-
-
Notifications
You must be signed in to change notification settings - Fork 529
Provision: ignore other test environments #2865
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Provision: ignore other test environments #2865
Conversation
src/tox/session/env_select.py
Outdated
@@ -241,13 +242,29 @@ def _finalize_config(self) -> None: | |||
self._state.conf.core.mark_finalized() | |||
|
|||
def _build_run_env(self, name: str) -> RunToxEnv | None: | |||
if self._provision is not None and self._provision[0] is False and name == self._provision[1]: | |||
provision_on = provision_tox_env = provision_loader = None |
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 we just need to change the base for the provision env.
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.
not sure how to proceed on that one... but i'll think about it.
i'm off for the night here. it's been really fun hacking on tox
today, thanks for the opportunity.
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.
See
Line 92 in a2222e9
base=[], # disable inheritance for provision environments |
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.
Right in the middle of that now. I think it's related to caching the "base"
value from the Ini before the provision loader is even added to env_conf
.
> /Users/masen/code/tox-dev/tox/.tox/py311/lib/python3.11/site-packages/tox/session/env_select.py(259)_build_run_env()
-> env_conf.loaders.insert(0, provision_loader)
(Pdb) env_conf._defined["base"]
ConfigDynamicDefinition(keys=('base',), desc=inherit missing keys from these sections, of_type=typing.List[str], default=['testenv'], _cache=['testenv'])
(Pdb) env_conf.loaders
[IniLoader(section=testenv, overrides={})]
If I reset the _cache
values for the following keys after adding the provision_loader
at index 0, then they can get the new values from the provision_loader
.
(Pdb) tuple(env_conf._defined)
('set_env', 'setenv', 'base')
Something like
for config_def in env_conf._defined:
if isinstance(config_def, ConfigDynamicDefinition):
config_def._cache = _PLACE_HOLDER
But this actually doesn't work, because the loader for the testenv
section is already in the chain at this point; removing it expicitly would be messy.
So the approach I'm taking now is to update Config.get_env
to accept a base
parameter, and if that's passed through it overrides the defaults. I couldn't find a way to reliably NOT include the base via config only, since shimming in the provision_loader
occurs after Config.get_env
, so the testenv
default base just gets baked into the env's loaders
.
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 instead insert we need to use https://github.com/tox-dev/tox/blob/main/src/tox/session/cmd/devenv.py#L38, as it's too late for inserting the loader 🤔
3dad658
to
cb7051a
Compare
src/tox/session/env_select.py
Outdated
@@ -241,13 +241,29 @@ def _finalize_config(self) -> None: | |||
self._state.conf.core.mark_finalized() | |||
|
|||
def _build_run_env(self, name: str) -> RunToxEnv | None: | |||
if self._provision is not None and self._provision[0] is False and name == self._provision[1]: | |||
provision_on = provision_tox_env = provision_loader = None |
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 file needs to be untouched, only the provision.py should be changed.
A testenv depends on a runner supplied via a plugin that tox needs to provision. Added the plugin to demo_pkg_inline since it seemed like the easiest place.
Ensure that the provision environment config is available _before_ attempting to load it, otherwise `base` will take the default resulting in values from the testenv being inadvertently inherited.
When running provision, ignore other environments, since their configuration might not be valid until running in the provisioned environment. Fix tox-dev#2862
Now that the loader is seeded via state.conf.memory_seed_loaders, the provision loader no longer needs to be passed through this interface.
cb7051a
to
32ec2b0
Compare
provision: seed loader with state.conf.memory_seed_loadersSmall change that fixes the base inheritance... with this change, the provisioning environment no longer implicitly inherits from testenv. env_select: ignore other env configurations when provisioningThis change is necessary to prevent accidentally loading configuration from other environments during provisioning. env_select: _mark_provision: remove loader argumentThis commit is just a cleanup, now that the loader is being pre-seeded, it doesn't need to be passed via Hopefully with a smaller diff, this is easier to review. |
This PR contains the following updates: | Package | Type | Update | Change | Pending | |---|---|---|---|---| | [tox](https://github.com/tox-dev/tox) ([changelog](https://tox.wiki/en/latest/changelog.html)) | dev | patch | `4.3.2` -> `4.3.3` | `4.4.2` (+4) | --- ### Release Notes <details> <summary>tox-dev/tox</summary> ### [`v4.3.3`](https://github.com/tox-dev/tox/releases/tag/4.3.3) [Compare Source](https://github.com/tox-dev/tox/compare/4.3.2...4.3.3) #### What's Changed - Provision: ignore other test environments by [@​masenf](https://github.com/masenf) in [https://github.com/tox-dev/tox/pull/2865](https://github.com/tox-dev/tox/pull/2865) **Full Changelog**: tox-dev/tox@4.3.2...4.3.3 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMDEuMCIsInVwZGF0ZWRJblZlciI6IjM0LjEwMS4wIn0=--> Co-authored-by: descope[bot] <descope[bot]@users.noreply.github.com>
When running provision, ignore other environments, since their configuration might not be valid until running in the provisioned environment.
When creating provision environment, seed the loader early via
memory_seed_loader
to ensure it's available when the environment is created. The provision environment must be configured explicitly, it will not inherit from[testenv]
.Fix #2862
Thanks for contribution
Please, make sure you address all the checklists (for details on how see
development documentation)!
tox -e fix
)docs/changelog
folder