From 8275320d8ab64ecb8bf4fa361aa2c3c7d7743303 Mon Sep 17 00:00:00 2001
From: stonebig <stonebig34@gmail.com>
Date: Wed, 16 Apr 2025 15:37:29 +0200
Subject: [PATCH] simplify 7zip installer creation

---
 make.py                     | 50 +++++++-----------------
 portable/installer_7zip.bat | 78 -------------------------------------
 2 files changed, 14 insertions(+), 114 deletions(-)
 delete mode 100644 portable/installer_7zip.bat

diff --git a/make.py b/make.py
index de329f90..8a3e2d2f 100644
--- a/make.py
+++ b/make.py
@@ -32,30 +32,6 @@ def find_7zip_executable() -> str:
             return str(executable_path)
     raise RuntimeError("7ZIP is not installed on this computer.")
 
-def build_installer_7zip(script_template_path: Path, output_script_path: Path, replacements: list[tuple[str, str]]):
-    """
-    Creates a 7-Zip installer script by copying a template and applying text replacements.
-
-    Args:
-        script_template_path: Path to the template 7-Zip script (.bat file).
-        output_script_path: Path to save the generated 7-Zip script.
-        replacements: A list of tuples for text replacements (prefix, new_text).
-    """
-    # Standard replacements for all 7zip scripts
-    data_to_replace = [
-        ("PORTABLE_DIR=", f"PORTABLE_DIR={PORTABLE_DIRECTORY}& rem "),
-        ("SEVENZIP_EXE=", f"SEVENZIP_EXE={find_7zip_executable()}& rem "),
-    ] + [(f"{a}=", f"{a}={b}& rem ") for a, b in replacements]
-
-    utils.replace_in_file(script_template_path, data_to_replace, output_script_path)
-
-    try:
-        # Execute the generated 7-Zip script, with stdout=sys.stderr to see 7zip compressing
-        print(f'Executing 7-Zip script: "{output_script_path}"')
-        subprocess.run(f'"{output_script_path}"', shell=True, check=True, stderr=sys.stderr, stdout=sys.stderr)
-    except subprocess.CalledProcessError as e:
-        print(f"Error executing 7-Zip script: {e}", file=sys.stderr)
-
 def copy_items(source_directories: list[Path], target_directory: Path, verbose: bool = False):
     """Copies items from source directories to the target directory."""
     target_directory.mkdir(parents=True, exist_ok=True)
@@ -216,21 +192,23 @@ def architecture_bits(self) -> int:
     def create_installer_7zip(self, installer_type: str = ".exe"):
         """Creates a WinPython installer using 7-Zip: ".exe", ".7z", ".zip")"""
         self._print_action(f"Creating WinPython installer ({installer_type})")
-        template_name = "installer_7zip.bat"
-        output_name = "installer_7zip-tmp.bat"
         if installer_type not in [".exe", ".7z", ".zip"]:
             print(f"Warning: Unsupported installer type '{installer_type}'. Defaulting to .exe")
             installer_type = ".exe"
-
-        replacements = [
-            ("DISTDIR", str(self.winpython_directory)),
-            ("ARCH", str(self.architecture_bits)),
-            ("VERSION", f"{self.python_full_version}.{self.build_number}{self.flavor}"),
-            ("VERSION_INSTALL", f'{self.python_full_version.replace(".", "")}{self.build_number}'),
-            ("RELEASELEVEL", self.release_level),
-            ("INSTALLER_OPTION", installer_type),
-        ]
-        build_installer_7zip(PORTABLE_DIRECTORY / template_name, self.target_directory  / output_name, replacements)
+        DISTDIR = self.winpython_directory
+        filname_stemp = f"Winpython{str(self.architecture_bits)}-{self.python_full_version}.{self.build_number}{self.flavor}{self.release_level}"
+        fullfilename = DISTDIR.parent / (filname_stemp + installer_type)
+        if installer_type == ".zip":
+            other = f'"{find_7zip_executable()}" -tzip -mx5 a "{fullfilename}" "{DISTDIR}" '
+        if installer_type == ".7z":
+            other = f'"{find_7zip_executable()}" -mx5 a "{fullfilename}" "{DISTDIR}" '
+        if installer_type == ".exe":
+            other = f'"{find_7zip_executable()}" -mx5 a "{fullfilename}" "{DISTDIR}" -sfx7z.sfx'
+        print(f'Executing 7-Zip script: "{other}"')
+        try:
+            subprocess.run(other, shell=True, check=True, stderr=sys.stderr, stdout=sys.stderr)
+        except subprocess.CalledProcessError as e:
+            print(f"Error executing 7-Zip script: {e}", file=sys.stderr)
 
     def _print_action(self, text: str):
         """Prints an action message with progress indicator."""
diff --git a/portable/installer_7zip.bat b/portable/installer_7zip.bat
deleted file mode 100644
index 0b308f2a..00000000
--- a/portable/installer_7zip.bat
+++ /dev/null
@@ -1,78 +0,0 @@
-rem Copyright @ 2018 WinPython team
-rem Licensed under the terms of the MIT License
-rem (see winpython/__init__.py for details)
-
-rem This is to do a 7-zip installer
-
-rem ================================================================
-rem These lines are automatically replaced when creating installer:
-rem (see winpython/make.py)
-set SEVENZIP_EXE=C:\Program Files (x86)\7-Zip\7z
-set DISTDIR=C:\WinP\bd36\buPs2\winp64-3.6.x.0
-set ARCH=64
-set VERSION=3.6.7.0Ps2
-
-rem  2018-04-04 need to minimize path length of installation further: remove flavor in install path
-
-set VERSION_INSTALL=3670
-
-set RELEASELEVEL=beta3
-set PORTABLE_DIR=C:\WinPython-64bit-3.4.3.7Qt5\winpython_github20181029\portable
-set INSTALLER_OPTION=.exe
-
-rem ================================================================
-rem these lines are static definitions
-set ID=Winpython
-set ID_INSTALL=WPy
-set FILE_DESCRIPTION=%ID% Installer
-set COMPANY=%ID%
-set BRANDING=%ID%, the portable Python Distribution for Scientists
-set COPYRIGHT=Copyright © 2018+ WinPython Team
-set MyAppPublisher=WinPython team
-set MyAppURL=https://winpython.github.io/
-
-rem  OutputBaseFilename "{#ID}{#ARCH}-{#VERSION}{#RELEASELEVEL}"
-
-rem ================================================================ [Setup]
-rem OutFile "${DISTDIR}\..\${ID}${ARCH}-${VERSION}${RELEASELEVEL}.exe"
-set MyBinaryOutputDir=%DISTDIR%\..
-set OutputBaseFilename=%ID%%ARCH%-%VERSION%%RELEASELEVEL%
-
-rem 7-zip uncompress the directory compressed %DISTDIR% (no option to change it in gui)
-
-rem ================================================================
-rem  2019-03-16 copy license at source (due to 7zip limitations)
-
-REM 2025-01-05 done in make.py 
-rem copy/Y %PORTABLE_DIR%\license.txt %DISTDIR%\license.txt
-
-rem ================================================================
-
-echo %time%
-
-rem compression + include auto_extract in GUI mode
-if "%INSTALLER_OPTION%"==".exe" (
-    "%SEVENZIP_EXE%" -mx5 a "%MyBinaryOutputDir%\%OutputBaseFilename%.exe" %DISTDIR% -sfx7z.sfx
-    echo  autoextract using command line options 
-    echo "%MyBinaryOutputDir%\%OutputBaseFilename%.exe" -y -o%MyBinaryOutputDir%\zz > NUL
-    )
-
-if "%INSTALLER_OPTION%"==".7z" (
-    "%SEVENZIP_EXE%" -mx5 a "%MyBinaryOutputDir%\%OutputBaseFilename%.7z" %DISTDIR%
-    echo  no autoextract 
-    )
-if "%INSTALLER_OPTION%"==".zip" (
-    "%SEVENZIP_EXE%" -tzip -mx5 a "%MyBinaryOutputDir%\%OutputBaseFilename%.zip" %DISTDIR%
-    echo  no autoextract 
-    )
-
-
-
-rem -mx1 = speed fastest
-rem -mx3 = speed fast
-rem -mx5 = speed normal
-rem -mx7 = compress maximum
-rem -mx9 = compress ultra
-
-rem -t7z  = [by default] 7 zip compression , the only choice with auto-extract 
-rem -tzip = Zip compatible compression.