Skip to content

Commit

Permalink
More output on error
Browse files Browse the repository at this point in the history
  • Loading branch information
j-woz committed Jan 23, 2025
1 parent 1eeb07e commit cd04570
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions dev/conda/find-pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@
# and reported to the user in repodata.json
# We can also find the pkg name from the message
# from 'conda build' saying "anaconda upload"
# NOTE: Logging output must go on stderr,
# stdout is captured by the shell script!

import argparse, json, os, sys
import argparse, json, os

parser = argparse.ArgumentParser(description="Show the package name")
parser.add_argument("filename", help="The repodata.json file")
parser.add_argument("-v", action="store_true",
help="Make verbose")
args = parser.parse_args()

def say(msg):
import sys
sys.stderr.write("find-pkg.py: " + str(msg) + "\n")

def fail(msg):
sys.stderr.write("find-pkg.py: " + msg + "\n")
say(msg)
exit(1)

if not os.path.exists(args.filename):
Expand All @@ -24,14 +30,24 @@ def fail(msg):
with open(args.filename, "r") as fp:
J = json.load(fp)

# This was "packages" in older versions:
pkg_key = "packages.conda"

def show_repodata(J):
say("full JSON:")
say(J)
say("key: '%s'" % pkg_key)
say(J[pkg_key])

if args.v:
print(str(J))
print(str(J["packages"]))
show_repodata(J)

P = J["packages"]
P = J[pkg_key]
if len(P) != 1:
print("find-pkg.py: found packages: " + str(P))
fail("package count is %i not 1!" % len(P))
say("found packages: " + str(P))
say("package count is %i not 1!" % len(P))
show_repodata(J)
fail("FAIL.")

pkg = list(P.keys())[0]
print(pkg)

0 comments on commit cd04570

Please sign in to comment.