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

feat: --json --list-sessions #665

Merged
merged 2 commits into from
Mar 5, 2023

Conversation

henryiii
Copy link
Collaborator

Closes #658.

No tests yet. Putting out an initial design.

Here's the output on nox itself:

nox --json -l -s cover lint | jq
[
  {
    "session": "cover",
    "name": "cover",
    "description": "Coverage analysis.",
    "python": null,
    "tags": [],
    "call_spec": {}
  },
  {
    "session": "lint",
    "name": "lint",
    "description": "Run pre-commit linting.",
    "python": "3.9",
    "tags": [],
    "call_spec": {}
  }
]

And it can be processed by jq:

$ nox --json -l -s tests | jq '.[].session'
"tests-3.7"
"tests-3.8"
"tests-3.9"
"tests-3.10"
"tests-3.11"

Thoughts?

@henryiii
Copy link
Collaborator Author

Any thoughts on the general design?

@FollowTheProcess
Copy link
Collaborator

Hey @henryiii sorry this one slipped by me! I like it and was actually surprised at how little needed to change to support this. For those wondering how it ends up looking:

image

Just a couple of questions more than anything.

When sessions don't have a python the output from this is null e.g. from our own docs session:

image

I wonder if there's something more helpful we can put here? This seems to be when we use the nox.session decorator without calling it so Nox uses the python that called it to do the virtualenv, could we populate the JSON python version with the version from sys.version_info? A quick POC on my local copy of your branch seems to work okay:

report.append(
      {
          "python": session.func.python or f"{sys.version_info.major}.{sys.version_info.minor}",
      }
  )

Finally a very minor one but I'm not sure of the usefulness of the name call_spec to anyone other than nox developers. I think a more user friendly term here would be good, something that makes it clearer this is to do with parametrize?

Other than that though this looks great!

@henryiii
Copy link
Collaborator Author

henryiii commented Oct 31, 2022

Null output

This can be used to detect when the Python version doesn't matter. I'd assume a user would want to fill nulls with 3.x on GitHub Actions, and possibly something else on other platforms. (I thought about injecting 3.x, but that could be a bit GHA specific, whereas I'd want this to be general? You can always replaced a known, unique string, though, so this wouldn't be too bad.)

I wouldn't want to inject the actual running Python because you lose the info that it doesn't matter, and you might not be running the listing on the same Python as you run the check later - that shouldn't matter.

call_spec

I wasn't sure what to call it and being consistent seemed the simplest thing. ¯\_(ツ)_/¯

@FollowTheProcess
Copy link
Collaborator

Ahh yeah good point re. "python doesn't matter"

I wasn't sure what to call it and being consistent seemed the simplest thing

That's fair, naming is hard after all! None of this was a blocker for me, this looks great 👍🏻

@henryiii
Copy link
Collaborator Author

henryiii commented Oct 31, 2022

That doesn't mean it has to be named "call_spec", I just was explaining where the name came from. :) If you want to suggest something, go ahead.

@FollowTheProcess
Copy link
Collaborator

Well I'm in a similar boat to be honest, I can't really think of a good name either 👀

@FollowTheProcess
Copy link
Collaborator

When dumping the JSON is it worth prettying it with indent or something do you think? Obviously computers don't care but it makes it a bit more human readable without using e.g. jq?

@henryiii
Copy link
Collaborator Author

henryiii commented Nov 1, 2022

is it worth prettying it with indent

I considered it, in fact I did do that at first, but dropped it when it's so easy to do it with jq, and the point of the output is to be processed, not to be human readable. But this is not something where saving a few whitespace characters matters, so indent is fine too.

My next plan is to try this on a repo somewhere, to see what processing this looks like. I've fixed my blog post's example something like 3-4 times because I missed things. That will probably make good documentation, too. :)

@FollowTheProcess
Copy link
Collaborator

FollowTheProcess commented Nov 1, 2022

Yeah agreed, I think it's fine to leave it out. Even if people pipe it to files as soon as they open them in e.g. VSCode it'll probably format it nicely anyway.

That will probably make good documentation, too. :)

This would be great! If you can find some useful tricks it might be worth making a new recipe in the Cookbook

I'd be interested to see how people might use this actually, it feels like it could be quite powerful in e.g. CI systems but I can't quite think of a use case in anything I'm doing at the moment

@FollowTheProcess
Copy link
Collaborator

Where did you get to on this @henryiii? With some tests this should be ready to go as far as I can tell?, would be great to get this in for the next release :)

@henryiii
Copy link
Collaborator Author

henryiii commented Mar 3, 2023

Finally tried this out: scikit-build/scikit-build-sample-projects#31 :)

@henryiii henryiii force-pushed the henryiii/feat/json branch from 73316fb to f79ce9c Compare March 3, 2023 23:26
Signed-off-by: Henry Schreiner <[email protected]>
@henryiii henryiii force-pushed the henryiii/feat/json branch from ebad9ec to 3d1809c Compare March 4, 2023 03:56
@henryiii
Copy link
Collaborator Author

henryiii commented Mar 4, 2023

Okay, unless someone wants something like --format=json instead of --json, this is ready. Probably needs a cookbook example or two eventually.

@henryiii henryiii marked this pull request as ready for review March 4, 2023 04:00
Copy link
Collaborator

@FollowTheProcess FollowTheProcess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thanks @henryiii

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

FEAT: json session listing
2 participants