Skip to content

FEAT: json session listing #658

@henryiii

Description

@henryiii

How would this feature be useful?

GitHub actions (and maybe others) let you configure the jobs dynamically using JSON. This was used very effectively by cibuildwheel (see https://iscinumpy.dev/post/cibuildwheel-2-10-0/#only-210). I was thinking this might be really nice for nox, too. Then the session list would be the source of truth for the CI Python jobs.

Describe the solution you'd like

A new flag, like --json-sessions, could be added to augment the -l list sessions command. It doesn't have to be json, but that's likely the easiest to process if there were multiple items in the output (and you could include handy items like the help text, and add to it later without breaking usage). Something like this:

$ nox --json-sessions
{"name": "tests-3.7", "help": "Run test suite with pytest."}
{"name": "tests-3.8", "help": "Run test suite with pytest."}
...

It should be possible to combine --json-sessions with -s session selections, just like it is with -l today, which would make it easy to produce just the correct subset.

Describe alternatives you've considered

The current output could be parsed, but it's not very amenable to parsing, and more info (like the base session name & the python interpreter) would be nice to have. It doesn't have to be json, but it should be easily machine readable (which json is). And technically I used json lines above, though regular json is fine too - either is easy to run through jq. It also should be only the active values (or have a bool for selected on/off).

Anything else?

Here's with another option (python) added:

$ nox --json-sessions
{"name": "tests-3.7", "python": "3.7", "help": "Run test suite with pytest."}
{"name": "tests-3.8", "python": "3.7",  "help": "Run test suite with pytest."}
...
{"name": "lint", "python": "3.x",  "help": "Run pre-commit linting."}
...

Then you could easily have enough for python-version.

I've not carefully worked this through, but thought I'd put it down to see what people thought.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions