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: support setting an empty session list #523

Merged
merged 9 commits into from
Dec 27, 2021

Conversation

henryiii
Copy link
Collaborator

Closes #465.

Setting an empty session list in the noxfile will default to listing the available sessions.

@henryiii henryiii force-pushed the henryiii/feat/emptylist branch from 32eba77 to 02ede6f Compare December 22, 2021 20:08
@FollowTheProcess
Copy link
Collaborator

@henryiii LGTM, just thinking maybe there should be a quick mention in the tutorial section of the docs? Probably fits best under the Selecting which sessions to run section. Otherwise looks great, thanks!

@cjolowicz
Copy link
Collaborator

See #465 (comment)

@henryiii henryiii force-pushed the henryiii/feat/emptylist branch from 2191d94 to 24c48a0 Compare December 23, 2021 17:08
docs/tutorial.rst Outdated Show resolved Hide resolved
nox/tasks.py Outdated Show resolved Hide resolved
@henryiii henryiii force-pushed the henryiii/feat/emptylist branch 2 times, most recently from 8254716 to 9f5a380 Compare December 23, 2021 22:51
Copy link
Collaborator

@cjolowicz cjolowicz left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this, this is looking great!

Here are a few minor things I noticed. I haven't had time to review the changed control flow yet.

docs/config.rst Outdated Show resolved Hide resolved
docs/tutorial.rst Outdated Show resolved Hide resolved
nox/tasks.py Outdated Show resolved Hide resolved
noxfile.py Outdated Show resolved Hide resolved
@FollowTheProcess
Copy link
Collaborator

Looking good overall! My only (minor) nit is that if you set nox.options.sessions = [] and run bare nox you get the following:

image

However if you run nox -l you get the little selected message on the end:

image

I have two thoughts:

  1. Ideally these two should be consistent with one another
  2. I think all sessions shown when nox.options.sessions = [] should appear as "unselected"

However this could just be my OCD showing so I'm happy to be overruled if we're happy with this as is 🙂

@cjolowicz cjolowicz mentioned this pull request Dec 25, 2021
nox/tasks.py Outdated Show resolved Hide resolved
nox/tasks.py Outdated Show resolved Hide resolved
nox/tasks.py Outdated
Comment on lines 212 to 220
if (
not global_config.keywords
and not global_config.pythons
and not global_config.sessions
and not global_config.list_sessions
and global_config.sessions is not None
):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel the intent could be expressed a little more clearly here. How do you feel about the suggestion below?

I omitted the checks for keywords and pythons because these conditions would have led to bailing out earlier.

Suggested change
if (
not global_config.keywords
and not global_config.pythons
and not global_config.sessions
and not global_config.list_sessions
and global_config.sessions is not None
):
# List sessions if `nox.options.sessions` is an empty sequence.
if (
global_config.sessions is not None
and not global_config.sessions
and not global_config.list_sessions
):

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I redid this, but I kept the keyword/python filtering, since nox -k keyword should select and run the tests with keyword, rather than forcing it to also be passed via -s, I think.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@cjolowicz
Copy link
Collaborator

I agree with @FollowTheProcess that we don't need to special-case the listing for the "no default sessions" case. To be precise, the sessions can be displayed with a minus because they are all deselected, and the explanatory sentence at the end can be kept. (Codewise, this would amount to dropping the ˋselectˋ parameter in ˋproduce_listingˋ.)

@cjolowicz
Copy link
Collaborator

Also I'm confused, why are there asterisks in the screenshot if all sessions are deselected?

@henryiii henryiii force-pushed the henryiii/feat/emptylist branch 2 times, most recently from e2d0424 to 947b352 Compare December 27, 2021 03:01
@cjolowicz
Copy link
Collaborator

cjolowicz commented Dec 27, 2021

I realize now that you don't filter sessions by name when nox.options.sessions is an empty list. This also explains why nox --list displays all sessions as selected (with an asterisk) even though they're not.

Can we change the condition for this filter to check for None instead of falsiness?

You will need to check for a non-empty manifest after filtering by session name, like for the other filters. If the check fails, you can invoke produce_listing. This would replace the block at the end of the function.

I believe there are three good reasons for this change:

  1. It would make the control flow easier to understand.
  2. It's important that nox --list can be used to debug session selection.
  3. Filtering by Python should not cause sessions to become selected. Currently, your PR changes this behavior (when the session list is empty).

As for selecting sessions by keyword even when nox.options.sessions is an empty list: This already works. The nox.options.sessions setting is ignored when -k is passed, see the function _sessions_and_keywords_merge_func in the _options module.

What do you think?

Update: My suggestion breaks some tests in test_tasks.py that initialize sessions to an empty tuple. The failing tests need to be updated by initializing sessions to None instead (which is the correct default value anyway).

nox/tasks.py Outdated
and not global_config.pythons
):
manifest.filter_by_name(global_config.sessions)
print("No sessions selected. Please select a session with -s <session name>.\n")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we use the logger here? It would make the message stand out from the session listing.

Suggested change
print("No sessions selected. Please select a session with -s <session name>.\n")
logger.warning(
"No sessions selected. Please select a session with -s <session name>.\n"
)

We'd need to adapt the new tests to use caplog.text instead of capsys.readouterr().out.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is it an error / warning though? The session listing is a print.

@henryiii
Copy link
Collaborator Author

As for selecting sessions by keyword even when nox.options.sessions is an empty list: This already works.

Ah, this was the piece I didn't know. I wanted to put the check here, but didn't realize it would not cause an issue with filtering. It's at all not obvious that this will be ignored from the logic in this function! Seems like it should have it in the if statement.

@henryiii henryiii force-pushed the henryiii/feat/emptylist branch from 947b352 to b880bbf Compare December 27, 2021 15:14
@henryiii
Copy link
Collaborator Author

(Haven't tested the recent comment by hand with the noxfile yet)

noxfile.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@cjolowicz cjolowicz left a comment

Choose a reason for hiding this comment

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

Thanks so much @henryiii for all the work that went into this

@cjolowicz cjolowicz merged commit f5be2cc into wntrblm:main Dec 27, 2021
@henryiii henryiii deleted the henryiii/feat/emptylist branch December 28, 2021 03:09
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.

sessions: empty list of default sessions could print help
4 participants