Skip to content

Commit

Permalink
Do not merge command-line options in place (#357)
Browse files Browse the repository at this point in the history
When merging options specified in the noxfile and on the command-line option, do
not use the output parameter `command_args` as the input for the merge; instead,
copy `command_args` initially and pass the copy to the merge functions.

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.

Co-authored-by: Claudio Jolowicz <cjolowicz@localhost.localdomain>
  • Loading branch information
cjolowicz and Claudio Jolowicz committed Nov 13, 2020
1 parent 9caaba5 commit e78d8d9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions nox/_option_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,16 @@ def merge_namespaces(
self, command_args: Namespace, noxfile_args: Namespace
) -> None:
"""Merges the command-line options with the noxfile options."""
command_args_copy = Namespace(**vars(command_args))
for name, option in self.options.items():
if option.merge_func:
setattr(
command_args, name, option.merge_func(command_args, noxfile_args)
command_args,
name,
option.merge_func(command_args_copy, noxfile_args),
)
elif option.noxfile:
value = getattr(command_args, name, None) or getattr(
value = getattr(command_args_copy, name, None) or getattr(
noxfile_args, name, None
)
setattr(command_args, name, value)

0 comments on commit e78d8d9

Please sign in to comment.