Skip to content

Commit 6a1549d

Browse files
authored
Merge pull request #1553 from stonebig/master
simplify 7zip installer creation
2 parents 6c4dbef + 8275320 commit 6a1549d

File tree

2 files changed

+14
-114
lines changed

2 files changed

+14
-114
lines changed

make.py

+14-36
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,6 @@ def find_7zip_executable() -> str:
3232
return str(executable_path)
3333
raise RuntimeError("7ZIP is not installed on this computer.")
3434

35-
def build_installer_7zip(script_template_path: Path, output_script_path: Path, replacements: list[tuple[str, str]]):
36-
"""
37-
Creates a 7-Zip installer script by copying a template and applying text replacements.
38-
39-
Args:
40-
script_template_path: Path to the template 7-Zip script (.bat file).
41-
output_script_path: Path to save the generated 7-Zip script.
42-
replacements: A list of tuples for text replacements (prefix, new_text).
43-
"""
44-
# Standard replacements for all 7zip scripts
45-
data_to_replace = [
46-
("PORTABLE_DIR=", f"PORTABLE_DIR={PORTABLE_DIRECTORY}& rem "),
47-
("SEVENZIP_EXE=", f"SEVENZIP_EXE={find_7zip_executable()}& rem "),
48-
] + [(f"{a}=", f"{a}={b}& rem ") for a, b in replacements]
49-
50-
utils.replace_in_file(script_template_path, data_to_replace, output_script_path)
51-
52-
try:
53-
# Execute the generated 7-Zip script, with stdout=sys.stderr to see 7zip compressing
54-
print(f'Executing 7-Zip script: "{output_script_path}"')
55-
subprocess.run(f'"{output_script_path}"', shell=True, check=True, stderr=sys.stderr, stdout=sys.stderr)
56-
except subprocess.CalledProcessError as e:
57-
print(f"Error executing 7-Zip script: {e}", file=sys.stderr)
58-
5935
def copy_items(source_directories: list[Path], target_directory: Path, verbose: bool = False):
6036
"""Copies items from source directories to the target directory."""
6137
target_directory.mkdir(parents=True, exist_ok=True)
@@ -216,21 +192,23 @@ def architecture_bits(self) -> int:
216192
def create_installer_7zip(self, installer_type: str = ".exe"):
217193
"""Creates a WinPython installer using 7-Zip: ".exe", ".7z", ".zip")"""
218194
self._print_action(f"Creating WinPython installer ({installer_type})")
219-
template_name = "installer_7zip.bat"
220-
output_name = "installer_7zip-tmp.bat"
221195
if installer_type not in [".exe", ".7z", ".zip"]:
222196
print(f"Warning: Unsupported installer type '{installer_type}'. Defaulting to .exe")
223197
installer_type = ".exe"
224-
225-
replacements = [
226-
("DISTDIR", str(self.winpython_directory)),
227-
("ARCH", str(self.architecture_bits)),
228-
("VERSION", f"{self.python_full_version}.{self.build_number}{self.flavor}"),
229-
("VERSION_INSTALL", f'{self.python_full_version.replace(".", "")}{self.build_number}'),
230-
("RELEASELEVEL", self.release_level),
231-
("INSTALLER_OPTION", installer_type),
232-
]
233-
build_installer_7zip(PORTABLE_DIRECTORY / template_name, self.target_directory / output_name, replacements)
198+
DISTDIR = self.winpython_directory
199+
filname_stemp = f"Winpython{str(self.architecture_bits)}-{self.python_full_version}.{self.build_number}{self.flavor}{self.release_level}"
200+
fullfilename = DISTDIR.parent / (filname_stemp + installer_type)
201+
if installer_type == ".zip":
202+
other = f'"{find_7zip_executable()}" -tzip -mx5 a "{fullfilename}" "{DISTDIR}" '
203+
if installer_type == ".7z":
204+
other = f'"{find_7zip_executable()}" -mx5 a "{fullfilename}" "{DISTDIR}" '
205+
if installer_type == ".exe":
206+
other = f'"{find_7zip_executable()}" -mx5 a "{fullfilename}" "{DISTDIR}" -sfx7z.sfx'
207+
print(f'Executing 7-Zip script: "{other}"')
208+
try:
209+
subprocess.run(other, shell=True, check=True, stderr=sys.stderr, stdout=sys.stderr)
210+
except subprocess.CalledProcessError as e:
211+
print(f"Error executing 7-Zip script: {e}", file=sys.stderr)
234212

235213
def _print_action(self, text: str):
236214
"""Prints an action message with progress indicator."""

portable/installer_7zip.bat

-78
This file was deleted.

0 commit comments

Comments
 (0)