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

Skip to content

Commit 7c1675d

Browse files
authored
Merge pull request #1554 from stonebig/master
small tweaks to make.py with mistral AI free
2 parents 6a1549d + 0ac8614 commit 7c1675d

File tree

1 file changed

+20
-34
lines changed

1 file changed

+20
-34
lines changed

make.py

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# Define constant paths for clarity
2020
CHANGELOGS_DIRECTORY = Path(__file__).parent / "changelogs"
2121
PORTABLE_DIRECTORY = Path(__file__).parent / "portable"
22+
NODEJS_RELATIVE_PATH = "n" # Relative path within WinPython dir
2223

2324
# Ensure necessary directories exist at the start
2425
assert CHANGELOGS_DIRECTORY.is_dir(), f"Changelogs directory not found: {CHANGELOGS_DIRECTORY}"
@@ -58,14 +59,11 @@ def parse_list_argument(argument_value: str | list[str], separator=" ") -> list[
5859
class WinPythonDistributionBuilder:
5960
"""Builds a WinPython distribution."""
6061

61-
NODEJS_RELATIVE_PATH = "n" # Relative path within WinPython dir
62-
6362
def __init__(self, build_number: int, release_level: str, target_directory: Path, wheels_directory: Path,
6463
tools_directories: list[Path] = None, documentation_directories: list[Path] = None, verbose: bool = False,
6564
base_directory: Path = None, install_options: list[str] = None, flavor: str = ""):
6665
"""
6766
Initializes the WinPythonDistributionBuilder.
68-
6967
Args:
7068
build_number: The build number (integer).
7169
release_level: The release level (e.g., "beta", "").
@@ -97,7 +95,7 @@ def __init__(self, build_number: int, release_level: str, target_directory: Path
9795
def _get_python_zip_file(self) -> Path:
9896
"""Finds the Python .zip file in the wheels directory."""
9997
for source_item in self.wheels_directory.iterdir():
100-
if re.match("(pypy3|python-)([0-9]|[a-zA-Z]|.)*.zip", source_item.name):
98+
if re.match(r"(pypy3|python-)([0-9]|[a-zA-Z]|.)*.zip", source_item.name):
10199
return source_item
102100
raise RuntimeError(f"Could not find Python zip package in {self.wheels_directory}")
103101

@@ -138,7 +136,7 @@ def get_tool_path(relative_path):
138136
path = self.winpython_directory / relative_path if self.winpython_directory else None
139137
return path if path and path.exists() else None
140138

141-
if nodejs_path := get_tool_path(self.NODEJS_RELATIVE_PATH):
139+
if nodejs_path := get_tool_path(NODEJS_RELATIVE_PATH):
142140
installed_tools.append(("Nodejs", utils.get_nodejs_version(nodejs_path)))
143141
installed_tools.append(("npmjs", utils.get_npmjs_version(nodejs_path)))
144142

@@ -151,8 +149,7 @@ def get_tool_path(relative_path):
151149
tool_lines = []
152150
for name, version in installed_tools:
153151
metadata = utils.get_package_metadata("tools.ini", name)
154-
url, description = metadata["url"], metadata["description"]
155-
tool_lines.append(f"[{name}]({url}) | {version} | {description}")
152+
tool_lines.append(f"[{name}]({metadata['url']}) | {version} | {metadata['description']}")
156153
return "\n".join(tool_lines)
157154

158155
def _get_installed_packages_markdown(self) -> str:
@@ -193,20 +190,16 @@ def create_installer_7zip(self, installer_type: str = ".exe"):
193190
"""Creates a WinPython installer using 7-Zip: ".exe", ".7z", ".zip")"""
194191
self._print_action(f"Creating WinPython installer ({installer_type})")
195192
if installer_type not in [".exe", ".7z", ".zip"]:
196-
print(f"Warning: Unsupported installer type '{installer_type}'. Defaulting to .exe")
197-
installer_type = ".exe"
193+
raise RuntimeError("installer_type {installer_type} is undefined")
198194
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}"')
195+
filename_stem = f"Winpython{self.architecture_bits}-{self.python_full_version}.{self.build_number}{self.flavor}{self.release_level}"
196+
fullfilename = DISTDIR.parent / (filename_stem + installer_type)
197+
sfx_option = "-sfx7z.sfx" if installer_type == ".exe" else ""
198+
zip_option = "-tzip" if installer_type == ".zip" else ""
199+
command = f'"{find_7zip_executable()}" {zip_option} -mx5 a "{fullfilename}" "{DISTDIR}" {sfx_option}'
200+
print(f'Executing 7-Zip script: "{command}"')
208201
try:
209-
subprocess.run(other, shell=True, check=True, stderr=sys.stderr, stdout=sys.stderr)
202+
subprocess.run(command, shell=True, check=True, stderr=sys.stderr, stdout=sys.stderr)
210203
except subprocess.CalledProcessError as e:
211204
print(f"Error executing 7-Zip script: {e}", file=sys.stderr)
212205

@@ -243,22 +236,20 @@ def _copy_essential_files(self):
243236
copy_items(self.tools_directories, tools_target_directory, self.verbose)
244237

245238
if (nodejs_current_directory := tools_target_directory / "n").is_dir():
246-
self._print_action(f"moving tools from {nodejs_current_directory} to {tools_target_directory.parent / self.NODEJS_RELATIVE_PATH} ")
239+
self._print_action(f"Moving tools from {nodejs_current_directory} to {tools_target_directory.parent / NODEJS_RELATIVE_PATH}")
247240
try:
248-
shutil.move(nodejs_current_directory, tools_target_directory.parent / self.NODEJS_RELATIVE_PATH)
241+
shutil.move(nodejs_current_directory, tools_target_directory.parent / NODEJS_RELATIVE_PATH)
249242
except Exception as e:
250243
print(f"Error moving Node.js directory: {e}")
251244

252245
def _create_initial_batch_scripts(self):
253246
"""Creates initial batch scripts, including environment setup."""
254247
self._print_action("Creating initial batch scripts")
255-
256248
# Replacements for batch scripts (PyPy compatibility)
257249
executable_name = self.distribution.short_exe if self.distribution else "python.exe" # default to python.exe if distribution is not yet set
258-
259250
init_variables = [('WINPYthon_exe', executable_name), ('WINPYthon_subdirectory_name', self.python_directory_name), ('WINPYVER', self.winpython_version_name)]
260251
with open(self.winpython_directory / "scripts" / "env.ini", "w") as f:
261-
f.writelines([f'{a}={b}\n' for a , b in init_variables])
252+
f.writelines([f'{a}={b}\n' for a, b in init_variables])
262253

263254
def build(self, rebuild: bool = True, requirements_files_list=None, winpy_dirname: str = None):
264255
"""Make or finalise WinPython distribution in the target directory"""
@@ -296,9 +287,7 @@ def build(self, rebuild: bool = True, requirements_files_list=None, winpy_dirnam
296287

297288
if requirements_files_list:
298289
for req in requirements_files_list:
299-
actions = ["install", "-r", req]
300-
if self.install_options is not None:
301-
actions += self.install_options
290+
actions = ["install", "-r", req] + (self.install_options or [])
302291
self._print_action(f"Piping: {' '.join(actions)}")
303292
self.distribution.do_pip_action(actions)
304293
self.distribution.patch_standard_packages()
@@ -386,12 +375,9 @@ def make_all(build_number: int, release_level: str, pyver: str, architecture: in
386375

387376
builder.build(rebuild=rebuild, requirements_files_list=requirements_files_list, winpy_dirname=winpython_dirname)
388377

389-
if ".zip" in create_installer.lower():
390-
builder.create_installer_7zip(".zip")
391-
if ".7z" in create_installer.lower():
392-
builder.create_installer_7zip(".7z")
393-
if "7zip" in create_installer.lower():
394-
builder.create_installer_7zip(".exe")
378+
for installer_type in [".zip", ".7z", ".exe"]:
379+
if installer_type in create_installer.lower().replace("7zip",".exe"):
380+
builder.create_installer_7zip(installer_type)
395381

396382
if __name__ == "__main__":
397383
# DO create only one Winpython distribution at a time
@@ -409,4 +395,4 @@ def make_all(build_number: int, release_level: str, pyver: str, architecture: in
409395
source_dirs=r"D:\WinPython\basedir34\packages.win-amd64",
410396
toolsdirs=r"D:\WinPython\basedir34\t.Slim",
411397
docsdirs=r"D:\WinPython\basedir34\docs.Slim",
412-
)
398+
)

0 commit comments

Comments
 (0)
0