Skip to content

Commit 25ca4cf

Browse files
committed
wppm support multiple packages install, list or navigation
1 parent cb85466 commit 25ca4cf

File tree

1 file changed

+40
-37
lines changed

1 file changed

+40
-37
lines changed

winpython/wppm.py

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def patch_standard_packages(self, package_name="", to_movable=True):
184184
# create movable launchers for previous package installations
185185
self.patch_all_shebang(to_movable=to_movable)
186186
if package_name.lower() in ("", "spyder"):
187-
# spyder don't goes on internet without I ask
187+
# spyder don't goes on internet without you ask
188188
utils.patch_sourcefile(
189189
Path(self.target) / "lib" / "site-packages" / "spyder" / "config" / "main.py",
190190
"'check_updates_on_startup': True,",
@@ -266,27 +266,24 @@ def main(test=False):
266266
description="WinPython Package Manager: handle a WinPython Distribution and its packages",
267267
formatter_class=RawTextHelpFormatter,
268268
)
269-
parser.add_argument("fname", metavar="package or lockfile", nargs="?", default="", type=str, help="optional package name or package wheel")
269+
parser.add_argument("fname", metavar="package(s) or lockfile", nargs="*", default=[""], type=str, help="optional package names, wheels, or lockfile")
270270
parser.add_argument("-v", "--verbose", action="store_true", help="show more details on packages and actions")
271271
parser.add_argument( "--register", dest="registerWinPython", action="store_true", help=registerWinPythonHelp)
272-
# parser.add_argument( "--register_forall", action="store_true", help="Register distribution for all users")
273272
parser.add_argument("--unregister", dest="unregisterWinPython", action="store_true", help=unregisterWinPythonHelp)
274-
# parser.add_argument( "--unregister_forall", action="store_true", help="un-Register distribution for all users")
275273
parser.add_argument("--fix", action="store_true", help="make WinPython fix")
276274
parser.add_argument("--movable", action="store_true", help="make WinPython movable")
277275
parser.add_argument("-ws", dest="wheelsource", default=None, type=str, help="wheels location, '.' = WheelHouse): wppm pylock.toml -ws source_of_wheels, wppm -ls -ws .")
278276
parser.add_argument("-wd", dest="wheeldrain" , default=None, type=str, help="wheels destination: wppm pylock.toml -wd destination_of_wheels")
279277
parser.add_argument("-ls", "--list", action="store_true", help="list installed packages matching [optional] expression: wppm -ls, wppm -ls pand")
280278
parser.add_argument("-lsa", dest="all", action="store_true",help=f"list details of packages matching [optional] expression: wppm -lsa pandas -l1")
281-
parser.add_argument("-md", dest="markdown", action="store_true",help=f"markdown summary if the installation")
279+
parser.add_argument("-md", dest="markdown", action="store_true",help=f"markdown summary of the installation")
282280
parser.add_argument("-p",dest="pipdown",action="store_true",help="show Package dependencies of the given package[option], [.]=all: wppm -p pandas[.]")
283281
parser.add_argument("-r", dest="pipup", action="store_true", help=f"show Reverse wppmdependancies of the given package[option]: wppm -r pytest[test]")
284282
parser.add_argument("-l", dest="levels", type=int, default=2, help="show 'LEVELS' levels of dependencies (with -p, -r), default is 2: wppm -p pandas -l1")
285283
parser.add_argument("-t", dest="target", default=sys.prefix, help=f'path to target Python distribution (default: "{sys.prefix}")')
286284
parser.add_argument("-i", "--install", action="store_true", help="install a given package wheel or pylock file (use pip for more features)")
287285
parser.add_argument("-u", "--uninstall", action="store_true", help="uninstall package (use pip for more features)")
288286

289-
290287
args = parser.parse_args()
291288
targetpython = None
292289
if args.target and args.target != sys.prefix:
@@ -301,35 +298,40 @@ def main(test=False):
301298
raise RuntimeError("Incompatible arguments: --install and --uninstall")
302299
if args.pipdown:
303300
pip = piptree.PipData(targetpython, args.wheelsource)
304-
pack, extra, *other = (args.fname + "[").replace("]", "[").split("[")
305-
print(pip.down(pack, extra, args.levels, verbose=args.verbose))
301+
for args_fname in args.fname:
302+
pack, extra, *other = (args_fname + "[").replace("]", "[").split("[")
303+
print(pip.down(pack, extra, args.levels, verbose=args.verbose))
306304
sys.exit()
307305
elif args.pipup:
308306
pip = piptree.PipData(targetpython, args.wheelsource)
309-
pack, extra, *other = (args.fname + "[").replace("]", "[").split("[")
310-
print(pip.up(pack, extra, args.levels, verbose=args.verbose))
307+
for args_fname in args.fname:
308+
pack, extra, *other = (args_fname + "[").replace("]", "[").split("[")
309+
print(pip.up(pack, extra, args.levels, verbose=args.verbose))
311310
sys.exit()
312311
elif args.list:
313312
pip = piptree.PipData(targetpython, args.wheelsource)
314-
todo = [l for l in pip.pip_list(full=True) if bool(re.search(args.fname, l[0]))]
313+
todo= []
314+
for args_fname in args.fname:
315+
todo += [l for l in pip.pip_list(full=True) if bool(re.search(args_fname, l[0]))]
316+
todo = sorted(set(todo)) #, key=lambda p: (p[0].lower(), p[2])
315317
titles = [['Package', 'Version', 'Summary'], ['_' * max(x, 6) for x in utils.columns_width(todo)]]
316318
listed = utils.formatted_list(titles + todo, max_width=70)
317319
for p in listed:
318320
print(*p)
319321
sys.exit()
320322
elif args.all:
321323
pip = piptree.PipData(targetpython, args.wheelsource)
322-
todo = [l for l in pip.pip_list(full=True) if bool(re.search(args.fname, l[0]))]
323-
for l in todo:
324-
# print(pip.distro[l[0]])
325-
title = f"** Package: {l[0]} **"
326-
print("\n" + "*" * len(title), f"\n{title}", "\n" + "*" * len(title))
327-
for key, value in pip.raw[l[0]].items():
328-
rawtext = json.dumps(value, indent=2, ensure_ascii=False)
329-
lines = [l for l in rawtext.split(r"\n") if len(l.strip()) > 2]
330-
if key.lower() != 'description' or args.verbose:
331-
print(f"{key}: ", "\n".join(lines).replace('"', ""))
332-
sys.exit()
324+
for args_fname in args.fname:
325+
todo = [l for l in pip.pip_list(full=True) if bool(re.search(args_fname, l[0]))]
326+
for l in sorted(set(todo)):
327+
title = f"** Package: {l[0]} **"
328+
print("\n" + "*" * len(title), f"\n{title}", "\n" + "*" * len(title))
329+
for key, value in pip.raw[l[0]].items():
330+
rawtext = json.dumps(value, indent=2, ensure_ascii=False)
331+
lines = [l for l in rawtext.split(r"\n") if len(l.strip()) > 2]
332+
if key.lower() != 'description' or args.verbose:
333+
print(f"{key}: ", "\n".join(lines).replace('"', ""))
334+
sys.exit()
333335
if args.registerWinPython:
334336
print(registerWinPythonHelp)
335337
if utils.is_python_distribution(args.target):
@@ -373,26 +375,27 @@ def main(test=False):
373375
else:
374376
print(default)
375377
sys.exit()
376-
if not args.install and not args.uninstall and args.fname.endswith(".toml"):
378+
if not args.install and not args.uninstall and args.fname[0].endswith(".toml"):
377379
args.install = True # for Drag & Drop of .toml (and not wheel)
378-
if args.fname == "" or (not args.install and not args.uninstall):
380+
if args.fname[0] == "" or (not args.install and not args.uninstall):
379381
parser.print_help()
380382
sys.exit()
381383
else:
382384
try:
383-
filename = Path(args.fname).name
384-
install_from_wheelhouse = ["--no-index", "--trusted-host=None", f"--find-links={dist.wheelhouse / 'included.wheels'}"]
385-
if filename.split('.')[0] == "pylock" and filename.split('.')[-1] == 'toml':
386-
print(' a lock file !', args.fname, dist.target)
387-
wh.get_pylock_wheels(dist.wheelhouse, Path(args.fname), args.wheelsource, args.wheeldrain)
388-
sys.exit()
389-
if args.uninstall:
390-
package = dist.find_package(args.fname)
391-
dist.uninstall(package)
392-
elif args.install:
393-
package = Package(args.fname)
394-
if args.install:
395-
dist.install(package, install_options=install_from_wheelhouse)
385+
for args_fname in args.fname:
386+
filename = Path(args_fname).name
387+
install_from_wheelhouse = ["--no-index", "--trusted-host=None", f"--find-links={dist.wheelhouse / 'included.wheels'}"]
388+
if filename.split('.')[0] == "pylock" and filename.split('.')[-1] == 'toml':
389+
print(' a lock file !', args_fname, dist.target)
390+
wh.get_pylock_wheels(dist.wheelhouse, Path(args_fname), args.wheelsource, args.wheeldrain)
391+
sys.exit()
392+
if args.uninstall:
393+
package = dist.find_package(args_fname)
394+
dist.uninstall(package)
395+
elif args.install:
396+
package = Package(args_fname)
397+
if args.install:
398+
dist.install(package, install_options=install_from_wheelhouse)
396399
except NotImplementedError:
397400
raise RuntimeError("Package is not (yet) supported by WPPM")
398401
else:

0 commit comments

Comments
 (0)