Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f3125fe

Browse files
committed
improve variable names via AI flash2 thinking
1 parent 9760fc9 commit f3125fe

File tree

1 file changed

+55
-56
lines changed

1 file changed

+55
-56
lines changed

make.py

+55-56
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __init__(
189189
self.flavor = flavor
190190
self.python_zip_file: Path = self._get_python_zip_file()
191191
self.python_name = self.python_zip_file.stem # Filename without extension
192-
self.python_dir_name = "python" # Standardized Python directory name
192+
self.python_directory_name = "python" # Standardized Python directory name
193193

194194
def _get_python_zip_file(self) -> Path:
195195
"""Finds the Python .zip file in the wheels directory."""
@@ -241,8 +241,8 @@ def _get_installed_tools_markdown(self) -> str:
241241
"""Generates Markdown for installed tools section in package index."""
242242
installed_tools = []
243243

244-
def get_tool_path(rel_path):
245-
path = self.winpython_directory / rel_path if self.winpython_directory else None
244+
def get_tool_path(relative_path):
245+
path = self.winpython_directory / relative_path if self.winpython_directory else None
246246
return path if path and (path.is_file() or path.is_dir()) else None
247247

248248
nodejs_path = get_tool_path(self.NODEJS_RELATIVE_PATH)
@@ -272,7 +272,7 @@ def get_tool_path(rel_path):
272272
def _get_installed_packages_markdown(self) -> str:
273273
"""Generates Markdown for installed packages section in package index."""
274274
if self.distribution is None:
275-
return "" # Distribution not initialized yet.
275+
return "" # Distribution not initialized yet.
276276
self.installed_packages = self.distribution.get_installed_packages(update=True)
277277
package_lines = [
278278
f"[{pkg.name}]({pkg.url}) | {pkg.version} | {pkg.description}"
@@ -296,14 +296,14 @@ def python_full_version(self) -> str:
296296
return utils.get_python_long_version(self.distribution.target)
297297

298298
@property
299-
def python_executable_dir(self) -> str:
299+
def python_executable_directory(self) -> str:
300300
"""Returns the directory containing the Python executable."""
301-
python_path_dir = self.winpython_directory / self.python_dir_name if self.winpython_directory else None
302-
if python_path_dir and python_path_dir.is_dir():
303-
return str(python_path_dir)
301+
python_path_directory = self.winpython_directory / self.python_directory_name if self.winpython_directory else None
302+
if python_path_directory and python_path_directory.is_dir():
303+
return str(python_path_directory)
304304
else:
305-
python_path_exe = self.winpython_directory / self.python_name if self.winpython_directory else None # Fallback for older structure
306-
return str(python_path_exe) if python_path_exe else ""
305+
python_path_executable = self.winpython_directory / self.python_name if self.winpython_directory else None # Fallback for older structure
306+
return str(python_path_executable) if python_path_executable else ""
307307

308308
@property
309309
def architecture_bits(self) -> int:
@@ -325,11 +325,11 @@ def pre_path_entries(self) -> list[str]:
325325
]
326326

327327
@property
328-
def docs_directories(self) -> list[Path]:
328+
def documentation_directories_list(self) -> list[Path]:
329329
"""Returns the list of documentation directories to include."""
330-
default_docs_dir = Path(__file__).resolve().parent / "docs"
331-
if default_docs_dir.is_dir():
332-
return [default_docs_dir] + self.documentation_directories
330+
default_docs_directory = Path(__file__).resolve().parent / "docs"
331+
if default_docs_directory.is_dir():
332+
return [default_docs_directory] + self.documentation_directories
333333
return self.documentation_directories
334334

335335
def create_batch_script(self, name: str, contents: str, replacements: list[tuple[str, str]] = None):
@@ -341,21 +341,20 @@ def create_batch_script(self, name: str, contents: str, replacements: list[tuple
341341
contents: The contents of the batch script.
342342
replacements: A list of tuples for text replacements in the content.
343343
"""
344-
script_dir = self.winpython_directory / "scripts" if self.winpython_directory else None
345-
if not script_dir:
344+
script_directory = self.winpython_directory / "scripts" if self.winpython_directory else None
345+
if not script_directory:
346346
print("Warning: WinPython directory not set, cannot create batch script.")
347347
return
348-
script_dir.mkdir(parents=True, exist_ok=True)
348+
script_directory.mkdir(parents=True, exist_ok=True)
349349
final_contents = contents
350350
if replacements:
351351
for old_text, new_text in replacements:
352352
final_contents = final_contents.replace(old_text, new_text)
353-
script_path = script_dir / name
353+
script_path = script_directory / name
354354
with open(script_path, "w") as f:
355355
f.write(final_contents)
356356
print(f"Created batch script: {script_path}")
357357

358-
359358
def create_installer_7zip(self, installer_type: str = ".exe"):
360359
"""
361360
Creates a WinPython installer using 7-Zip.
@@ -399,63 +398,63 @@ def _extract_python_archive(self):
399398
targetdir=str(self.winpython_directory), # Extract directly to winpython_directory
400399
)
401400
# Relocate to /python subfolder if needed (for newer structure) #2024-12-22 to /python
402-
python_target_dir = self.winpython_directory / self.python_dir_name
403-
if self.python_dir_name != self.python_name and not python_target_dir.is_dir():
404-
os.rename(self.winpython_directory / self.python_name, python_target_dir)
401+
expected_python_directory = self.winpython_directory / self.python_directory_name
402+
if self.python_directory_name != self.python_name and not expected_python_directory.is_dir():
403+
os.rename(self.winpython_directory / self.python_name, expected_python_directory)
405404

406405
def _copy_tools(self):
407406
"""Copies development tools to the WinPython 't' directory."""
408-
tools_target_dir = self.winpython_directory / "t"
409-
self._print_action(f"Copying tools to {tools_target_dir}")
410-
_copy_items(self.tools_directories, tools_target_dir, self.verbose)
407+
tools_target_directory = self.winpython_directory / "t"
408+
self._print_action(f"Copying tools to {tools_target_directory}")
409+
_copy_items(self.tools_directories, tools_target_directory, self.verbose)
411410

412411
# Special handling for Node.js to move it up one level
413-
nodejs_current_dir = tools_target_dir / "n"
414-
nodejs_target_dir = self.winpython_directory / self.NODEJS_RELATIVE_PATH
415-
if nodejs_current_dir != nodejs_target_dir and nodejs_current_dir.is_dir():
412+
nodejs_current_directory = tools_target_directory / "n"
413+
nodejs_target_directory = self.winpython_directory / self.NODEJS_RELATIVE_PATH
414+
if nodejs_current_directory != nodejs_target_directory and nodejs_current_directory.is_dir():
416415
try:
417-
shutil.move(nodejs_current_dir, nodejs_target_dir)
416+
shutil.move(nodejs_current_directory, nodejs_target_directory)
418417
except Exception as e:
419418
print(f"Error moving Node.js directory: {e}")
420419

421420
def _copy_documentation(self):
422421
"""Copies documentation files to the WinPython 'docs' directory."""
423-
docs_target_dir = self.winpython_directory / "notebooks" / "docs"
424-
self._print_action(f"Copying documentation to {docs_target_dir}")
425-
_copy_items(self.docs_directories, docs_target_dir, self.verbose)
426-
422+
docs_target_directory = self.winpython_directory / "notebooks" / "docs"
423+
self._print_action(f"Copying documentation to {docs_target_directory}")
424+
_copy_items(self.documentation_directories_list, docs_target_directory, self.verbose)
425+
427426
def _copy_launchers(self):
428427
"""Copies pre-made launchers to the WinPython directory."""
429428
self._print_action("Creating launchers")
430429
_copy_items([PORTABLE_DIRECTORY / "launchers_final"], self.winpython_directory, self.verbose)
431430

432431
def _copy_default_scripts(self):
433-
"""Copies launchers and defeult scripts."""
432+
"""Copies launchers and default scripts."""
434433
self._print_action("copying pre-made scripts")
435434
_copy_items([PORTABLE_DIRECTORY / "scripts"], self.winpython_directory / "scripts", self.verbose)
436-
435+
437436
def _create_initial_batch_scripts(self):
438437
"""Creates initial batch scripts, including environment setup."""
439438
self._print_action("Creating initial batch scripts")
440439

441-
path_entries_str = ";".join([rf"%WINPYDIR%\{pth}" for pth in self.pre_path_entries])
442-
full_path_env_var = f"{path_entries_str};%PATH%"
440+
path_entries_string = ";".join([rf"%WINPYDIR%\{path}" for path in self.pre_path_entries])
441+
full_path_environment_variable = f"{path_entries_string};%PATH%"
443442

444-
path_entries_ps_str = ";".join([rf"$env:WINPYDIR\\{pth}" for pth in self.pre_path_entries])
445-
full_path_ps_env_var = f"{path_entries_ps_str};$env:path"
443+
path_entries_powershell_string = ";".join([rf"$env:WINPYDIR\\{path}" for path in self.pre_path_entries])
444+
full_path_powershell_environment_variable = f"{path_entries_powershell_string};$env:path"
446445

447446
# Replacements for batch scripts (PyPy compatibility)
448-
exe_name = self.distribution.short_exe if self.distribution else "python.exe" # default to python.exe if distribution is not yet set
447+
executable_name = self.distribution.short_exe if self.distribution else "python.exe" # default to python.exe if distribution is not yet set
449448

450449
destination = self.winpython_directory / "scripts"
451-
for specials in ('env.bat', 'WinPython_PS_Prompt.ps1'):
452-
destspe=str(destination / specials)
453-
print('destspe:', destspe)
454-
utils.patch_sourcefile(destspe,'{self.python_dir_name}', self.python_dir_name)
455-
utils.patch_sourcefile(destspe,'{self.winpython_version_name}', self.winpython_version_name)
456-
utils.patch_sourcefile(destspe,'{full_path_env_var}', full_path_env_var)
457-
utils.patch_sourcefile(destspe,'{full_path_ps_env_var}', full_path_ps_env_var)
458-
450+
for script_name in ('env.bat', 'WinPython_PS_Prompt.ps1'):
451+
destination_script_path = str(destination / script_name)
452+
print('destination_script_path:', destination_script_path)
453+
utils.patch_sourcefile(destination_script_path, 'python.exe', executable_name)
454+
utils.patch_sourcefile(destination_script_path, '{self.python_dir_name}', self.python_directory_name)
455+
utils.patch_sourcefile(destination_script_path, '{self.winpython_version_name}', self.winpython_version_name)
456+
utils.patch_sourcefile(destination_script_path, '{full_path_env_var}', full_path_environment_variable)
457+
utils.patch_sourcefile(destination_script_path,'{full_path_ps_env_var}', full_path_powershell_environment_variable)
459458

460459
def build(self, rebuild: bool = True, requirements=None, winpy_dirname: str = None):
461460
"""Make WinPython distribution in target directory from the installers
@@ -485,7 +484,7 @@ def build(self, rebuild: bool = True, requirements=None, winpy_dirname: str = No
485484
self._extract_python_archive()
486485

487486
self.distribution = wppm.Distribution(
488-
self.python_executable_dir,
487+
self.python_executable_directory,
489488
verbose=self.verbose,
490489
indent=True,
491490
)
@@ -528,11 +527,11 @@ def build(self, rebuild: bool = True, requirements=None, winpy_dirname: str = No
528527
self._print_action("Writing package index")
529528
# winpyver2 = the version without build part but with self.distribution.architecture
530529
self.winpyver2 = f"{self.python_full_version}.{self.build_number}"
531-
fname = str(self.winpython_directory.parent / f"WinPython{self.flavor}-{self.distribution.architecture}bit-{self.winpyver2}.md")
532-
open(fname, "w", encoding='utf-8').write(self.package_index_markdown)
530+
output_markdown_filename = str(self.winpython_directory.parent / f"WinPython{self.flavor}-{self.distribution.architecture}bit-{self.winpyver2}.md")
531+
open(output_markdown_filename, "w", encoding='utf-8').write(self.package_index_markdown)
533532

534533
# Copy to winpython/changelogs
535-
shutil.copyfile(fname, str(Path(CHANGELOGS_DIRECTORY) / Path(fname).name))
534+
shutil.copyfile(output_markdown_filename, str(Path(CHANGELOGS_DIRECTORY) / Path(output_markdown_filename).name))
536535

537536
# Writing changelog
538537
self._print_action("Writing changelog")
@@ -594,22 +593,22 @@ def make_all(
594593
docs_dirs_list = _parse_list_argument(docsdirs, ",")
595594
install_options_list = _parse_list_argument(install_options, " ")
596595
find_links_dirs_list = _parse_list_argument(find_links, ",")
597-
requirements_files_list = [Path(f) for f in _parse_list_argument(requirements, ",") if f] # ensure Path objects
596+
requirements_files_list = [Path(f) for f in _parse_list_argument(requirements, ",") if f] # ensure Path objects
598597
find_links_options = [f"--find-links={link}" for link in find_links_dirs_list + [source_dirs]]
599-
builddir = str(Path(basedir) / ("bu" + flavor))
598+
build_directory = str(Path(basedir) / ("bu" + flavor))
600599

601600
if rebuild:
602601
# Rebuild Winpython Wheel Package
603602
utils.print_box(f"Making WinPython {architecture}bits at {Path(basedir) / ('bu' + flavor)}")
604-
os.makedirs(Path(builddir), exist_ok=True)
603+
os.makedirs(Path(build_directory), exist_ok=True)
605604
# use source_dirs as the directory to re-build Winpython wheel
606605
winpython_source_dir = Path(__file__).resolve().parent
607606
rebuild_winpython_package(winpython_source_dir, source_dirs, architecture, verbose)
608607

609608
builder = WinPythonDistributionBuilder(
610609
build_number,
611610
release_level,
612-
builddir,
611+
build_directory,
613612
wheels_directory=source_dirs,
614613
tools_directories=[Path(d) for d in tools_dirs_list],
615614
documentation_directories=[Path(d) for d in docs_dirs_list],

0 commit comments

Comments
 (0)