Tox: Provide autocompletions for tox environments

Created on 17 Sep 2016  路  18Comments  路  Source: tox-dev/tox

To Do:

  • tox -e could autocomplete with the sections marked in tox.ini ( + all)
new medium

All 18 comments

@AvdN I just talked to a colleague today that it would be nice to have. I might build something for zsh ...

Although this would be nice, it is actually nothing that could be implemented in tox itself, as this is something that needs work from the shell (e.g. autocompletion functions for zsh or bash) - so I am closing this for now. But please let us know, if anyone came up with tox completions for any of the shells :)

This is actually something that can most easily be implemented in tox itself, assuming (which was true at the time of writing) that you are using argcomplete. tox already parses the .ini file.

But argcomplete is pretty slow, as the bash script has to invoke the python interpreter etc. IIRC the slowness was the cause for Holger to drop this.

Hi @AvdN - interesting project, but it does not cover what would be needed in tox.

Argcomplete provides easy, extensible command line tab completion of arguments for your Python script.
It makes two assumptions:
You鈥檙e using bash as your shell (limited support for zsh and tcsh is available)

As we are very conservative about pulling dependencies and support a wider range of OSSES and interpreters, I would say this is too much of a maintenance burden to implement it insode of tox.

To see what environements are defined (including generated envs and descriptions (since 2.7)) you can say tox -av and would get:

default environments:
py27      -> run the unit tests with pytest under the current Python env
py26      -> run the unit tests with pytest under the current Python env
py34      -> run the unit tests with pytest under the current Python env
py33      -> run the unit tests with pytest under the current Python env
py35      -> run the unit tests with pytest under the current Python env
py36      -> run the unit tests with pytest under the current Python env
pypy      -> run the unit tests with pytest under the current Python env
flakes    -> run static analysis and style check using flakes and pep-8
py26-bare -> invoke the tox help message under Python 2.6

additional environments:
X         -> print the positional arguments passed in with echo
dev       -> DEV enviroment, if no posarg is specified: run pytest
docs      -> invoke sphinx-build and try to build the HTML page (also check link validity)

for the current tox.ini.

In extension: using tox -a provides a machine parsable list that would make it easy to provide environment completions (I actually think that would be very easy for zsh).

although this is related more closely to the shell, I think we should provide a MVP of this inside our user documentation; which the users can reuse :+1: we're the most likely people to complete these at the end of the day

or ... if somebody does this, we can add the project to the org and reference it.

Yeah, I picture this most likely being a gist; one for zsh and one for bash should be enough to mark it solved. And then just link it on the documentation page.

or maybe have it under the contrib, as git does; so packaging systems can just link to it (see e.g. https://github.com/git/git/blob/master/contrib/completion/git-completion.bash)

I like that contrib idea best.

here's one that makes the tox -e work via bash-completion; without any error checks for now as a POC; will follow up on this with a PR

#/etc/bash_completion.d/tox
_tox() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    case "${prev}" in
        -e)
            local running=`tox -a`
            COMPREPLY=( $(compgen -W "${running}" -- ${cur}) )
            return 0
            ;;
        *)
        ;;
    esac

   COMPREPLY=($(compgen -W "${opts}" -- ${cur}))  
   return 0
}
complete -F _tox tox

Thinking about it ... how hard is it to get this kind of stuff into the prepacked completions of e.g. bash and zsh? I mean it would be great if this could work out of the box ... maybe try also open that PR against https://github.com/scop/bash-completion 馃

Wow. You are super fast! 馃憤

bash is merged 馃憤 the zshell seems to require some more documentation as I would want to avoid listing explicitly most options and instead reuse the _gnu_generic parser; which most other tools do in that repo.

Nice! zsh completions are tricky - so much I know.

Split out into https://github.com/tox-dev/tox/issues/916 and https://github.com/tox-dev/tox/issues/917. Because mostly their separate actionable items. Bash support is done but will need to document it via https://github.com/tox-dev/tox/issues/918.

Was this page helpful?
0 / 5 - 0 ratings