diff --git a/conan/cli/commands/list.py b/conan/cli/commands/list.py index 68eece68b08..1fd4a88113d 100644 --- a/conan/cli/commands/list.py +++ b/conan/cli/commands/list.py @@ -256,12 +256,12 @@ def list(conan_api: ConanAPI, parser, *args): "a 'pkgname/version:*' pattern is necessary") # If neither remote nor cache are defined, show results only from cache pkglist = MultiPackagesList() + profile = conan_api.profiles.get_profile(args.filter_profile or [], + args.filter_settings, + args.filter_options) \ + if args.filter_profile or args.filter_settings or args.filter_options else None if args.cache or not args.remote: try: - profile = conan_api.profiles.get_profile(args.filter_profile or [], - args.filter_settings, - args.filter_options) \ - if args.filter_profile or args.filter_settings or args.filter_options else None cache_list = conan_api.list.select(ref_pattern, args.package_query, remote=None, lru=args.lru, profile=profile) except Exception as e: @@ -272,7 +272,8 @@ def list(conan_api: ConanAPI, parser, *args): remotes = conan_api.remotes.list(args.remote) for remote in remotes: try: - remote_list = conan_api.list.select(ref_pattern, args.package_query, remote) + remote_list = conan_api.list.select(ref_pattern, args.package_query, remote, + profile=profile) except Exception as e: pkglist.add_error(remote.name, str(e)) else: diff --git a/conans/test/integration/command_v2/list_test.py b/conans/test/integration/command_v2/list_test.py index c0824d02f09..98a662b0e46 100644 --- a/conans/test/integration/command_v2/list_test.py +++ b/conans/test/integration/command_v2/list_test.py @@ -799,8 +799,11 @@ def test_list_compact_no_settings_no_options(self): class TestListBinaryFilter: - def test_list_filter(self): - c = TestClient() + + @pytest.mark.parametrize("remote", [True, False]) + def test_list_filter(self, remote): + r = "-r=default" if remote else "" + c = TestClient(default_server_user=remote) c.save({"pkg/conanfile.py": GenConanfile("pkg", "1.0").with_settings("os", "arch") .with_shared_option(False), "header/conanfile.py": GenConanfile("header", "1.0"), @@ -811,49 +814,52 @@ def test_list_filter(self): c.run("create pkg -s os=Linux -s arch=armv8") c.run("create pkg -s os=Macos -s arch=armv8 -o shared=True") c.run("create header") + if remote: + c.run("upload *:* -r=default -c") + pkg_key = "default" if remote else "Local Cache" - c.run("list *:* -fp=profile_linux --format=json") + c.run(f"list *:* -fp=profile_linux --format=json {r}") result = json.loads(c.stdout) - header = result["Local Cache"]["header/1.0"]["revisions"]["747cc49983b14bdd00df50a0671bd8b3"] + header = result[pkg_key]["header/1.0"]["revisions"]["747cc49983b14bdd00df50a0671bd8b3"] assert header["packages"] == {"da39a3ee5e6b4b0d3255bfef95601890afd80709": {"info": {}}} - pkg = result["Local Cache"]["pkg/1.0"]["revisions"]["03591c8b22497dd74214e08b3bf2a56f"] + pkg = result[pkg_key]["pkg/1.0"]["revisions"]["03591c8b22497dd74214e08b3bf2a56f"] assert len(pkg["packages"]) == 1 settings = pkg["packages"]["2d46abc802bbffdf2af11591e3e452bc6149ea2b"]["info"]["settings"] assert settings == {"arch": "armv8", "os": "Linux"} # for linux + x86 only the header-only is a match - c.run("list *:* -fp=profile_linux -fs=arch=x86 --format=json") + c.run(f"list *:* -fp=profile_linux -fs=arch=x86 --format=json {r}") result = json.loads(c.stdout) - header = result["Local Cache"]["header/1.0"]["revisions"]["747cc49983b14bdd00df50a0671bd8b3"] + header = result[pkg_key]["header/1.0"]["revisions"]["747cc49983b14bdd00df50a0671bd8b3"] assert header["packages"] == {"da39a3ee5e6b4b0d3255bfef95601890afd80709": {"info": {}}} - pkg = result["Local Cache"]["pkg/1.0"]["revisions"]["03591c8b22497dd74214e08b3bf2a56f"] + pkg = result[pkg_key]["pkg/1.0"]["revisions"]["03591c8b22497dd74214e08b3bf2a56f"] assert pkg["packages"] == {} - c.run("list *:* -fp=profile_armv8 --format=json") + c.run(f"list *:* -fp=profile_armv8 --format=json {r}") result = json.loads(c.stdout) - header = result["Local Cache"]["header/1.0"]["revisions"]["747cc49983b14bdd00df50a0671bd8b3"] + header = result[pkg_key]["header/1.0"]["revisions"]["747cc49983b14bdd00df50a0671bd8b3"] assert header["packages"] == {"da39a3ee5e6b4b0d3255bfef95601890afd80709": {"info": {}}} - pkg = result["Local Cache"]["pkg/1.0"]["revisions"]["03591c8b22497dd74214e08b3bf2a56f"] + pkg = result[pkg_key]["pkg/1.0"]["revisions"]["03591c8b22497dd74214e08b3bf2a56f"] assert len(pkg["packages"]) == 2 settings = pkg["packages"]["2d46abc802bbffdf2af11591e3e452bc6149ea2b"]["info"]["settings"] assert settings == {"arch": "armv8", "os": "Linux"} settings = pkg["packages"]["2a67a51fbf36a4ee345b2125dd2642be60ffd3ec"]["info"]["settings"] assert settings == {"arch": "armv8", "os": "Macos"} - c.run("list *:* -fp=profile_shared --format=json") + c.run(f"list *:* -fp=profile_shared --format=json {r}") result = json.loads(c.stdout) - header = result["Local Cache"]["header/1.0"]["revisions"]["747cc49983b14bdd00df50a0671bd8b3"] + header = result[pkg_key]["header/1.0"]["revisions"]["747cc49983b14bdd00df50a0671bd8b3"] assert header["packages"] == {"da39a3ee5e6b4b0d3255bfef95601890afd80709": {"info": {}}} - pkg = result["Local Cache"]["pkg/1.0"]["revisions"]["03591c8b22497dd74214e08b3bf2a56f"] + pkg = result[pkg_key]["pkg/1.0"]["revisions"]["03591c8b22497dd74214e08b3bf2a56f"] assert len(pkg["packages"]) == 1 settings = pkg["packages"]["2a67a51fbf36a4ee345b2125dd2642be60ffd3ec"]["info"]["settings"] assert settings == {"arch": "armv8", "os": "Macos"} - c.run("list *:* -fs os=Windows -fo *:shared=False --format=json") + c.run(f"list *:* -fs os=Windows -fo *:shared=False --format=json {r}") result = json.loads(c.stdout) - header = result["Local Cache"]["header/1.0"]["revisions"]["747cc49983b14bdd00df50a0671bd8b3"] + header = result[pkg_key]["header/1.0"]["revisions"]["747cc49983b14bdd00df50a0671bd8b3"] assert header["packages"] == {"da39a3ee5e6b4b0d3255bfef95601890afd80709": {"info": {}}} - pkg = result["Local Cache"]["pkg/1.0"]["revisions"]["03591c8b22497dd74214e08b3bf2a56f"] + pkg = result[pkg_key]["pkg/1.0"]["revisions"]["03591c8b22497dd74214e08b3bf2a56f"] assert len(pkg["packages"]) == 1 settings = pkg["packages"]["d2e97769569ac0a583d72c10a37d5ca26de7c9fa"]["info"]["settings"] assert settings == {"arch": "x86", "os": "Windows"}