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

New conan graph explain command to search, compare and explain missing binaries #14694

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
22 changes: 19 additions & 3 deletions conan/api/subapi/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,23 @@ def filter_packages_configurations(pkg_configurations, query):
"""
return filter_packages(query, pkg_configurations)

def select(self, pattern, package_query=None, remote=None):
if package_query and pattern.package_id and "*" not in pattern.package_id:
raise ConanException("Cannot specify '-p' package queries, "
@staticmethod
def filter_packages_profile(pkg_configurations, profile):
profile_settings = profile.settings

def _matches(d): # Only implements settings matching at this moment
settings = d.get("settings", {})
for k, v in settings.items():
profile_value = profile_settings.get(k)
if profile_value is not None and profile_value != v:
return False
return True

return {pref: data for pref, data in pkg_configurations.items() if _matches(data)}
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved

def select(self, pattern, package_query=None, profile=None, remote=None):
if (package_query or profile) and pattern.package_id and "*" not in pattern.package_id:
raise ConanException("Cannot specify '-p' package queries or profile, "
"if 'package_id' is not a pattern")
select_bundle = PackagesList()
# Avoid doing a ``search`` of recipes if it is an exact ref and it will be used later
Expand Down Expand Up @@ -128,6 +142,8 @@ def select(self, pattern, package_query=None, remote=None):
packages = self.packages_configurations(rrev, remote)
if package_query is not None:
packages = self.filter_packages_configurations(packages, package_query)
if profile is not None:
packages = self.filter_packages_profile(packages, profile)
prefs = packages.keys()
prefs = pattern.filter_prefs(prefs)
packages = {pref: conf for pref, conf in packages.items() if pref in prefs}
Expand Down
2 changes: 1 addition & 1 deletion conan/cli/commands/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def download(conan_api: ConanAPI, parser, *args):
raise ConanException(f"The current package list does not contain remote '{remote.name}'")
else:
ref_pattern = ListPattern(args.pattern, package_id="*", only_recipe=args.only_recipe)
package_list = conan_api.list.select(ref_pattern, args.package_query, remote)
package_list = conan_api.list.select(ref_pattern, args.package_query, remote=remote)

parallel = conan_api.config.get("core.download:parallel", default=1, check_type=int)

Expand Down
11 changes: 9 additions & 2 deletions conan/cli/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def list(conan_api: ConanAPI, parser, *args):
parser.add_argument('-p', '--package-query', default=None, action=OnceArgument,
help="List only the packages matching a specific query, e.g, os=Windows AND "
"(arch=x86 OR compiler=gcc)")
parser.add_argument('-pr', '--profile', default=None, action="append",
help="Profiles to filter the package binaries")
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved
parser.add_argument("-r", "--remote", default=None, action="append",
help="Remote names. Accepts wildcards ('*' means all the remotes available)")
parser.add_argument("-c", "--cache", action='store_true', help="Search in the local cache")
Expand All @@ -117,6 +119,8 @@ def list(conan_api: ConanAPI, parser, *args):
raise ConanException("Cannot define both the pattern and the graph json file")
if (args.graph_recipes or args.graph_binaries) and not args.graph:
raise ConanException("--graph-recipes and --graph-binaries require a --graph input")
if args.package_query and args.profile:
raise ConanException("--package-query and --profile are mutually exclusive")

if args.graph:
graphfile = make_abs_path(args.graph)
Expand All @@ -125,9 +129,11 @@ def list(conan_api: ConanAPI, parser, *args):
ref_pattern = ListPattern(args.pattern, rrev=None, prev=None)
# If neither remote nor cache are defined, show results only from cache
pkglist = MultiPackagesList()
profile = conan_api.profiles.get_profile(args.profile) if args.profile else None
if args.cache or not args.remote:
try:
cache_list = conan_api.list.select(ref_pattern, args.package_query, remote=None)
cache_list = conan_api.list.select(ref_pattern, args.package_query, profile,
remote=None)
except Exception as e:
pkglist.add_error("Local Cache", str(e))
else:
Expand All @@ -136,7 +142,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,
profile, remote)
except Exception as e:
pkglist.add_error(remote.name, str(e))
else:
Expand Down
2 changes: 1 addition & 1 deletion conan/cli/commands/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def confirmation(message):
ref_pattern = ListPattern(args.pattern, rrev="*", prev="*")
if ref_pattern.package_id is None and args.package_query is not None:
raise ConanException('--package-query supplied but the pattern does not match packages')
package_list = conan_api.list.select(ref_pattern, args.package_query, remote)
package_list = conan_api.list.select(ref_pattern, args.package_query, remote=remote)
multi_package_list = MultiPackagesList()
multi_package_list.add(cache_name, package_list)

Expand Down
28 changes: 28 additions & 0 deletions conans/test/integration/command_v2/list_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,34 @@ def test_list_empty_settings():
assert pkgs == {NO_SETTINGS_PACKAGE_ID: {"info": {}}}


def test_list_package_filter_profile():
c = TestClient(default_server_user=True)
c.save({"pkg/conanfile.py": GenConanfile("pkg", "1.0"),
"other/conanfile.py": GenConanfile("other", "1.0").with_settings("os"),
"windows": "[settings]\nos=Windows",
"linux": "[settings]\nos=Linux"})
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved
c.run("create pkg")
c.run("create other -s os=Linux")

c.run("list *:* -pr windows --format=json")
cache = json.loads(c.stdout)["Local Cache"]
revisions = cache["pkg/1.0"]["revisions"]
pkgs = revisions["a69a86bbd19ae2ef7eedc64ae645c531"]["packages"]
assert "da39a3ee5e6b4b0d3255bfef95601890afd80709" in pkgs
revisions = cache["other/1.0"]["revisions"]
pkgs = revisions["de88e3cc9893934e52db4bca09605c0e"]["packages"]
assert pkgs == {}

c.run("list *:* -pr linux --format=json")
cache = json.loads(c.stdout)["Local Cache"]
revisions = cache["pkg/1.0"]["revisions"]
pkgs = revisions["a69a86bbd19ae2ef7eedc64ae645c531"]["packages"]
assert "da39a3ee5e6b4b0d3255bfef95601890afd80709" in pkgs
revisions = cache["other/1.0"]["revisions"]
pkgs = revisions["de88e3cc9893934e52db4bca09605c0e"]["packages"]
assert "9a4eb3c8701508aa9458b1a73d0633783ecc2270" in pkgs


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