Tox: unclear argument description

Created on 8 Apr 2021  路  6Comments  路  Source: tox-dev/tox

This parser argument ...

https://github.com/tox-dev/tox/blob/3edd7dc4e902cc99e921cb60193226e5ead52079/src/tox/session/state.py#L109-L119

gets rendered as ...

Screenshot from 2021-04-08 15-34-34

What does "default execute" mean?

Maybe change the help text to "specify runner"?

normal

All 6 comments

The interesting part: Why is default empty, and not virtualenv like on my cli?

I guess this relates to REGISTER.default_run_env only gets set during runtime of tox and not right from the beginning.

I think there is not much we can do? cc @gaborbernat

The parser is setup for the doc generation here https://github.com/tox-dev/tox/blob/rewrite/docs/cli_interface.rst, so we could inject here https://github.com/tox-dev/tox/blob/rewrite/src/tox/config/cli/parse.py#L62 customization to set any values we might want.

Ok, so I had a deep dive into argparse...

Looks like the optional arguments are stored in parser._optionals._actions.

As _actions is a list, I cannot access the runner argument directly, but I would need to iterate over the list like...

for action in tox_parser._optionals._actions:
    if action.dest == "default_runner":
        action.default="virtualenv"
        break

And then create a function like parser_for_doc_generation? Which I would reference from cli_interface.rst?

So it would look like:

.. sphinx_argparse_cli::
  :module: tox.config.cli.parse
  :func: parser_for_doc_generation

and

def parser_for_doc_generation() -> ToxParser:
    parser = _get_parser()
    for action in parser._optionals._actions:
        if action.dest == "default_runner":
            action.default="virtualenv"
            break
    return parser

But possibly there is a better way... @gaborbernat

Rather than patch post creation can't we just make sure it loads the right value during creation?

Rather than patch post creation can't we just make sure it loads the right value during creation?

I do use argparse occasionally, but I am not familiar at a deeper level.

When I look at ToxParsers init, it either gets all commands or none (add_cmd).
https://github.com/tox-dev/tox/blob/3addb35bfd56ad077aaf6526d9d479940be4a31c/src/tox/config/cli/parser.py#L122-L136

When we do not use add_subparsers, we would need to add all commands manually? I think that is not what we want.

I also saw a fix_default(s) method - I am not sure whether that would be better, and that's patching, too. So... :shrug: :-)
https://github.com/tox-dev/tox/blob/3addb35bfd56ad077aaf6526d9d479940be4a31c/src/tox/config/cli/parser.py#L41-L55

I'll take a look at why this is not set 馃憤馃徎 and get back to you at a later point in the week.

Was this page helpful?
0 / 5 - 0 ratings