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

tox 4: enable plugins to discover config sections & testenvs #2200

Closed
dcrosta opened this issue Sep 3, 2021 · 1 comment
Closed

tox 4: enable plugins to discover config sections & testenvs #2200

dcrosta opened this issue Sep 3, 2021 · 1 comment
Assignees
Labels
area:plugins-hooks feature:new something does not exist yet, but should
Milestone

Comments

@dcrosta
Copy link
Member

dcrosta commented Sep 3, 2021

My plugin tox-docker could benefit from being able to discover all configuration sections and/or to get a list of all testenvs from the Config.

tox-docker starts docker containers as configured by each testenv; the testenv references another section (eg [docker:nginx] by way of saying docker=nginx in the testenv). In order to discover all configuration, I need to enumerate all testenvs or all sections (and filter the list to docker:* sections).

I'm currently doing the former with:

class EnvDockerConfigSet(ConfigSet):
    def __init__(self, conf: Config) -> None:
        super().__init__(conf)

        self.add_config(
            keys=["docker"],
            of_type=EnvList,
            default=EnvList([]),
            desc="docker image configs to load",
            post_process=list,
        )

def discover_container_configs(config: Config) -> Sequence[str]:
    docker_configs = set()
    for env_name in config:
        env_config = config.get_section_config(f"testenv:{env_name}", EnvDockerConfigSet)
        docker_configs.update(env_config.load("docker"))
    return list(docker_configs)

It would be more explicit to have eg. config.get_test_envs() that returns either all testenvs, or better yet, the specific testenvs that will be run (eg due to setting -e on the commandline, or the envlist, etc).

@dcrosta dcrosta added the feature:new something does not exist yet, but should label Sep 3, 2021
@gaborbernat gaborbernat added this to the 4.0 milestone Sep 5, 2021
@gaborbernat
Copy link
Member

  1. For getting a list of all tox environments you can use https://github.com/tox-dev/tox/blob/rewrite/src/tox/session/cmd/show_config.py#L61. We need to expose this somehow though on the config argument or something like that.

  2. For the new configuration section: So there's some complexity we need to tackle here: different configu2ration sources. Today this is mostly INI file only. However, going ahead we'll have other files, such as the pyproject.toml. For that file, it's not allowed to reuse the docker namespace directly, but instead, https://www.python.org/dev/peps/pep-0518/#tool-table governs that. To follow that ad litera you'll likely want to add the docker sections under tool.tox-docker.docker-nginx, and tool.tox-docker.docker-db. The system should hideaway this from you somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:plugins-hooks feature:new something does not exist yet, but should
Projects
None yet
Development

No branches or pull requests

2 participants