Skip to content

DOS post simplification with openAI: modularize and simplify #1696

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 1 commit into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
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
170 changes: 65 additions & 105 deletions generate_a_winpython_distro.bat
Original file line number Diff line number Diff line change
@@ -1,123 +1,78 @@
rem generate_a_winpython_distro.bat: to be launched from a winpython directory, where 'make.py' is
@echo on

REM === Step 01:Set default values if not already defined ===
REM === Initialize default values ===
if not defined my_release_level set "my_release_level=b1"
if not defined my_create_installer set "my_create_installer=True"
if not defined my_constraints set "my_constraints=C:\WinP\constraints.txt"
if not defined target_python_exe set "target_python_exe=python.exe"
if not defined mandatory_requirements set "mandatory_requirements=%~dp0\mandatory_requirements.txt"

REM === Define archive directory ===
set "my_archive_dir=%~dp0WinPython_build_logs"
if not exist "%my_archive_dir%" mkdir "%my_archive_dir%"

REM === Format current time for use in log file ===
REM === Format log timestamp ===
set "my_time=%time:~0,5%"
set "my_time=%my_time::=_%"
set "my_time=%my_time: =0%"

REM === Define archive log file path ===
set "my_archive_log=%my_archive_dir%\build_%my_pyver%_%my_release%%my_flavor%_%my_release_level%_of_%date:/=-%at_%my_time%.txt"

REM === Step 02:Set Python version and release ===
if "%my_python_target%"=="311" (
set "my_python_target_release=3119"
set "my_release=2"
) else if "%my_python_target%"=="312" (
set "my_python_target_release=31210"
set "my_release=2"
) else if "%my_python_target%"=="313" (
set "my_python_target_release=3135"
set "my_release=1"
) else if "%my_python_target%"=="314" (
set "my_python_target_release=3140"
set "my_release=1"
)
REM === Determine Python target version ===
if "%my_python_target%"=="311" (set "my_python_target_release=3119" & set "my_release=2")
if "%my_python_target%"=="312" (set "my_python_target_release=31210" & set "my_release=2")
if "%my_python_target%"=="313" (set "my_python_target_release=3135" & set "my_release=1")
if "%my_python_target%"=="314" (set "my_python_target_release=3140" & set "my_release=1")

REM === Step 03:Define base build and distribution paths ===
REM === Define base build and distribution paths ===
set "my_basedir=%my_root_dir_for_builds%\bd%my_python_target%"
set "my_WINPYDIRBASE=%my_basedir%\bu%my_flavor%\WPy%my_arch%-%my_python_target_release%%my_release%%my_release_level%"


rem a building env need is a Python with packages: WinPython + build + flit + packaging + mkshim400.py
set my_buildenv=C:\WinPdev\WPy64-310111
set "my_buildenv=C:\WinPdev\WPy64-310111"

call :log_section preparing winPython for %my_pyver% (%my_python_target%)release %my_release%%my_flavor% (%my_release_level%) *** %my_arch% bit ***
call :log_section Preparing WinPython for %my_pyver% (%my_python_target%)release %my_release%%my_flavor% (%my_release_level%) *** %my_arch% bit ***

REM === Step 04: Pre-clear previous build infrastructure ===
REM === Optionally clear previous build ===
if /i "%my_preclear_build_directory%"=="Yes" (
call :log_section Pre-clear previous build infrastructure

REM Delete Jupyter config if it exists
if exist "%userprofile%\.jupyter\jupyter_notebook_config.py" (
del /f /q "%userprofile%\.jupyter\jupyter_notebook_config.py"
)

REM Navigate to build directory
del /f /q "%userprofile%\.jupyter\jupyter_notebook_config.py"
REM Navigate to build directory and Rename previous build folder if it exists
cd /D "%my_root_dir_for_builds%\bd%my_python_target%"

REM Rename previous build folder if it exists
if exist "bu%my_flavor%" (
if exist "bu%my_flavor%" (
ren "bu%my_flavor%" "bu%my_flavor%_old"
rmdir /s /q "bu%my_flavor%_old"
)
)

REM === Step 05: Create new build ===
call :log_section Create a new build
REM === Begin Build ===
call :log_section Creating Build Infrastructure
call :activate_env "%my_buildenv%"

REM Activate base build environment
cd /D "%~dp0"
set "path=%my_original_path%"
call "%my_buildenv%\scripts\env.bat"

REM Call make_all to create basic infrastructure
call :log_section Create basic build infrastructure
python.exe -c "from make import make_all; make_all(%my_release%, '%my_release_level%', basedir_wpy=r'%my_WINPYDIRBASE%', verbose=True, flavor='%my_flavor%', source_dirs=r'%my_source_dirs%', toolsdirs=r'%my_toolsdirs%')" >>"%my_archive_log%"


REM === Check infrastructure exists ===
call :log_section Check infrastructure

REM === Check env.bat has been created ===
set "WINPYDIRBASE=%my_WINPYDIRBASE%"

if not exist "%WINPYDIRBASE%\scripts\env.bat" (
echo ERROR: %WINPYDIRBASE%\scripts\env.bat does not exist
echo Please verify:
echo my_arch=%my_arch%
echo my_python_target_release=%my_python_target_release%
echo my_release=%my_release%
echo my_release_level=%my_release_level%
echo ERROR: %WINPYDIRBASE%\scripts\env.bat script not found
echo Please verify: my_arch=%my_arch% my_python_target_release=%my_python_target_release%
echo my_release=%my_release% my_release_level=%my_release_level%
pause
exit /b 1
)

REM === Step 06: Add pre-requisite packages ===
call :log_section Add pre-requisite packages
REM === Install Prerequisites ===
call :pip_install "%my_WINPYDIRBASE%" "%mandatory_requirements%" "Mandatory requirements"
call :pip_install "%my_WINPYDIRBASE%" "%my_requirements_pre%" "Pre-requirements"
call :pip_install "%my_WINPYDIRBASE%" "%my_requirements%" "Main requirements"

set "path=%my_original_path%"
call "%my_WINPYDIRBASE%\scripts\env.bat"

rem python -m ensurepip
REM Upgrade essential pip tools
python -m pip install --upgrade pip setuptools wheel wppm -c "%my_constraints%" --pre --no-index --trusted-host=None --find-links="%my_find_links%" >>"%my_archive_log%"
REM === Patch WinPython ===
python -c "from wppm import wppm; wppm.Distribution(r'%WINPYDIR%').patch_standard_packages('', to_movable=True)"

REM Install additional pre-requirements if specified
if defined my_requirements_pre (
if not defined my_find_links_pre set "my_find_links_pre=%my_find_links%"
python -m pip install -r "%my_requirements_pre%" -c "%my_constraints%" --pre --no-index --trusted-host=None --find-links="%my_find_links_pre%" >>"%my_archive_log%"
) else (
echo No pre-requisite packages specified >>"%my_archive_log%"
)

REM === Step 07: Install main requirement packages ===
call :log_section Add main requirement packages
python -m pip install -r "%my_requirements%" -c "%my_constraints%" --pre --no-index --trusted-host=None --find-links="%my_find_links%" >>"%my_archive_log%"

REM Patch installed packages to be portable (WinPython style)
python -c "from wppm import wppm;dist=wppm.Distribution(r'%WINPYDIR%');dist.patch_standard_packages('', to_movable=True)"

REM === Step 08: Define lockfile paths for included wheels ===
REM === Lock files and requirements ===
set "WINPYVERLOCK=%WINPYVER2:.=_%"
set "LOCKDIR=%WINPYDIRBASE%\..\"

Expand All @@ -126,7 +81,7 @@ set "pip_lock_includedweb=%LOCKDIR%pylock.%WINPYARCH%-%WINPYVERLOCK%%my_flavor%%
set "req_lock_includedlocal=%LOCKDIR%requir.%WINPYARCH%-%WINPYVERLOCK%%my_flavor%%my_release_level%_wheelslocal.txt"
set "req_lock_includedweb=%LOCKDIR%requir.%WINPYARCH%-%WINPYVERLOCK%%my_flavor%%my_release_level%_wheels.txt"

REM === Step 09: Add lockfile wheels for the Wheelhouse (optional) ===
REM === Add lockfile wheels for the Wheelhouse (optional) ===
if defined wheelhousereq if exist "%wheelhousereq%" (
call :log_section Add wheels for the Wheelhouse

Expand All @@ -143,11 +98,7 @@ if defined wheelhousereq if exist "%wheelhousereq%" (
"%my_WINPYDIRBASE%\python\scripts\wppm.exe" "%pip_lock_includedweb%" -ws "%my_find_links%" -wd "%my_WINPYDIRBASE%\wheelhouse\included.wheels"
)

rem set path=%my_original_path%
rem call %my_WINPYDIRBASE%\scripts\env.bat


REM === Step 10: Freeze environment and generate final lockfiles ===
REM === Freeze environment and generate final lockfiles ===
call :log_section Freeze environment and generate lockfiles

set "req=%LOCKDIR%requirement.%my_flavor%-%WINPYARCH%bit-%WINPYVERLOCK%_raw.txt"
Expand Down Expand Up @@ -188,45 +139,54 @@ copy /Y "%req_lock_web%" "%my_changelog_reqfile%"

call :log_section Archive success

REM === Step 11: Generate changelog and binaries ===
call :log_section Generate changelog and binaries

REM Define markdown changelog filenames
set "mdn=WinPython%my_flavor%-%my_arch%bit-%WINPYVER2%.md"
set "out=WinPython%my_flavor%-%my_arch%bit-%WINPYVER2%_History.md"

REM Create markdown package list
%target_python_exe% -m wppm -md > "%my_WINPYDIRBASE%\..\%mdn%"
copy /Y "%my_WINPYDIRBASE%\..\%mdn%" "%~dp0changelogs\%mdn%"
REM === Generate changelog and history ===
call :log_section Generate changelog
call :generate_changelog

REM Generate historical diff
%target_python_exe% -c "from wppm import diff; result = diff.compare_package_indexes('%WINPYVER2%', searchdir=r'%~dp0changelogs', flavor=r'%my_flavor%', architecture=%my_arch%); open(r'%my_WINPYDIRBASE%\..\%out%', 'w', encoding='utf-8').write(result)"
copy /Y "%my_WINPYDIRBASE%\..\%out%" "%~dp0changelogs\%out%"

REM === Step 13b: Compress distribution to .7z or installer ===
REM === Create installer ===
call :log_section Creating installer
set "stem=WinPython%my_arch%-%WINPYVER2%%my_flavor%%my_release_level%"
%target_python_exe% -c "from wppm import utils; utils.command_installer_7zip(r'%my_WINPYDIRBASE%', r'%my_WINPYDIRBASE%\..', r'%stem%', r'%my_create_installer%')"

REM === Step 12: Final logs and cleanup ===
REM === Archive and cleanup ===
call :log_section Final logs and cleanup

REM Restore environment
set "path=%my_original_path%"
call "%my_WINPYDIRBASE%\scripts\env.bat"

REM Freeze final package versions to archive
%target_python_exe% -m pip freeze > "%my_archive_log%.packages_versions.txt"

call :log_section END OF CREATION

REM Open log files in Notepad for review
start notepad.exe "%my_archive_log%"
start notepad.exe "%my_archive_log%.packages_versions.txt"
pause
exit /b

REM Restore path again (in case env.bat changed it)
:: ----------------------------------------
:activate_env
cd /D "%~dp0"
set "path=%my_original_path%"
pause
exit
call "%~1\scripts\env.bat"
exit /b

:pip_install
call :log_section Installing %~3
call :activate_env "%~1"
if not "%~2"=="" (
python -m pip install -r "%~2" -c "%my_constraints%" --pre --no-index --trusted-host=None --find-links="%my_find_links%" >>"%my_archive_log%"
) else (
echo No %~3 specified >>"%my_archive_log%"
)

exit /b

:generate_changelog
REM Create markdown file and diff history
set "mdn=WinPython%my_flavor%-%my_arch%bit-%WINPYVER2%.md"
set "out=WinPython%my_flavor%-%my_arch%bit-%WINPYVER2%_History.md"
%target_python_exe% -m wppm -md > "%my_WINPYDIRBASE%\..\%mdn%"
copy /Y "%my_WINPYDIRBASE%\..\%mdn%" "%~dp0changelogs\%mdn%"
%target_python_exe% -c "from wppm import diff; result = diff.compare_package_indexes('%WINPYVER2%', searchdir=r'%~dp0changelogs', flavor=r'%my_flavor%', architecture=%my_arch%); open(r'%my_WINPYDIRBASE%\..\%out%', 'w', encoding='utf-8').write(result)"
copy /Y "%my_WINPYDIRBASE%\..\%out%" "%~dp0changelogs\%out%"
exit /b

:log_section
echo. >>%my_archive_log%
Expand Down
5 changes: 5 additions & 0 deletions mandatory_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# the mandatory
pip
setuptools
#not Wheel
wppm