From c6558094ef63b30a6c816098359345852efa275a Mon Sep 17 00:00:00 2001 From: Carlos Zoido Date: Wed, 13 Dec 2023 16:32:02 +0100 Subject: [PATCH] Add pkglist formatter for conan export command (#15266) add pkglist formatter and test --- conan/cli/commands/export.py | 23 +++++++++++++++---- .../command_v2/test_combined_pkglist_flows.py | 9 ++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/conan/cli/commands/export.py b/conan/cli/commands/export.py index 1d69f4b37c8..c052fe1cd4a 100644 --- a/conan/cli/commands/export.py +++ b/conan/cli/commands/export.py @@ -1,6 +1,7 @@ import json import os +from conan.api.model import MultiPackagesList, PackagesList from conan.api.output import cli_out_write from conan.cli.command import conan_command, OnceArgument from conan.cli.args import add_reference_args @@ -11,11 +12,15 @@ def common_args_export(parser): add_reference_args(parser) -def json_export(ref): - cli_out_write(json.dumps({"reference": ref.repr_notime()})) +def json_export(data): + cli_out_write(json.dumps({"reference": data["reference"].repr_notime()})) -@conan_command(group="Creator", formatters={"json": json_export}) +def pkglist_export(data): + cli_out_write(json.dumps(data["pkglist"], indent=4)) + + +@conan_command(group="Creator", formatters={"json": json_export, "pkglist": pkglist_export}) def export(conan_api, parser, *args): """ Export a recipe to the Conan package cache. @@ -51,4 +56,14 @@ def export(conan_api, parser, *args): lockfile = conan_api.lockfile.update_lockfile_export(lockfile, conanfile, ref, args.build_require) conan_api.lockfile.save_lockfile(lockfile, args.lockfile_out, cwd) - return ref + + exported_list = PackagesList() + exported_list.add_refs([ref]) + + pkglist = MultiPackagesList() + pkglist.add("Local Cache", exported_list) + + return { + "pkglist": pkglist.serialize(), + "reference": ref + } diff --git a/conans/test/integration/command_v2/test_combined_pkglist_flows.py b/conans/test/integration/command_v2/test_combined_pkglist_flows.py index 8bbfbeefe78..f6b1cd28c36 100644 --- a/conans/test/integration/command_v2/test_combined_pkglist_flows.py +++ b/conans/test/integration/command_v2/test_combined_pkglist_flows.py @@ -66,6 +66,15 @@ def test_create_upload(self): assert "Uploading package 'zlib" in c.out +class TestExportUpload: + def test_export_upload(self): + c = TestClient(default_server_user=True) + c.save({"zlib/conanfile.py": GenConanfile("zlib", "1.0")}) + c.run("export zlib --format=pkglist", redirect_stdout="pkglist.json") + c.run("upload --list=pkglist.json -r=default -c") + assert "Uploading recipe 'zlib/1.0#c570d63921c5f2070567da4bf64ff261'" in c.out + + class TestCreateGraphToPkgList: def test_graph_pkg_list_only_built(self): c = TestClient()