Add option for default python version
How would this feature be useful?
Remove's the need to specify the python version for every session.
Describe the solution you'd like
Something like:
options.default_pythons = ['3.12']
@session()
def alpha(session: Session):
pass
@session()
def bravo(session: Session):
pass
Would act as if you had ran:
@session(python=['3.12'])
def alpha(session: Session):
pass
@session(python=['3.12'])
def bravo(session: Session):
pass
Describe alternatives you've considered
I currently set the default as a variable and then use that with each decorator call. But it would be cleaner to set it once and not have as many params in the decorator.
Anything else?
Great library/utility, thanks.
I wonder if a .python-version file could be a good way to handle this in general? Several tools have adapted this as a convention and it would be cool if nox also uses this file if it is available.
This is somewhat of an antipattern for nox - I'd say you either should let the user specify the Python version (via force), or you should create a list of versions (and we helpers for that), but not usually lock it to one version for everything. And, if you do have a situation like that, you can easily implement it yourself in a noxfile, with something like:
default_python = Path(".python-version").read_text().strip()
session = functools.partial(nox.sesssion, python=default_python)
For clarity, nothing about this is locked. I didn't state it in the OP, but this would still be possible:
options.default_pythons = ['3.12']
@session()
def alpha(session: Session):
pass
@session()
def bravo(session: Session):
pass
@session(python='3.13')
def charlie(session: Session):
pass
It's just a default. But if this is an anti-pattern, feel free to close, np. Thanks.