8000 Merge pull request #1596 from stonebig/master · winpython/winpython@aba6b68 · GitHub
[go: up one dir, main page]

Skip to content

Commit aba6b68

Browse files
authored
Merge pull request #1596 from stonebig/master
replace --fix and --movable per wppm options
2 parents 7a1f32f + 316c6e6 commit aba6b68

File tree

3 files changed

+48
-101
lines changed

3 files changed

+48
-101
lines changed

portable/scripts/make_winpython_fix.bat

Lines changed: 0 additions & 6 deletions
This file was deleted.

portable/scripts/make_winpython_movable.bat

Lines changed: 0 additions & 6 deletions
This file was deleted.

winpython/wppm.py

Lines changed: 48 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def __init__(self, target: str = None, verbose: bool = False):
4545
self.pip = None
4646
self.to_be_removed = []
4747
self.version, self.architecture = utils.get_python_infos(self.target)
48-
self.short_exe = Path(utils.get_python_executable(self.target)).name
48+
self.python_exe = utils.get_python_executable(self.target)
49+
self.short_exe = Path(self.python_exe).name
4950

5051
def create_file(self, package, name, dstdir, contents):
5152
"""Generate data file -- path is relative to distribution root dir"""
@@ -224,81 +225,30 @@ def install_bdist_direct(self, package, install_options=None):
224225

225226
def main(test=False):
226227

227-
registerWinPythonHelp = f"Register distribution: associate file extensions, icons and context menu with this WinPython"
228-
unregisterWinPythonHelp = f"Unregister distribution: de-associate file extensions, icons and context menu from this WinPython"
228+
registerWinPythonHelp = f"Register WinPython: associate file extensions, icons and context menu with this WinPython"
229+
unregisterWinPythonHelp = f"Unregister WinPython: de-associate file extensions, icons and context menu from this WinPython"
229230
parser = ArgumentParser(
230231
description="WinPython Package Manager: handle a WinPython Distribution and its packages",
231232
formatter_class=RawTextHelpFormatter,
232233
)
233-
parser.add_argument(
234-
"fname",
235-
metavar="package",
236-
nargs="?",
237-
default="",
238-
type=str,
239-
help="optional package name or package wheel",
240-
)
241-
parser.add_argument(
242-
"--register",
243-
dest="registerWinPython",
244-
action="store_true", # Store True when flag is present
245-
help=registerWinPythonHelp,
246-
)
247-
parser.add_argument(
248-
"--unregister",
249-
dest="unregisterWinPython",
250-
action="store_true",
251-
help=unregisterWinPythonH EDBE elp,
252-
)
253-
parser.add_argument(
254-
"-v", "--verbose",
255-
action="store_true",
256-
help="show more details on packages and actions",
257-
)
258-
parser.add_argument(
259-
"-ls", "--list",
260-
action="store_true",
261-
help="list installed packages matching the given [optional] package expression: wppm -ls, wppm -ls pand",
262-
)
263-
parser.add_argument(
264-
"-p",
265-
dest="pipdown",
266-
action="store_true",
267-
help="show Package dependencies of the given package[option]: wppm -p pandas[test]",
268-
)
269-
parser.add_argument(
270-
"-r",
271-
dest="pipup",
272-
action="store_true",
273-
help=f"show Reverse dependancies of the given package[option]: wppm -r pytest[test]",
274-
)
275-
parser.add_argument(
276-
"-l", "--levels",
277-
type=int,
278-
default=2,
279-
help="show 'LEVELS' levels of dependencies (with -p, -r), default is 2: wppm -p pandas -l1",
280-
)
281-
parser.add_argument(
282-
"-lsa",
283-
dest="all",
284-
action="store_true",
285-
help=f"list details of package names matching given regular expression: wppm -lsa pandas -l1",
286-
)
287-
parser.add_argument(
288-
"-t", "--target",
289-
default=sys.prefix,
290-
help=f'path to target Python distribution (default: "{sys.prefix}")',
291-
)
292-
parser.add_argument(
293-
"-i", "--install",
294-
action="store_true",
295-
help="install a given package wheel (use pip for more features)",
296-
)
297-
parser.add_argument(
298-
"-u", "--uninstall",
299-
action="store_true", # Store True when flag is present
300-
help="uninstall package (use pip for more features)",
301-
)
234+
parser.add_argument("fname", metavar="package", nargs="?", default="", type=str, help="optional package name or package wheel")
235+
parser.add_argument("-v", "--verbose", action="store_true", help="show more details on packages and actions")
236+
parser.add_argument( "--register", dest="registerWinPython", action="store_true", help=registerWinPythonHelp)
237+
# parser.add_argument( "--register_forall", action="store_true", help="Register distribution for all users")
238+
parser.add_argument("--unregister", dest="unregisterWinPython", action="store_true", help=unregisterWinPythonHelp)
239+
# parser.add_argument( "--unregister_forall", action="store_true", help="un-Register distribution for all users")
240+
parser.add_argument("--fix", action="store_true", help="make WinPython fix")
241+
parser.add_argument("--movable", action="store_true", help="make WinPython movable")
242+
parser.add_argument("-ls", "--list", action="store_true", help="list installed packages matching the given [optional] package expression: wppm -ls, wppm -ls pand")
243+
parser.add_argument("-lsa", dest="all", action="store_true",help=f"list details of package names matching given regular expression: wppm -lsa pandas -l1")
244+
parser.add_argument("-p",dest="pipdown",action="store_true",help="show Package dependencies of the given package[option]: wppm -p pandas[test]")
245+
parser.add_argument("-r", dest="pipup", action="store_true", help=f"show Reverse dependancies of the given package[option]: wppm -r pytest[test]")
246+
parser.add_argument("-l", "--levels", type=int, default=2, help="show 'LEVELS' levels of dependencies (with -p, -r), default is 2: wppm -p pandas -l1")
247+
parser.add_argument("-t", "--target", default=sys.prefix, help=f'path to target Python distribution (default: "{sys.prefix}")')
248+
parser.add_argument("-i", "--install", action="store_true", help="install a given package wheel (use pip for more features)")
249+
parser.add_argument("-u", "--uninstall", action="store_true", help="uninstall package (use pip for more features)")
250+
251+
302252
args = parser.parse_args()
303253
targetpython = None
304254
if args.target and args.target != sys.prefix:
@@ -362,26 +312,35 @@ def main(test=False):
362312
if theAnswer == "Y":
363313
associate.unregister(dist.target, verbose=args.verbose)
364314
sys.exit()
365-
elif not args.install and not args.uninstall:
366-
args.install = True
367-
if not Path(args.fname).is_file() and args.install:
368-
if args.fname == "":
369-
parser.print_help()
370-
sys.exit()
371-
else:
372-
raise FileNotFoundError(f"File not found: {args.fname}")
373315
if utils.is_python_distribution(args.target):
374316
dist = Distribution(args.target, verbose=True)
375-
try:
376-
if args.uninstall:
377-
package = dist.find_package(args.fname)
378-
dist.uninstall(package)
317+
cmd_fix = rf"from winpython import wppm;dist=wppm.Distribution(r'{dist.target}');dist.patch_standard_packages('pip', to_movable=False)"
318+
cmd_mov = rf"from winpython import wppm;dist=wppm.Distribution(r'{dist.target}');dist.patch_standard_packages('pip', to_movable=True)"
319+
if args.fix:
320+
# dist.patch_standard_packages('pip', to_movable=False) # would fail on wppm.exe
321+
p = subprocess.Popen(["start", "cmd", "/k",dist.python_exe, "-c" , cmd_fix], shell = True, cwd=dist.target)
322+
sys.exit()
323+
if args.movable:
324+
p = subprocess.Popen(["start", "cmd", "/k",dist.python_exe, "-c" , cmd_mov], shell = True, cwd=dist.target)
325+
sys.exit()
326+
if not args.install and not args.uninstall:
327+
args.install = True
328+
if not Path(args.fname).is_file() and args.install:
329+
if args.fname == "":
330+
parser.print_help()
331+
sys.exit()
379332
else:
380-
package = Package(args.fname)
381-
if args.install:
382-
dist.install(package)
383-
except NotImplementedError:
384-
raise RuntimeError("Package is not (yet) supported by WPPM")
333+
raise FileNotFoundError(f"File not found: {args.fname}")
334+
try:
335+
if args.uninstall:
336+
package = dist.find_package(args.fname)
337+
dist.uninstall(package)
338+
elif args.install:
339+
package = Package(args.fname)
340+
if args.install:
341+
dist.install(package)
342+
except NotImplementedError:
343+
raise RuntimeError("Package is not (yet) supported by WPPM")
385344
else:
386345
raise OSError(f"Invalid Python distribution {args.target}")
387346

0 commit comments

Comments
 (0)
0