diff --git a/make.py b/make.py index 773660d8..c1a6a93a 100644 --- a/make.py +++ b/make.py @@ -252,8 +252,6 @@ def build(self, rebuild: bool = True, requirements_files_list=None, winpy_dirnam self.distribution.do_pip_action(actions) self.distribution.patch_standard_packages() - self._print_action("Cleaning up distribution") - self.distribution.clean_up() # still usefull ? self._print_action("Writing package index") self.winpyver2 = f"{self.python_full_version}.{self.build_number}" output_markdown_filename = str(self.winpython_directory.parent / f"WinPython{self.flavor}-{self.distribution.architecture}bit-{self.winpyver2}.md") diff --git a/portable/scripts/make_winpython_fix.bat b/portable/scripts/make_winpython_fix.bat deleted file mode 100644 index a0dddfa6..00000000 --- a/portable/scripts/make_winpython_fix.bat +++ /dev/null @@ -1,6 +0,0 @@ -@echo off -call "%~dp0env.bat" -echo patch pip and current launchers for non-move - -"%WINPYDIR%\python.exe" -c "from winpython import wppm;dist=wppm.Distribution(r'%WINPYDIR%');dist.patch_standard_packages('pip', to_movable=False)" -pause \ No newline at end of file diff --git a/portable/scripts/make_winpython_movable.bat b/portable/scripts/make_winpython_movable.bat deleted file mode 100644 index 2ae903f8..00000000 --- a/portable/scripts/make_winpython_movable.bat +++ /dev/null @@ -1,6 +0,0 @@ -@echo off -call "%~dp0env.bat" -echo patch pip and current launchers for move - -"%WINPYDIR%\python.exe" -c "from winpython import wppm;dist=wppm.Distribution(r'%WINPYDIR%');dist.patch_standard_packages('pip', to_movable=True)" -pause \ No newline at end of file diff --git a/portable/scripts/register_python.bat b/portable/scripts/register_python.bat deleted file mode 100644 index 0298a25f..00000000 --- a/portable/scripts/register_python.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off -call "%~dp0env_for_icons.bat" -"%WINPYDIR%\python.exe" "%WINPYDIR%\Lib\site-packages\winpython\associate.py" diff --git a/portable/scripts/unregister_python.bat b/portable/scripts/unregister_python.bat deleted file mode 100644 index 6b170231..00000000 --- a/portable/scripts/unregister_python.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off -call "%~dp0env_for_icons.bat" -"%WINPYDIR%\python.exe" "%WINPYDIR%\Lib\site-packages\winpython\associate.py" --unregister diff --git a/portable/scripts/winqtconsole.bat b/portable/scripts/winqtconsole.bat deleted file mode 100644 index c05e36fa..00000000 --- a/portable/scripts/winqtconsole.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off -call "%~dp0env_for_icons.bat" %* -"%WINPYDIR%\scripts\jupyter-qtconsole.exe" %* \ No newline at end of file diff --git a/winpython/wppm.py b/winpython/wppm.py index e24ca6c2..659d14a4 100644 --- a/winpython/wppm.py +++ b/winpython/wppm.py @@ -45,22 +45,8 @@ def __init__(self, target: str = None, verbose: bool = False): self.pip = None self.to_be_removed = [] self.version, self.architecture = utils.get_python_infos(self.target) - self.short_exe = Path(utils.get_python_executable(self.target)).name - - def clean_up(self): - """Remove directories that were marked for removal.""" - for path in self.to_be_removed: - try: - shutil.rmtree(path, onexc=utils.onerror) - except OSError as e: - print(f"Error: Could not remove directory {path}: {e}", file=sys.stderr) - - def remove_directory(self, path: str): - """Try to remove a directory, add to removal list on failure.""" - try: - shutil.rmtree(path) - except OSError: - self.to_be_removed.append(path) + self.python_exe = utils.get_python_executable(self.target) + self.short_exe = Path(self.python_exe).name def create_file(self, package, name, dstdir, contents): """Generate data file -- path is relative to distribution root dir""" @@ -239,81 +225,30 @@ def install_bdist_direct(self, package, install_options=None): def main(test=False): - registerWinPythonHelp = f"Register distribution: associate file extensions, icons and context menu with this WinPython" - unregisterWinPythonHelp = f"Unregister distribution: de-associate file extensions, icons and context menu from this WinPython" + registerWinPythonHelp = f"Register WinPython: associate file extensions, icons and context menu with this WinPython" + unregisterWinPythonHelp = f"Unregister WinPython: de-associate file extensions, icons and context menu from this WinPython" parser = ArgumentParser( description="WinPython Package Manager: handle a WinPython Distribution and its packages", formatter_class=RawTextHelpFormatter, ) - parser.add_argument( - "fname", - metavar="package", - nargs="?", - default="", - type=str, - help="optional package name or package wheel", - ) - parser.add_argument( - "--register", - dest="registerWinPython", - action="store_true", # Store True when flag is present - help=registerWinPythonHelp, - ) - parser.add_argument( - "--unregister", - dest="unregisterWinPython", - action="store_true", - help=unregisterWinPythonHelp, - ) - parser.add_argument( - "-v", "--verbose", - action="store_true", - help="show more details on packages and actions", - ) - parser.add_argument( - "-ls", "--list", - action="store_true", - help="list installed packages matching the given [optional] package expression: wppm -ls, wppm -ls pand", - ) - parser.add_argument( - "-p", - dest="pipdown", - action="store_true", - help="show Package dependencies of the given package[option]: wppm -p pandas[test]", - ) - parser.add_argument( - "-r", - dest="pipup", - action="store_true", - help=f"show Reverse dependancies of the given package[option]: wppm -r pytest[test]", - ) - 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", - ) - parser.add_argument( - "-lsa", - dest="all", - action="store_true", - help=f"list details of package names matching given regular expression: wppm -lsa pandas -l1", - ) - parser.add_argument( - "-t", "--target", - default=sys.prefix, - help=f'path to target Python distribution (default: "{sys.prefix}")', - ) - parser.add_argument( - "-i", "--install", - action="store_true", - help="install a given package wheel (use pip for more features)", - ) - parser.add_argument( - "-u", "--uninstall", - action="store_true", # Store True when flag is present - help="uninstall package (use pip for more features)", - ) + parser.add_argument("fname", metavar="package", nargs="?", default="", type=str, help="optional package name or package wheel") + parser.add_argument("-v", "--verbose", action="store_true", help="show more details on packages and actions") + parser.add_argument( "--register", dest="registerWinPython", action="store_true", help=registerWinPythonHelp) + # parser.add_argument( "--register_forall", action="store_true", help="Register distribution for all users") + parser.add_argument("--unregister", dest="unregisterWinPython", action="store_true", help=unregisterWinPythonHelp) + # parser.add_argument( "--unregister_forall", action="store_true", help="un-Register distribution for all users") + parser.add_argument("--fix", action="store_true", help="make WinPython fix") + parser.add_argument("--movable", action="store_true", help="make WinPython movable") + parser.add_argument("-ls", "--list", action="store_true", help="list installed packages matching the given [optional] package expression: wppm -ls, wppm -ls pand") + parser.add_argument("-lsa", dest="all", action="store_true",help=f"list details of package names matching given regular expression: wppm -lsa pandas -l1") + parser.add_argument("-p",dest="pipdown",action="store_true",help="show Package dependencies of the given package[option]: wppm -p pandas[test]") + parser.add_argument("-r", dest="pipup", action="store_true", help=f"show Reverse dependancies of the given package[option]: wppm -r pytest[test]") + 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") + parser.add_argument("-t", "--target", default=sys.prefix, help=f'path to target Python distribution (default: "{sys.prefix}")') + parser.add_argument("-i", "--install", action="store_true", help="install a given package wheel (use pip for more features)") + parser.add_argument("-u", "--uninstall", action="store_true", help="uninstall package (use pip for more features)") + + args = parser.parse_args() targetpython = None if args.target and args.target != sys.prefix: @@ -377,26 +312,35 @@ def main(test=False): if theAnswer == "Y": associate.unregister(dist.target, verbose=args.verbose) sys.exit() - elif not args.install and not args.uninstall: - args.install = True - if not Path(args.fname).is_file() and args.install: - if args.fname == "": - parser.print_help() - sys.exit() - else: - raise FileNotFoundError(f"File not found: {args.fname}") if utils.is_python_distribution(args.target): dist = Distribution(args.target, verbose=True) - try: - if args.uninstall: - package = dist.find_package(args.fname) - dist.uninstall(package) + cmd_fix = rf"from winpython import wppm;dist=wppm.Distribution(r'{dist.target}');dist.patch_standard_packages('pip', to_movable=False)" + cmd_mov = rf"from winpython import wppm;dist=wppm.Distribution(r'{dist.target}');dist.patch_standard_packages('pip', to_movable=True)" + if args.fix: + # dist.patch_standard_packages('pip', to_movable=False) # would fail on wppm.exe + p = subprocess.Popen(["start", "cmd", "/k",dist.python_exe, "-c" , cmd_fix], shell = True, cwd=dist.target) + sys.exit() + if args.movable: + p = subprocess.Popen(["start", "cmd", "/k",dist.python_exe, "-c" , cmd_mov], shell = True, cwd=dist.target) + sys.exit() + if not args.install and not args.uninstall: + args.install = True + if not Path(args.fname).is_file() and args.install: + if args.fname == "": + parser.print_help() + sys.exit() else: - package = Package(args.fname) - if args.install: - dist.install(package) - except NotImplementedError: - raise RuntimeError("Package is not (yet) supported by WPPM") + raise FileNotFoundError(f"File not found: {args.fname}") + try: + if args.uninstall: + package = dist.find_package(args.fname) + dist.uninstall(package) + elif args.install: + package = Package(args.fname) + if args.install: + dist.install(package) + except NotImplementedError: + raise RuntimeError("Package is not (yet) supported by WPPM") else: raise OSError(f"Invalid Python distribution {args.target}")