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

Skip to content

Commit ca08175

Browse files
committed
use AI Gemini Flash2 thinking intermediate thoughts
1 parent f3125fe commit ca08175

File tree

2 files changed

+49
-83
lines changed

2 files changed

+49
-83
lines changed

make.py

+47-78
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,22 @@ def _extract_python_archive(self):
401401
expected_python_directory = self.winpython_directory / self.python_directory_name
402402
if self.python_directory_name != self.python_name and not expected_python_directory.is_dir():
403403
os.rename(self.winpython_directory / self.python_name, expected_python_directory)
404+
405+
def _copy_essential_files(self):
406+
"""Copies pre-made objects"""
407+
self._print_action("Copying default scripts")
408+
_copy_items([PORTABLE_DIRECTORY / "scripts"], self.winpython_directory / "scripts", self.verbose)
409+
410+
self._print_action("Copying launchers")
411+
_copy_items([PORTABLE_DIRECTORY / "launchers_final"], self.winpython_directory, self.verbose)
412+
413+
docs_target_directory = self.winpython_directory / "notebooks" / "docs"
414+
self._print_action(f"Copying documentation to {docs_target_directory}")
415+
_copy_items(self.documentation_directories_list, docs_target_directory, self.verbose)
404416

405-
def _copy_tools(self):
406-
"""Copies development tools to the WinPython 't' directory."""
407417
tools_target_directory = self.winpython_directory / "t"
408418
self._print_action(f"Copying tools to {tools_target_directory}")
409-
_copy_items(self.tools_directories, tools_target_directory, self.verbose)
419+
_copy_items(self.tools_directories, self.winpython_directory / "t", self.verbose)
410420

411421
# Special handling for Node.js to move it up one level
412422
nodejs_current_directory = tools_target_directory / "n"
@@ -417,22 +427,6 @@ def _copy_tools(self):
417427
except Exception as e:
418428
print(f"Error moving Node.js directory: {e}")
419429

420-
def _copy_documentation(self):
421-
"""Copies documentation files to the WinPython 'docs' directory."""
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-
426-
def _copy_launchers(self):
427-
"""Copies pre-made launchers to the WinPython directory."""
428-
self._print_action("Creating launchers")
429-
_copy_items([PORTABLE_DIRECTORY / "launchers_final"], self.winpython_directory, self.verbose)
430-
431-
def _copy_default_scripts(self):
432-
"""Copies launchers and default scripts."""
433-
self._print_action("copying pre-made scripts")
434-
_copy_items([PORTABLE_DIRECTORY / "scripts"], self.winpython_directory / "scripts", self.verbose)
435-
436430
def _create_initial_batch_scripts(self):
437431
"""Creates initial batch scripts, including environment setup."""
438432
self._print_action("Creating initial batch scripts")
@@ -456,45 +450,33 @@ def _create_initial_batch_scripts(self):
456450
utils.patch_sourcefile(destination_script_path, '{full_path_env_var}', full_path_environment_variable)
457451
utils.patch_sourcefile(destination_script_path,'{full_path_ps_env_var}', full_path_powershell_environment_variable)
458452

459-
def build(self, rebuild: bool = True, requirements=None, winpy_dirname: str = None):
460-
"""Make WinPython distribution in target directory from the installers
461-
located in wheels_directory
462-
463-
rebuild=True: (default) install all from scratch
464-
rebuild=False: for complementary purposes (create installers)
465-
requirements=file(s) of requirements (separated by space if several)"""
453+
def build(self, rebuild: bool = True, requirements_files_list=None, winpy_dirname: str = None):
454+
"""Make or finalise WinPython distribution in the target directory"""
455+
466456
python_zip_filename = self.python_zip_file.name
467457
print(f"Building WinPython with Python archive: {python_zip_filename}")
468458

469459
if winpy_dirname is None:
470460
raise RuntimeError("WinPython base directory to create is undefined")
471461
else:
472462
self.winpython_directory = self.target_directory / winpy_dirname # Create/re-create the WinPython base directory
473-
self._print_action(f"Creating WinPython {self.winpython_directory} base directory")
474-
if self.winpython_directory.is_dir() and rebuild:
475-
try:
476-
shutil.rmtree(self.winpython_directory, onexc=utils.onerror)
477-
except TypeError: # before 3.12
478-
shutil.rmtree(self.winpython_directory, onerror=utils.onerror)
479-
os.makedirs(self.winpython_directory, exist_ok=True)
480463
if rebuild:
464+
self._print_action(f"Creating WinPython {self.winpython_directory} base directory")
465+
if self.winpython_directory.is_dir():
466+
try:
467+
shutil.rmtree(self.winpython_directory, onexc=utils.onerror)
468+
except TypeError: # before 3.12
469+
shutil.rmtree(self.winpython_directory, onerror=utils.onerror)
470+
os.makedirs(self.winpython_directory, exist_ok=True)
481471
# preventive re-Creation of settings directory
482-
# (necessary if user is starting an application with a batch)
483-
(self.winpython_directory / "settings" / "AppData" / "Roaming").mkdir(parents=True, exist_ok=True) # Ensure settings dir exists
472+
(self.winpython_directory / "settings" / "AppData" / "Roaming").mkdir(parents=True, exist_ok=True)
484473
self._extract_python_archive()
485474

486-
self.distribution = wppm.Distribution(
487-
self.python_executable_directory,
488-
verbose=self.verbose,
489-
indent=True,
490-
)
475+
self.distribution = wppm.Distribution(self.python_executable_directory, verbose=self.verbose)
491476

492477
if rebuild:
493-
self._copy_default_scripts()
478+
self._copy_essential_files()
494479
self._create_initial_batch_scripts()
495-
self._copy_launchers()
496-
self._copy_tools()
497-
self._copy_documentation()
498480

499481
utils.python_execmodule("ensurepip", self.distribution.target) # Ensure pip is installed for PyPy
500482
self.distribution.patch_standard_packages("pip")
@@ -503,53 +485,40 @@ def build(self, rebuild: bool = True, requirements=None, winpy_dirname: str = No
503485
essential_packages = ["pip", "setuptools", "wheel", "winpython"]
504486
for package_name in essential_packages:
505487
actions = ["install", "--upgrade", "--pre", package_name] + self.install_options
506-
print(f"Piping: {' '.join(actions)}")
507488
self._print_action(f"Piping: {' '.join(actions)}")
508489
self.distribution.do_pip_action(actions)
509490
self.distribution.patch_standard_packages(package_name)
510491

511-
if requirements:
512-
if not isinstance(requirements, list):
513-
requirements = requirements.split(",")
514-
for req in requirements:
515-
actions = ["install", "-r", req]
516-
if self.install_options is not None:
517-
actions += self.install_options
518-
print(f"piping {' '.join(actions)}")
519-
self._print_action(f"piping {' '.join(actions)}")
520-
self.distribution.do_pip_action(actions)
521-
492+
if requirements_files_list:
493+
for req in requirements_files_list:
494+
actions = ["install", "-r", req]
495+
if self.install_options is not None:
496+
actions += self.install_options
497+
self._print_action(f"piping {' '.join(actions)}")
498+
self.distribution.do_pip_action(actions)
522499
self.distribution.patch_standard_packages()
523500

524-
self._print_action("Cleaning up distribution")
525-
self.distribution.clean_up()
501+
self._print_action("Cleaning up distribution")
502+
self.distribution.clean_up() # still usefull ?
526503
# Writing package index
527504
self._print_action("Writing package index")
528505
# winpyver2 = the version without build part but with self.distribution.architecture
529506
self.winpyver2 = f"{self.python_full_version}.{self.build_number}"
530507
output_markdown_filename = str(self.winpython_directory.parent / f"WinPython{self.flavor}-{self.distribution.architecture}bit-{self.winpyver2}.md")
531508
open(output_markdown_filename, "w", encoding='utf-8').write(self.package_index_markdown)
532509

533-
# Copy to winpython/changelogs
534-
shutil.copyfile(output_markdown_filename, str(Path(CHANGELOGS_DIRECTORY) / Path(output_markdown_filename).name))
535-
536510
# Writing changelog
537511
self._print_action("Writing changelog")
538-
diff.write_changelog(
539-
self.winpyver2,
540-
basedir=self.base_directory,
541-
flavor=self.flavor,
542-
release_level=self.release_level,
543-
architecture=self.distribution.architecture,
544-
)
512+
shutil.copyfile(output_markdown_filename, str(Path(CHANGELOGS_DIRECTORY) / Path(output_markdown_filename).name))
513+
diff.write_changelog(self.winpyver2, None, self.base_directory, self.flavor, self.release_level, self.distribution.architecture)
545514

546515

547-
def rebuild_winpython_package(source_dir: Path, target_directory: Path, architecture: int = 64, verbose: bool = False):
516+
def rebuild_winpython_package(source_directory: Path, target_directory: Path, architecture: int = 64, verbose: bool = False):
548517
"""Rebuilds the winpython package from source using flit."""
549518
for filename in os.listdir(target_directory):
550519
if filename.startswith("winpython-") and filename.endswith((".exe", ".whl", ".gz")):
551520
os.remove(Path(target_directory) / filename)
552-
utils.buildflit_wininst(source_dir, copy_to=target_directory, verbose=verbose)
521+
utils.buildflit_wininst(source_directory, copy_to=target_directory, verbose=verbose)
553522

554523

555524
def make_all(
@@ -618,19 +587,19 @@ def make_all(
618587
flavor=flavor,
619588
)
620589
# define the directory where to create the distro
621-
my_x = "".join(builder.python_name.replace(".amd64", "").split(".")[-2:-1])
622-
while not my_x.isdigit() and len(my_x) > 0:
623-
my_x = my_x[:-1]
590+
python_minor_version_str = "".join(builder.python_name.replace(".amd64", "").split(".")[-2:-1])
591+
while not python_minor_version_str.isdigit() and len(python_minor_version_str) > 0:
592+
python_minor_version_str = python_minor_version_str[:-1]
624593
# simplify for PyPy
625-
if not python_target_release == None:
626-
winpy_dirname = f"WPy{architecture}-{python_target_release}{build_number}{release_level}"
594+
if python_target_release is not None:
595+
winpython_dirname = f"WPy{architecture}-{python_target_release}{build_number}{release_level}"
627596
else:
628-
winpy_dirname = f"WPy{architecture}-{pyver.replace('.', '')}{my_x}{build_number}{release_level}"
597+
winpython_dirname = f"WPy{architecture}-{pyver.replace('.', '')}{python_minor_version_str}{build_number}{release_level}"
629598

630599
builder.build(
631600
rebuild=rebuild,
632-
requirements=requirements_files_list,
633-
winpy_dirname=winpy_dirname,
601+
requirements_files_list=requirements_files_list,
602+
winpy_dirname=winpython_dirname,
634603
)
635604
if ".zip" in str(create_installer).lower():
636605
builder.create_installer_7zip(".zip")

winpython/wppm.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,10 @@ def __str__(self):
4949

5050

5151
class Distribution:
52-
def __init__(self, target=None, verbose=False, indent=False):
52+
def __init__(self, target=None, verbose=False):
5353
# if no target path given, take the current python interpreter one
5454
self.target = target or os.path.dirname(sys.executable)
5555
self.verbose = verbose
56-
self.indent = indent
5756
self.pip = None
5857
self.to_be_removed = [] # list of directories to be removed later
5958
self.version, self.architecture = utils.get_python_infos(target)
@@ -376,9 +375,7 @@ def _print(self, package, action):
376375
if self.verbose:
377376
utils.print_box(text)
378377
else:
379-
if self.indent:
380-
text = (" " * 4) + text
381-
print(text + "...", end=" ")
378+
print(" " + text + "...", end=" ")
382379

383380
def _print_done(self):
384381
"""Print OK at the end of a process"""

0 commit comments

Comments
 (0)