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

[tox4] Document loaders on config set #2287

Closed
frenzymadness opened this issue Dec 6, 2021 · 5 comments
Closed

[tox4] Document loaders on config set #2287

frenzymadness opened this issue Dec 6, 2021 · 5 comments
Labels
bug:normal affects many people or has quite an impact
Milestone

Comments

@frenzymadness
Copy link

I'm trying to port our tox extension to the new tox 4 and I have one problem described in this thread: fedora-python/tox-current-env#42 (review)

The problem basically is that it's not possible to call get_env in tox_add_env_config because it causes an endless recursion. I need to do it so I can overwrite some settings loaded from config with values from the extension.

@frenzymadness frenzymadness added the bug:normal affects many people or has quite an impact label Dec 6, 2021
@gaborbernat
Copy link
Member

The problem basically is that it's not possible to call get_env in tox_add_env_config because it causes an endless recursion.

Can you post an example code doing this?

@frenzymadness
Copy link
Author

It has been a few weeks since I touched it last time but this should be it:

@impl
def tox_add_env_config(env_conf, config):
    loader = MemoryLoader(allowlist_externals=["*"])
    env_name = next(config.env_list())
    config.get_env(env_name, loaders=[loader])

To accomplish the same, I have my own executor where I can simply rewrite the option in the request:

class CurrentEnvRunExecutor(Execute):
    def build_instance(
        self,
        request,
        options,
        out,
        err,
    ):
        # Disable check for the external commands,
        # all of them are external for us.
        request.allow = None
        return LocalSubProcessExecuteInstance(request, options, out, err)

@gaborbernat
Copy link
Member

At that point, the config is already constructed. You're trying to construct it again that's causing the infinite recursion. If you want to extend the loaders can't you directly insert the memory loader into env_conf?

@gaborbernat
Copy link
Member

gaborbernat commented Dec 6, 2021

@gaborbernat gaborbernat changed the title [tox4] Endless recursion in tox_add_env_config [tox4] Document loaders on config set Dec 6, 2021
@frenzymadness
Copy link
Author

Thanks for your help, this little piece of code solved my problem:

@impl
def tox_add_env_config(env_conf, config):
    # This allows all external commands.
    # All of them are extenal for us.
    loader = MemoryLoader(allowlist_externals=["*"])
    config.core.loaders.insert(0, loader)

I see that you want to use this issue for better documentation of loaders so I'm gonna keep it open.

@gaborbernat gaborbernat added this to the 4.0 milestone Jan 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:normal affects many people or has quite an impact
Projects
None yet
Development

No branches or pull requests

2 participants