Skip to content

more clean-up #1506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2025
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
51 changes: 6 additions & 45 deletions make.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,6 @@ def pre_path_entries(self) -> list[str]:
r".." + self.NODEJS_PATH_REL,
]

@property
def post_path_entries(self) -> list[str]:
"""Returns a list of PATH entries to append to the environment."""
return []

@property
def tools_directories(self) -> list[Path]:
"""Returns the list of tools directories to include."""
Expand Down Expand Up @@ -381,8 +376,7 @@ def create_installer_7zip(self, installer_type: str = ".exe"):
"""
Creates a WinPython installer using 7-Zip.

Args:
installer_type: Type of installer to create (".exe", ".7z", ".zip").
Args: installer_type: Type of installer to create (".exe", ".7z", ".zip").
"""
self._print_action(f"Creating WinPython installer ({installer_type})")
template_name = "installer_7zip.bat"
Expand All @@ -408,7 +402,6 @@ def create_installer_7zip(self, installer_type: str = ".exe"):
PORTABLE_DIR / output_name,
replacements
)
self._print_action_done()


def _print_action(self, text: str):
Expand All @@ -418,19 +411,13 @@ def _print_action(self, text: str):
else:
print(f"{text}... ", end="", flush=True)

def _print_action_done(self):
"""Prints "OK" to indicate action completion."""
if not self.verbose:
print("OK")

def _extract_python_archive(self):
"""Extracts the Python zip archive to create the base Python environment."""
self._print_action("Extracting Python archive")
utils.extract_archive(
str(self.python_zip_file),
targetdir=str(self.winpy_dir), # Extract directly to winpy_dir
)
self._print_action_done()
# Relocate to /python subfolder if needed (for newer structure) #2024-12-22 to /python
python_target_dir = self.winpy_dir / self.python_dir_name
if self.python_dir_name != self.python_name and not python_target_dir.is_dir():
Expand All @@ -450,48 +437,35 @@ def _copy_tools(self):
shutil.move(nodejs_current_dir, nodejs_target_dir)
except Exception as e:
print(f"Error moving Node.js directory: {e}")
self._print_action_done()

def _copy_documentation(self):
"""Copies documentation files to the WinPython 'docs' directory."""
docs_target_dir = self.winpy_dir / "notebooks" / "docs"
self._print_action(f"Copying documentation to {docs_target_dir}")
_copy_items(self.docs_directories, docs_target_dir, self.verbose)
self._print_action_done()


def _copy_launchers(self):
"""Copies pre-made launchers to the WinPython directory."""
self._print_action("Creating launchers")
launchers_source_dir = PORTABLE_DIR / "launchers_final"
_copy_items([launchers_source_dir], self.winpy_dir, self.verbose)
self._print_action_done()
_copy_items([PORTABLE_DIR / "launchers_final"], self.winpy_dir, self.verbose)

def _copy_default_scripts(self):
"""Copies launchers and defeult scripts."""
self._print_action("copying pre-made scripts")
origin = PORTABLE_DIR / "scripts"
destination = self.winpy_dir / "scripts"
_copy_items([origin], destination, self.verbose)
self._print_action_done()
_copy_items([PORTABLE_DIR / "scripts"], self.winpy_dir / "scripts", self.verbose)

def _create_initial_batch_scripts(self):
"""Creates initial batch scripts, including environment setup."""
self._print_action("Creating initial batch scripts")

path_entries_str = ";".join([rf"%WINPYDIR%\{pth}" for pth in self.pre_path_entries])
full_path_env_var = f"{path_entries_str};%PATH%;" + ";".join([rf"%WINPYDIR%\{pth}" for pth in self.post_path_entries])
full_path_env_var = f"{path_entries_str};%PATH%"

path_entries_ps_str = ";".join([rf"$env:WINPYDIR\\{pth}" for pth in self.pre_path_entries])
full_path_ps_env_var = f"{path_entries_ps_str};$env:path;" + ";".join([rf"$env:WINPYDIR\\{pth}" for pth in self.post_path_entries])
full_path_ps_env_var = f"{path_entries_ps_str};$env:path"

# Replacements for batch scripts (PyPy compatibility)
exe_name = self.distribution.short_exe if self.distribution else "python.exe" # default to python.exe if distribution is not yet set
batch_replacements = [
(r"DIR%\\python.exe", rf"DIR%\\{exe_name}"),
(r"DIR%\\PYTHON.EXE", rf"DIR%\\{exe_name}"),
]
if self.distribution and (Path(self.distribution.target) / r"lib-python\3\idlelib").is_dir():
batch_replacements.append((r"\Lib\idlelib", r"\lib-python\3\idlelib"))

destination = self.winpy_dir / "scripts"
for specials in ('env.bat', 'WinPython_PS_Prompt.ps1'):
Expand All @@ -501,22 +475,13 @@ def _create_initial_batch_scripts(self):
utils.patch_sourcefile(destspe,'{self.winpython_version_name}', self.winpython_version_name)
utils.patch_sourcefile(destspe,'{full_path_env_var}', full_path_env_var)
utils.patch_sourcefile(destspe,'{full_path_ps_env_var}', full_path_ps_env_var)
self._print_action_done()


def _create_standard_batch_scripts(self):
"""Creates standard WinPython batch scripts for various actions."""
self._print_action("Creating standard batch scripts")

exe_name = self.distribution.short_exe if self.distribution else "python.exe"
batch_replacements = [
(r"DIR%\\python.exe", rf"DIR%\\{exe_name}"),
(r"DIR%\\PYTHON.EXE", rf"DIR%\\{exe_name}"),
]
if self.distribution and (Path(self.distribution.target) / r"lib-python\3\idlelib").is_dir():
batch_replacements.append((r"\Lib\idlelib", r"\lib-python\3\idlelib"))

self._print_action_done()


def build(self, remove_existing: bool = True, requirements=None, winpy_dirname: str = None):
Expand Down Expand Up @@ -546,7 +511,6 @@ def build(self, remove_existing: bool = True, requirements=None, winpy_dirname:
(self.winpy_dir / "settings" / "AppData" / "Roaming").mkdir(parents=True, exist_ok=True) # Ensure settings dir exists
self._extract_python_archive()

self._print_action_done()
self.distribution = wppm.Distribution(
self.python_executable_dir,
verbose=self.verbose,
Expand Down Expand Up @@ -589,7 +553,6 @@ def build(self, remove_existing: bool = True, requirements=None, winpy_dirname:

self._print_action("Cleaning up distribution")
self.distribution.clean_up()
self._print_action_done()
# Writing package index
self._print_action("Writing package index")
# winpyver2 = the version without build part but with self.distribution.architecture
Expand All @@ -609,7 +572,6 @@ def build(self, remove_existing: bool = True, requirements=None, winpy_dirname:
fname,
str(Path(CHANGELOGS_DIR) / Path(fname).name),
)
self._print_action_done()

# Writing changelog
self._print_action("Writing changelog")
Expand All @@ -620,7 +582,6 @@ def build(self, remove_existing: bool = True, requirements=None, winpy_dirname:
release_level=self.release_level,
architecture=self.distribution.architecture,
)
self._print_action_done()


def rebuild_winpython_package(source_dir: Path, target_dir: Path, architecture: int = 64, verbose: bool = False):
Expand Down