Skip to content

Commit

Permalink
Add pkglist formatter for conan export command (#15266)
Browse files Browse the repository at this point in the history
add pkglist formatter and test
  • Loading branch information
czoido authored Dec 13, 2023
1 parent d0e6a3f commit c655809
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
23 changes: 19 additions & 4 deletions conan/cli/commands/export.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c655809

Please sign in to comment.