Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 13 additions & 44 deletions make.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# -*- coding: utf-8 -*-
#
# WinPython build script
# Copyright © 2012 Pierre Raybaut
# Copyright © 2014-2024+  The Winpython development team https://github.com/winpython/
# Licensed under the terms of the MIT License
# (see winpython/__init__.py for details)

"""
WinPython build script
"""

import os
import re
import shutil
Expand Down Expand Up @@ -66,7 +63,7 @@ def replace_lines_in_file(filepath: Path, replacements: list[tuple[str, str]]):
for index, line in enumerate(lines):
for prefix, new_text in replacements:
start_prefix = prefix
if prefix not in ("Icon", "OutFile") and not prefix.startswith("!"):
if not prefix.startswith("!"):
start_prefix = "set " + prefix
if line.startswith(start_prefix + "="):
updated_lines[index] = f"{start_prefix}={new_text}\n"
Expand All @@ -90,13 +87,12 @@ def build_installer_7zip(
output_script_path: Path to save the generated 7-Zip script.
replacements: A list of tuples for text replacements (prefix, new_text).
"""
sevenzip_executable = find_7zip_executable()
shutil.copy(script_template_path, output_script_path)

# Standard replacements for all 7zip scripts
data_to_replace = [
("PORTABLE_DIR", str(PORTABLE_DIRECTORY)),
("SEVENZIP_EXE", sevenzip_executable),
("SEVENZIP_EXE", find_7zip_executable()),
] + replacements

replace_lines_in_file(output_script_path, data_to_replace)
Expand All @@ -108,7 +104,7 @@ def build_installer_7zip(
subprocess.run(
command, shell=True, check=True, stderr=sys.stderr, stdout=sys.stderr
# with stdout=sys.stdout, we would not see 7zip compressing
) # Use subprocess.run for better error handling
)
except subprocess.CalledProcessError as e:
print(f"Error executing 7-Zip script: {e}", file=sys.stderr)

Expand Down Expand Up @@ -332,29 +328,6 @@ def documentation_directories_list(self) -> list[Path]:
return [default_docs_directory] + self.documentation_directories
return self.documentation_directories

def create_batch_script(self, name: str, contents: str, replacements: list[tuple[str, str]] = None):
"""
Creates a batch script in the WinPython scripts directory.

Args:
name: The name of the batch script file.
contents: The contents of the batch script.
replacements: A list of tuples for text replacements in the content.
"""
script_directory = self.winpython_directory / "scripts" if self.winpython_directory else None
if not script_directory:
print("Warning: WinPython directory not set, cannot create batch script.")
return
script_directory.mkdir(parents=True, exist_ok=True)
final_contents = contents
if replacements:
for old_text, new_text in replacements:
final_contents = final_contents.replace(old_text, new_text)
script_path = script_directory / name
with open(script_path, "w") as f:
f.write(final_contents)
print(f"Created batch script: {script_path}")

def create_installer_7zip(self, installer_type: str = ".exe"):
"""
Creates a WinPython installer using 7-Zip.
Expand Down Expand Up @@ -510,7 +483,7 @@ def build(self, rebuild: bool = True, requirements_files_list=None, winpy_dirnam
# Writing changelog
self._print_action("Writing changelog")
shutil.copyfile(output_markdown_filename, str(Path(CHANGELOGS_DIRECTORY) / Path(output_markdown_filename).name))
diff.write_changelog(self.winpyver2, None, self.base_directory, self.flavor, self.release_level, self.distribution.architecture)
diff.write_changelog(self.winpyver2, None, self.base_directory, self.flavor, self.distribution.architecture)


def rebuild_winpython_package(source_directory: Path, target_directory: Path, architecture: int = 64, verbose: bool = False):
Expand Down Expand Up @@ -539,19 +512,17 @@ def make_all(
docsdirs: str | list[Path] = None,
python_target_release: str = None, # e.g. "37101" for 3.7.10
):
"""Make WinPython distribution, for a given base directory and
architecture:
"""Make a WinPython distribution for a given set of parameters:
`build_number`: build number [int]
`release_level`: release level (e.g. 'beta1', '') [str]
`pyver`: python version ('3.4' or 3.5')
`architecture`: [int] (32 or 64)
`basedir`: where will be created tmp_wheel and Winpython build
r'D:\Winpython\basedir34'.
`requirements`: the package list for pip r'D:\requirements.txt',
`install_options`: pip options r'--no-index --pre --trusted-host=None',
`find_links`: package directories r'D:\Winpython\packages.srcreq',
`source_dirs`: the python.zip + rebuilt winpython wheel package directory,
`toolsdirs`: r'D:\WinPython\basedir34\t.Slim',
`basedir`: where to create the build (r'D:\Winpython\basedir34')
`requirements`: package lists for pip (r'D:\requirements.txt')
`install_options`: pip options (r'--no-index --pre --trusted-host=None')
`find_links`: package directories (r'D:\Winpython\packages.srcreq')
`source_dirs`: the python.zip + rebuilt winpython wheel package directory
`toolsdirs`: r'D:\WinPython\basedir34\t.Slim'
`docsdirs`: r'D:\WinPython\basedir34\docs.Slim'"""

assert basedir is not None, "The *basedir* directory must be specified"
Expand Down Expand Up @@ -610,9 +581,7 @@ def make_all(


if __name__ == "__main__":
# DO create only one version at a time
# You may have to manually delete previous build\winpython-.. directory

# DO create only one Winpython distribution at a time
make_all(
build_number=1,
release_level="build3",
Expand Down