Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix conan list for packages with no settings or options #13662

Merged
merged 1 commit into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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