You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
nox > Running session tests-3.9
nox > Creating virtual environment (virtualenv) using python3.9 in .nox/tests-3-9
nox > Session tests-3.9 was successful.
nox > Running session tests-3.10
nox > Creating virtual environment (virtualenv) using python3 in .nox/tests-3-10
nox > Session tests-3.10 was successful.
nox > Ran multiple sessions:
nox > * tests-3.9: success
nox > * tests-3.10: success
Expected behavior
The tests session is run on Python 3.9.
The tests session is not run on Python 3.10.
The launch_missiles session is not run at all.
nox > Running session tests-3.9
nox > Creating virtual environment (virtualenv) using python3.9 in .nox/tests-3-9
nox > Session tests-3.9 was successful.
Discussion
Before going into details, I'd like to thank you for creating and maintaining a wonderful tool! 💚
The function OptionSet.merge_namespaces merges options set in noxfile.py into the command-line options. Where applicable, this is done with the help of custom merge functions. The options --sessions, --keywords, and --pythons are handled by a custom merge function _session_filters_merge_func, which ensures that noxfile.py is ignored for all of these options if any of them are set on the command-line.
For example, if noxfile.py contains nox.options.keywords = "not launch_missiles", we want the user to still be able to trigger the session explicitly using --session=launch_missiles; the custom merge function achieves that. Without the custom merge function, the user would be forced to use --keywords instead of --sessions.
Unfortunately, OptionSet.merge_namespaces merges the command-line options in place. Merge functions such as _session_filters_merge_func inspect command_args to see if other options have been specified on the command-line. When the options are merged in place, this check produces false positives.
For example, nox.options.sessions is copied into command_args as a part of the merge; so it will appear to have been specified on the command-line when merging nox.options.pythons, causing the latter to be ignored.
Note that this is unrelated to the new --pythons option. For example, consider the following two nox files:
importnoxnox.options.sessions= ("tests",)
nox.options.keywords="tests or launch_missiles"@nox.sessiondeftests(session):
pass@nox.sessiondeflaunch_missiles(session):
pass
In the first version, sessions excludes launch_missiles, while keywords contains all sessions. When Nox is run without options, it will ignore keywords because sessions was already merged into the command-line options, and appears to have been specified on the command-line. As a result, only the tests session is run.
In the second version, sessions lists all sessions, while keywords excludes launch_missiles. When Nox is run without options, it will again ignore keywords because sessions was already merged into the command-line options. As a result, both tests and launch_missiles are run.
The order of precedence is determined by the declaration of options in nox._options: sessions -- pythons -- keywords.
Proposed solution
As a fix, I would propose that OptionSet.merge_namespaces copy command_args initially, and use that copy as the input for the merge functions, instead of the instance that is being mutated.
The text was updated successfully, but these errors were encountered:
Describe the bug
When both
nox.options.sessions
andnox.options.pythons
are specified innoxfile.py
, the latter setting is ignored.How to reproduce
Run
nox
without options.Actual behavior
Expected behavior
Discussion
Before going into details, I'd like to thank you for creating and maintaining a wonderful tool! 💚
The function
OptionSet.merge_namespaces
merges options set innoxfile.py
into the command-line options. Where applicable, this is done with the help of custom merge functions. The options--sessions
,--keywords
, and--pythons
are handled by a custom merge function_session_filters_merge_func
, which ensures thatnoxfile.py
is ignored for all of these options if any of them are set on the command-line.For example, if
noxfile.py
containsnox.options.keywords = "not launch_missiles"
, we want the user to still be able to trigger the session explicitly using--session=launch_missiles
; the custom merge function achieves that. Without the custom merge function, the user would be forced to use--keywords
instead of--sessions
.Unfortunately,
OptionSet.merge_namespaces
merges the command-line options in place. Merge functions such as_session_filters_merge_func
inspectcommand_args
to see if other options have been specified on the command-line. When the options are merged in place, this check produces false positives.For example,
nox.options.sessions
is copied intocommand_args
as a part of the merge; so it will appear to have been specified on the command-line when mergingnox.options.pythons
, causing the latter to be ignored.Note that this is unrelated to the new
--pythons
option. For example, consider the following two nox files:In the first version,
sessions
excludeslaunch_missiles
, whilekeywords
contains all sessions. When Nox is run without options, it will ignorekeywords
becausesessions
was already merged into the command-line options, and appears to have been specified on the command-line. As a result, only thetests
session is run.In the second version,
sessions
lists all sessions, whilekeywords
excludeslaunch_missiles
. When Nox is run without options, it will again ignorekeywords
becausesessions
was already merged into the command-line options. As a result, bothtests
andlaunch_missiles
are run.The order of precedence is determined by the declaration of options in
nox._options
:sessions
--pythons
--keywords
.Proposed solution
As a fix, I would propose that
OptionSet.merge_namespaces
copycommand_args
initially, and use that copy as the input for the merge functions, instead of the instance that is being mutated.The text was updated successfully, but these errors were encountered: