Skip to content

Commit

Permalink
refactor: simpler impl
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Dec 27, 2021
1 parent 9682fdd commit b880bbf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
23 changes: 7 additions & 16 deletions nox/tasks.py
Expand Up @@ -174,14 +174,19 @@ def filter_manifest(

# Filter by the name of any explicit sessions.
# This can raise KeyError if a specified session does not exist;
# log this if it happens.
if global_config.sessions:
# log this if it happens. The sessions does not come from the noxfile
# if keywords is not empty.
if global_config.sessions is not None:
try:
manifest.filter_by_name(global_config.sessions)
except KeyError as exc:
logger.error("Error while collecting sessions.")
logger.error(exc.args[0])
return 3
if not manifest and not global_config.list_sessions:
print("No sessions selected. Please select a session with -s <session name>.\n")
_produce_listing(manifest, global_config)
return 0

# Filter by python interpreter versions.
if global_config.pythons:
Expand All @@ -208,20 +213,6 @@ def filter_manifest(
logger.error("No sessions selected after filtering by keyword.")
return 3

# If the global_config is set to an empty list, and a list was not
# requested, and no filtering was done,
if (
global_config.sessions is not None
and not global_config.sessions
and not global_config.list_sessions
and not global_config.keywords
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")
_produce_listing(manifest, global_config)
return 0

# Return the modified manifest.
return manifest

Expand Down
10 changes: 5 additions & 5 deletions tests/test_tasks.py
Expand Up @@ -228,7 +228,7 @@ def test_filter_manifest_not_found():

def test_filter_manifest_pythons():
config = _options.options.namespace(
sessions=(), pythons=("3.8",), keywords=(), posargs=[]
sessions=None, pythons=("3.8",), keywords=(), posargs=[]
)
manifest = Manifest(
{"foo": session_func_with_python, "bar": session_func, "baz": session_func},
Expand All @@ -241,7 +241,7 @@ def test_filter_manifest_pythons():

def test_filter_manifest_pythons_not_found(caplog):
config = _options.options.namespace(
sessions=(), pythons=("1.2",), keywords=(), posargs=[]
sessions=None, pythons=("1.2",), keywords=(), posargs=[]
)
manifest = Manifest(
{"foo": session_func_with_python, "bar": session_func, "baz": session_func},
Expand All @@ -254,7 +254,7 @@ def test_filter_manifest_pythons_not_found(caplog):

def test_filter_manifest_keywords():
config = _options.options.namespace(
sessions=(), pythons=(), keywords="foo or bar", posargs=[]
sessions=None, pythons=(), keywords="foo or bar", posargs=[]
)
manifest = Manifest(
{"foo": session_func, "bar": session_func, "baz": session_func}, config
Expand All @@ -266,7 +266,7 @@ def test_filter_manifest_keywords():

def test_filter_manifest_keywords_not_found(caplog):
config = _options.options.namespace(
sessions=(), pythons=(), keywords="mouse or python", posargs=[]
sessions=None, pythons=(), keywords="mouse or python", posargs=[]
)
manifest = Manifest(
{"foo": session_func, "bar": session_func, "baz": session_func}, config
Expand All @@ -278,7 +278,7 @@ def test_filter_manifest_keywords_not_found(caplog):

def test_filter_manifest_keywords_syntax_error():
config = _options.options.namespace(
sessions=(), pythons=(), keywords="foo:bar", posargs=[]
sessions=None, pythons=(), keywords="foo:bar", posargs=[]
)
manifest = Manifest({"foo_bar": session_func, "foo_baz": session_func}, config)
return_value = tasks.filter_manifest(manifest, config)
Expand Down

0 comments on commit b880bbf

Please sign in to comment.