def repoquery(args, parser): if not args.subcmd: print("repoquery needs a subcommand (search, depends or whoneeds)") print("eg:") print(" $ mamba repoquery search xtensor\n") exit(1) # print(args) if args.platform: platform = args.platform else: platform = context.subdir channels = None if hasattr(args, "channel"): channels = args.channel if args.all_channels or (channels is None and args.subcmd == "search"): if channels: print("WARNING: Using all channels instead of configured channels") channels = context.channels use_installed = args.installed if args.no_installed: use_installed = False # if we're asking for depends and channels are given, disregard # installed packages to prevent weird mixing if args.subcmd in ("depends", "whoneeds") and use_installed and channels: use_installed = False only_installed = True if args.subcmd == "search" and not args.installed: only_installed = False elif args.all_channels or (channels and len(channels)): only_installed = False if only_installed and args.no_installed: print("No channels selected.") print("Activate -a to search all channels.") exit(1) if not context.json: print("\nExecuting the query %s\n" % args.package_query) if context.json: fmt = api.QueryFormat.JSON elif hasattr(args, "tree") and args.tree: fmt = api.QueryFormat.TREE elif hasattr(args, "pretty") and args.pretty: fmt = api.QueryFormat.PRETTY else: fmt = api.QueryFormat.TABLE pool = repoquery_api.create_pool(channels, platform, use_installed) print("\n") print(repoquery_api._repoquery(args.subcmd, args.package_query, pool, fmt))
def test_depends(): pool = repoquery.create_pool(["conda-forge"], "linux-64", False) res = repoquery.depends("xtensor", pool) assert res["query"]["query"] == "xtensor" assert res["query"]["type"] == "depends" assert res["result"]["graph_roots"][0]["name"] == "xtensor" assert int(res["result"]["graph_roots"][0]["version"].split(".")[1]) >= 21 pkgs = res["result"]["pkgs"] assert any(x["name"] == "libstdcxx-ng" for x in pkgs) assert pkgs[0]["subdir"] == "linux-64"
def test_whoneeds(): pool = repoquery.create_pool(["conda-forge"], "osx-64", False) res = repoquery.whoneeds("xtensor", pool) assert res["query"]["query"] == "xtensor" assert res["query"]["type"] == "whoneeds" assert res["result"]["graph_roots"] == ["xtensor"] pkgs = res["result"]["pkgs"] assert any(x["name"] == "xtensor-blas" for x in pkgs) assert pkgs[0]["subdir"] == "osx-64"
def test_search(): pool = repoquery.create_pool(["conda-forge"], "win-64", False) res = repoquery.search("xtensor*", pool) assert res["query"]["query"] == "xtensor*" assert res["query"]["type"] == "search" pkgs = res["result"]["pkgs"] assert any(x["name"] == "xtensor-blas" for x in pkgs) assert any(x["name"] == "xtensor" for x in pkgs) assert any(x["name"] == "xtensor-io" for x in pkgs) assert pkgs[0]["subdir"] == "win-64" res2 = repoquery.search("xtensor >=0.21", pool) assert all( int(x["version"].split(".")[1]) >= 21 for x in res2["result"]["pkgs"])