From 781579d8136969e66faf0e1a56570b3feb7e323b Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Sat, 8 Jul 2023 13:31:01 -0700 Subject: [PATCH 1/5] Add test for upload --list on an empty list --- .../command_v2/test_combined_pkglist_flows.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 36d3798b48e..5513d75efe3 100644 --- a/conans/test/integration/command_v2/test_combined_pkglist_flows.py +++ b/conans/test/integration/command_v2/test_combined_pkglist_flows.py @@ -37,6 +37,18 @@ def test_list_upload_packages(self, client): assert f"Uploading recipe '{r}'" in client.out assert str(client.out).count("Uploading package") == 2 + def test_list_upload_empty_list(self, client): + client.run(f"install --requires=zlib/1.0.0@user/channel -f json", + redirect_stdout="install_graph.json") + + # Generate an empty pkglist.json + client.run(f"list --format=json --graph=install_graph.json --graph-binaries=bogus", + redirect_stdout="pkglist.json") + + # No binaries should be uploaded since the pkglist is empty, but the command + # should not error + client.run("upload --list=pkglist.json -r=default") + class TestGraphCreatedUpload: def test_create_upload(self): From 313c9a32b4a1b1209db3134d004870d6c9dfe785 Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Sat, 8 Jul 2023 13:37:51 -0700 Subject: [PATCH 2/5] Allow empty recipes when using upload --list --- conan/cli/commands/upload.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/conan/cli/commands/upload.py b/conan/cli/commands/upload.py index 2795b9fb087..3e92fd8cb39 100644 --- a/conan/cli/commands/upload.py +++ b/conan/cli/commands/upload.py @@ -81,24 +81,25 @@ def upload(conan_api: ConanAPI, parser, *args): ref_pattern = ListPattern(args.pattern, package_id="*", only_recipe=args.only_recipe) package_list = conan_api.list.select(ref_pattern, package_query=args.package_query) - if not package_list.recipes: + if package_list.recipes: + if args.check: + conan_api.cache.check_integrity(package_list) + # Check if the recipes/packages are in the remote + conan_api.upload.check_upstream(package_list, remote, args.force) + + # If only if search with "*" we ask for confirmation + if not args.list and not args.confirm and "*" in args.pattern: + _ask_confirm_upload(conan_api, package_list) + + conan_api.upload.prepare(package_list, enabled_remotes, args.metadata) + + if not args.dry_run: + conan_api.upload.upload(package_list, remote) + conan_api.upload.upload_backup_sources(package_list) + elif not args.list: + # Don't error on no recipes for automated workflows using list raise ConanException("No recipes found matching pattern '{}'".format(args.pattern)) - if args.check: - conan_api.cache.check_integrity(package_list) - # Check if the recipes/packages are in the remote - conan_api.upload.check_upstream(package_list, remote, args.force) - - # If only if search with "*" we ask for confirmation - if not args.list and not args.confirm and "*" in args.pattern: - _ask_confirm_upload(conan_api, package_list) - - conan_api.upload.prepare(package_list, enabled_remotes, args.metadata) - - if not args.dry_run: - conan_api.upload.upload(package_list, remote) - conan_api.upload.upload_backup_sources(package_list) - pkglist = MultiPackagesList() pkglist.add(remote.name, package_list) return { From 613a43a1e76f8ed8c2720116d505619e8da9fcac Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Sat, 8 Jul 2023 13:49:21 -0700 Subject: [PATCH 3/5] Add a test that expects an error from uploading a pattern that doesn't match any recipes --- conans/test/integration/command/upload/upload_test.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/conans/test/integration/command/upload/upload_test.py b/conans/test/integration/command/upload/upload_test.py index 74d03d36c74..f7ae887a14d 100644 --- a/conans/test/integration/command/upload/upload_test.py +++ b/conans/test/integration/command/upload/upload_test.py @@ -99,6 +99,12 @@ def test_pattern_upload(self): assert "Uploading recipe 'hello0/1.2.1@" in client.out assert "Uploading package 'hello0/1.2.1@" in client.out + def test_pattern_upload_no_recipes(self): + client = TestClient(default_server_user=True) + client.save({"conanfile.py": conanfile}) + client.run("upload bogus/*@dummy/testing --confirm -r default", assert_error=True) + self.assertIn("No recipes found matching pattern 'bogus/*@dummy/testing'", client.out) + def test_broken_sources_tgz(self): # https://github.com/conan-io/conan/issues/2854 client = TestClient(default_server_user=True) From e674d66054d86272adbc646c2cb9f8ceefb2b1d7 Mon Sep 17 00:00:00 2001 From: Nicolas Morales Date: Sat, 8 Jul 2023 18:56:07 -0700 Subject: [PATCH 4/5] Output a warning if no packages were uploaded due to an empty package list --- conan/cli/commands/upload.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/conan/cli/commands/upload.py b/conan/cli/commands/upload.py index 3e92fd8cb39..251dfca7229 100644 --- a/conan/cli/commands/upload.py +++ b/conan/cli/commands/upload.py @@ -1,6 +1,6 @@ from conan.api.conan_api import ConanAPI from conan.api.model import ListPattern, MultiPackagesList -from conan.api.output import cli_out_write +from conan.api.output import cli_out_write, ConanOutput from conan.cli import make_abs_path from conan.cli.command import conan_command, OnceArgument from conan.cli.commands.list import print_list_json, print_serial @@ -96,8 +96,11 @@ def upload(conan_api: ConanAPI, parser, *args): if not args.dry_run: conan_api.upload.upload(package_list, remote) conan_api.upload.upload_backup_sources(package_list) - elif not args.list: - # Don't error on no recipes for automated workflows using list + elif args.list: + # Don't error on no recipes for automated workflows using list, + # but warn to tell the user that no packages were uploaded + ConanOutput().warning(f"No packages were uploaded because the package list is empty.") + else: raise ConanException("No recipes found matching pattern '{}'".format(args.pattern)) pkglist = MultiPackagesList() From a2077e25527657c8ab6097a3951d901bc1f007cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Rinc=C3=B3n=20Blanco?= Date: Mon, 10 Jul 2023 01:11:36 +0200 Subject: [PATCH 5/5] Update conans/test/integration/command_v2/test_combined_pkglist_flows.py --- .../test/integration/command_v2/test_combined_pkglist_flows.py | 1 + 1 file changed, 1 insertion(+) 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 5513d75efe3..275931cc9ba 100644 --- a/conans/test/integration/command_v2/test_combined_pkglist_flows.py +++ b/conans/test/integration/command_v2/test_combined_pkglist_flows.py @@ -48,6 +48,7 @@ def test_list_upload_empty_list(self, client): # No binaries should be uploaded since the pkglist is empty, but the command # should not error client.run("upload --list=pkglist.json -r=default") + assert "No packages were uploaded because the package list is empty." in client.out class TestGraphCreatedUpload: