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

Add a default=True argument to nox.session #654

Closed
Julian opened this issue Oct 6, 2022 · 6 comments · Fixed by #810
Closed

Add a default=True argument to nox.session #654

Julian opened this issue Oct 6, 2022 · 6 comments · Fixed by #810

Comments

@Julian
Copy link
Contributor

Julian commented Oct 6, 2022

How would this feature be useful?

I'd like to write

@nox.session
def bar():
    pass

@nox.session(default=False)
def foo():
    pass

@nox.session
def baz():
    pass

as a DRYer alternative to:

nox.options.sessions = ["bar", "baz"]

@nox.session
def bar():
    pass

@nox.session
def foo():
    pass

@nox.session
def baz():
    pass

i.e. to be able to specify whether a session is run by default or not when defining it, rather than hardcoding the sessions that should be run.

Has this been considered before perhaps?

Describe the solution you'd like

Programmatically build up nox.options.sessions unless it's defined explicitly via the addition of a parameter (defaulting to True to match the current behavior) which defines whether a session is run by default or not.

Describe alternatives you've considered

Obviously there could be some noodling on what to call the parameter.

Anything else?

No response

@DiddiLeija
Copy link
Collaborator

Sounds good to me! Using a parameter (instead of a variable) could be more human-readable, maybe?

Any thoughts from the maintainers?

@rnickle
Copy link

rnickle commented Feb 11, 2023

It looks like this was brought up before and closed in #232. It was also discussed in #40, which was closed in favor of #141.

The nox.options implementation of nox.options.sessions was the solution adopted.

@Julian
Copy link
Contributor Author

Julian commented Feb 12, 2023

Fair enough, if there isn't a desire to add this obviously feel free to close -- I've basically started copy pasting this into all my noxfiles which I'm happy to keep doing if others don't need this.

@12rambau
Copy link

I would be very interested by this functionality. Just to give you a use case, we manage the translation of our Sphinx theme with Babel. update and compilation is managed by a nox session and a 2nd one is used to add extra languages. we would like to exclude the "init_language" from the default.

@JayBazuzi
Copy link

I would love this for autopep8.

I have a flake8 session that I want to run by default. If I could, I would make an autopep8 session that was skipped by default, and then nox -s autopep8 to fix most reported errors.

(Or black --check / black)

Another use would be a session to run pip freeze > constraints.txt.

@MicaelJarniac
Copy link
Contributor

I'd also really like something like this.

I'm currently experimenting with the following:

import nox
skip = {"foobar"}
# Needs to go at the bottom of `noxfile.py`:
nox.options.sessions = [key for key in nox.registry.get() if key not in skip]

Which isn't perfect, but might do the trick in some cases.

I was also thinking about writing my own custom decorators, like an @skip and/or an @only, to throw above @nox.session, that'd manage including or excluding sessions by default.

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

Successfully merging a pull request may close this issue.

6 participants