Skip to content

Commit 32174fb

Browse files
stonebigclaude
andcommitted
extend --json to -ls: machine-readable package/wheelhouse inventory
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent d70d8c1 commit 32174fb

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎wppm/wppm.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def main(test=False):
278278
parser.add_argument("-p",dest="pipdown",action="store_true",help="show Package (!= missing) dependencies of the given package[option], [.]=all: wppm -p pandas[.]")
279279
parser.add_argument("-r", dest="pipup", action="store_true", help=f"show Reverse (!= constraining) dependancies of the given package[option]: wppm -r pytest![test]")
280280
parser.add_argument("-l", dest="levels", type=int, default=-1, help="show 'LEVELS' levels of dependencies (with -p, -r): wppm -p pandas -l1")
281-
parser.add_argument("--json", dest="json", action="store_true", help="output the dependency tree as JSON (with -p, -r): wppm -p pandas[.] --json")
281+
parser.add_argument("--json", dest="json", action="store_true", help="machine-readable JSON output (with -p, -r, -ls): wppm -p pandas[.] --json")
282282
parser.add_argument("-t", dest="target", default=sys.prefix, help=f'path to target Python distribution (default: "{sys.prefix}")')
283283
parser.add_argument("-i", "--install", action="store_true", help="install a given package wheel or pylock file (use pip for more features)")
284284
parser.add_argument("-u", "--uninstall", action="store_true", help="uninstall package (use pip for more features)")
@@ -313,6 +313,9 @@ def main(test=False):
313313
for args_fname in args.fname:
314314
todo += [l for l in pip.pip_list(full=True) if bool(re.search(args_fname, l[0]))]
315315
todo = sorted(set(todo)) #, key=lambda p: (p[0].lower(), p[2])
316+
if args.json:
317+
print(json.dumps([{"package": p, "version": v, "summary": s} for p, v, s in todo], indent=4))
318+
sys.exit()
316319
titles = [['Package', 'Version', 'Summary'], ['_' * max(x, 6) for x in utils.columns_width(todo)]]
317320
listed = utils.formatted_list(titles + todo, max_width=70)
318321
for p in listed:

0 commit comments

Comments
 (0)