You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/02 13:50:06 UTC

[GitHub] [arrow] pitrou commented on a diff in pull request #14569: ARROW-18227: [CI][Packaging] Do not fail conda-clean if conda search raises PackagesNotFound

pitrou commented on code in PR #14569:
URL: https://github.com/apache/arrow/pull/14569#discussion_r1011798752


##########
dev/tasks/conda-recipes/clean.py:
##########
@@ -21,37 +21,56 @@
 ]
 
 
+class CommandFailedException(Exception):
+
+    def __init__(self, cmdline, output):
+        self.cmdline = cmdline
+        self.output = output
+
+
 def run_command(cmdline, **kwargs):
     kwargs.setdefault('capture_output', True)
     p = subprocess.run(cmdline, **kwargs)
     if p.returncode != 0:
         print(f"Command {cmdline} returned non-zero exit status "
               f"{p.returncode}", file=sys.stderr)
+        output = ""
         if p.stdout:
             print("Stdout was:\n" + "-" * 70, file=sys.stderr)
-            print(p.stdout.decode().rstrip(), file=sys.stderr)
+            output = p.stdout.decode().rstrip()
+            print(output, file=sys.stderr)
             print("-" * 70, file=sys.stderr)
         if p.stderr:
             print("Stderr was:\n" + "-" * 70, file=sys.stderr)
+            output = p.stderr.decode().rstrip()
             print(p.stderr.decode().rstrip(), file=sys.stderr)
             print("-" * 70, file=sys.stderr)
-        sys.exit(1)
+        raise CommandFailedException(cmdline=cmdline, output=output)
     return p.stdout
 
 
 def builds_to_delete(platform: str, to_delete: Set[str]) -> int:
-    pkgs_json = run_command(
-        [
-            "conda",
-            "search",
-            "--json",
-            "-c",
-            "arrow-nightlies",
-            "--override-channels",
-            "--subdir",
-            platform
-        ],
-    )
+    try:
+        pkgs_json = run_command(
+            [
+                "conda",
+                "search",
+                "--json",
+                "-c",
+                "arrow-nightlies",
+                "--override-channels",
+                "--subdir",
+                platform
+            ],
+        )
+    except CommandFailedException as ex:
+        # If the command failed due to no packages found, return
+        # 0 builds to delete.
+        if "PackagesNotFoundError" in ex.output:
+            return 0
+        else:
+            sys.exit(1)

Review Comment:
   Why swallow the exception?
   ```suggestion
               raise
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org