Skip to content

Commit

Permalink
fix conan list for packages with no settings or options
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded committed Apr 10, 2023
1 parent 0a64c9f commit 63ef651
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 4 additions & 4 deletions conans/search/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ def compatible_prop(setting_value, _prop_value):
return (_prop_value == setting_value) or (_prop_value == "None" and setting_value is None)

# TODO: Necessary to generalize this query evaluation to include all possible fields
info_settings = binary_info.get("settings")
info_options = binary_info.get("options")
info_settings = binary_info.get("settings", {})
info_options = binary_info.get("options", {})

if not prop_name.startswith("options."):
return compatible_prop(info_settings.get(prop_name, None), prop_value)
return compatible_prop(info_settings.get(prop_name), prop_value)
else:
prop_name = prop_name[len("options."):]
return compatible_prop(info_options.get(prop_name, None), prop_value)
return compatible_prop(info_options.get(prop_name), prop_value)


def search_recipes(cache, pattern=None, ignorecase=True):
Expand Down
20 changes: 19 additions & 1 deletion conans/test/integration/command_v2/list_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from conans.errors import ConanException, ConanConnectionError
from conans.test.assets.genconanfile import GenConanfile
from conans.test.utils.tools import TestClient, TestServer
from conans.test.utils.tools import TestClient, TestServer, NO_SETTINGS_PACKAGE_ID
from conans.util.env import environment_update
from conans.util.files import load, save

Expand Down Expand Up @@ -615,6 +615,24 @@ def test_list_query_options():
assert "myoption: 3" not in c.out


def test_list_empty_settings():
"""
If settings are empty, do not crash
"""
c = TestClient(default_server_user=True)
c.save({"conanfile.py": GenConanfile("pkg", "1.0")})
c.run("create .")

c.run("list pkg/1.0:* -p os=Windows -f=json")
revisions = json.loads(c.stdout)["Local Cache"]["pkg/1.0"]["revisions"]
pkgs = revisions["a69a86bbd19ae2ef7eedc64ae645c531"]["packages"]
assert pkgs == {}
c.run("list pkg/1.0:* -p os=None -f=json")
revisions = json.loads(c.stdout)["Local Cache"]["pkg/1.0"]["revisions"]
pkgs = revisions["a69a86bbd19ae2ef7eedc64ae645c531"]["packages"]
assert pkgs == {NO_SETTINGS_PACKAGE_ID: {"info": {}}}


class TestListNoUserChannel:
def test_no_user_channel(self):
c = TestClient(default_server_user=True)
Expand Down

0 comments on commit 63ef651

Please sign in to comment.