11rem generate_a_winpython_distro.bat: to be launched from a winpython directory, where 'make.py' is
22@ echo on
33
4- REM === Step 01:Set default values if not already defined ===
4+ REM === Initialize default values ===
55if not defined my_release_level set " my_release_level = b1"
66if not defined my_create_installer set " my_create_installer = True"
77if not defined my_constraints set " my_constraints = C:\WinP\constraints.txt"
88if not defined target_python_exe set " target_python_exe = python.exe"
9+ if not defined mandatory_requirements set " mandatory_requirements = %~dp0 \mandatory_requirements.txt"
910
10- REM === Define archive directory ===
1111set " my_archive_dir = %~dp0 WinPython_build_logs"
1212if not exist " %my_archive_dir% " mkdir " %my_archive_dir% "
1313
14- REM === Format current time for use in log file ===
14+ REM === Format log timestamp ===
1515set " my_time = %time:~0 ,5 % "
1616set " my_time = %my_time:: =_ % "
1717set " my_time = %my_time: =0 % "
1818
19- REM === Define archive log file path ===
2019set " my_archive_log = %my_archive_dir% \build_%my_pyver% _%my_release%%my_flavor% _%my_release_level% _of_%date:/ =- % at_%my_time% .txt"
2120
22- REM === Step 02:Set Python version and release ===
23- if " %my_python_target% " == " 311" (
24- set " my_python_target_release = 3119"
25- set " my_release = 2"
26- ) else if " %my_python_target% " == " 312" (
27- set " my_python_target_release = 31210"
28- set " my_release = 2"
29- ) else if " %my_python_target% " == " 313" (
30- set " my_python_target_release = 3135"
31- set " my_release = 1"
32- ) else if " %my_python_target% " == " 314" (
33- set " my_python_target_release = 3140"
34- set " my_release = 1"
35- )
21+ REM === Determine Python target version ===
22+ if " %my_python_target% " == " 311" (set " my_python_target_release=3119" & set " my_release = 2" )
23+ if " %my_python_target% " == " 312" (set " my_python_target_release=31210" & set " my_release = 2" )
24+ if " %my_python_target% " == " 313" (set " my_python_target_release=3135" & set " my_release = 1" )
25+ if " %my_python_target% " == " 314" (set " my_python_target_release=3140" & set " my_release = 1" )
3626
37- REM === Step 03: Define base build and distribution paths ===
27+ REM === Define base build and distribution paths ===
3828set " my_basedir = %my_root_dir_for_builds% \bd%my_python_target% "
3929set " my_WINPYDIRBASE = %my_basedir% \bu%my_flavor% \WPy%my_arch% -%my_python_target_release%%my_release%%my_release_level% "
4030
41-
4231rem a building env need is a Python with packages: WinPython + build + flit + packaging + mkshim400.py
43- set my_buildenv = C:\WinPdev\WPy64-310111
32+ set " my_buildenv = C:\WinPdev\WPy64-310111"
4433
45- call :log_section preparing winPython for %my_pyver% (%my_python_target% )release %my_release%%m y_flavor% (%my_release_level% ) *** %my_arch% bit ***
34+ call :log_section Preparing WinPython for %my_pyver% (%my_python_target% )release %my_release%%m y_flavor% (%my_release_level% ) *** %my_arch% bit ***
4635
47- REM === Step 04: Pre- clear previous build infrastructure ===
36+ REM === Optionally clear previous build ===
4837if /i " %my_preclear_build_directory% " == " Yes" (
4938 call :log_section Pre-clear previous build infrastructure
50-
5139 REM Delete Jupyter config if it exists
52- if exist " %userprofile% \.jupyter\jupyter_notebook_config.py" (
53- del /f /q " %userprofile% \.jupyter\jupyter_notebook_config.py"
54- )
55-
56- REM Navigate to build directory
40+ del /f /q " %userprofile% \.jupyter\jupyter_notebook_config.py"
41+ REM Navigate to build directory and Rename previous build folder if it exists
5742 cd /D " %my_root_dir_for_builds% \bd%my_python_target% "
58-
59- REM Rename previous build folder if it exists
60- if exist " bu%my_flavor% " (
43+ if exist " bu%my_flavor% " (
6144 ren " bu%my_flavor% " " bu%my_flavor% _old"
6245 rmdir /s /q " bu%my_flavor% _old"
6346 )
6447)
6548
66- REM === Step 05: Create new build ===
67- call :log_section Create a new build
49+ REM === Begin Build ===
50+ call :log_section Creating Build Infrastructure
51+ call :activate_env " %my_buildenv% "
6852
69- REM Activate base build environment
70- cd /D " %~dp0 "
71- set " path = %my_original_path% "
72- call " %my_buildenv% \scripts\env.bat"
73-
74- REM Call make_all to create basic infrastructure
75- call :log_section Create basic build infrastructure
7653python.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% "
7754
7855
79- REM === Check infrastructure exists ===
80- call :log_section Check infrastructure
81-
56+ REM === Check env.bat has been created ===
8257set " WINPYDIRBASE = %my_WINPYDIRBASE% "
8358
8459if not exist " %WINPYDIRBASE% \scripts\env.bat" (
85- echo ERROR: %WINPYDIRBASE% \scripts\env.bat does not exist
86- echo Please verify:
87- echo my_arch=%my_arch%
88- echo my_python_target_release=%my_python_target_release%
89- echo my_release=%my_release%
90- echo my_release_level=%my_release_level%
60+ echo ERROR: %WINPYDIRBASE% \scripts\env.bat script not found
61+ echo Please verify: my_arch=%my_arch% my_python_target_release=%my_python_target_release%
62+ echo my_release=%my_release% my_release_level=%my_release_level%
9163 pause
9264 exit /b 1
9365)
9466
95- REM === Step 06: Add pre-requisite packages ===
96- call :log_section Add pre-requisite packages
67+ REM === Install Prerequisites ===
68+ call :pip_install " %my_WINPYDIRBASE% " " %mandatory_requirements% " " Mandatory requirements"
69+ call :pip_install " %my_WINPYDIRBASE% " " %my_requirements_pre% " " Pre-requirements"
70+ call :pip_install " %my_WINPYDIRBASE% " " %my_requirements% " " Main requirements"
9771
98- set " path = %my_original_path% "
99- call " %my_WINPYDIRBASE% \scripts\env.bat"
100-
101- rem python -m ensurepip
102- REM Upgrade essential pip tools
103- 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% "
72+ REM === Patch WinPython ===
73+ python -c " from wppm import wppm; wppm.Distribution(r'%WINPYDIR% ').patch_standard_packages('', to_movable=True)"
10474
105- REM Install additional pre-requirements if specified
106- if defined my_requirements_pre (
107- if not defined my_find_links_pre set " my_find_links_pre = %my_find_links% "
108- 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% "
109- ) else (
110- echo No pre-requisite packages specified >> " %my_archive_log% "
111- )
112-
113- REM === Step 07: Install main requirement packages ===
114- call :log_section Add main requirement packages
115- python -m pip install -r " %my_requirements% " -c " %my_constraints% " --pre --no-index --trusted-host=None --find-links=" %my_find_links% " >> " %my_archive_log% "
116-
117- REM Patch installed packages to be portable (WinPython style)
118- python -c " from wppm import wppm;dist=wppm.Distribution(r'%WINPYDIR% ');dist.patch_standard_packages('', to_movable=True)"
119-
120- REM === Step 08: Define lockfile paths for included wheels ===
75+ REM === Lock files and requirements ===
12176set " WINPYVERLOCK = %WINPYVER2:. =_ % "
12277set " LOCKDIR = %WINPYDIRBASE% \..\"
12378
@@ -126,7 +81,7 @@ set "pip_lock_includedweb=%LOCKDIR%pylock.%WINPYARCH%-%WINPYVERLOCK%%my_flavor%%
12681set " req_lock_includedlocal = %LOCKDIR% requir.%WINPYARCH% -%WINPYVERLOCK%%my_flavor%%my_release_level% _wheelslocal.txt"
12782set " req_lock_includedweb = %LOCKDIR% requir.%WINPYARCH% -%WINPYVERLOCK%%my_flavor%%my_release_level% _wheels.txt"
12883
129- REM === Step 09: Add lockfile wheels for the Wheelhouse (optional) ===
84+ REM === Add lockfile wheels for the Wheelhouse (optional) ===
13085if defined wheelhousereq if exist " %wheelhousereq% " (
13186 call :log_section Add wheels for the Wheelhouse
13287
@@ -143,11 +98,7 @@ if defined wheelhousereq if exist "%wheelhousereq%" (
14398 " %my_WINPYDIRBASE% \python\scripts\wppm.exe" " %pip_lock_includedweb% " -ws " %my_find_links% " -wd " %my_WINPYDIRBASE% \wheelhouse\included.wheels"
14499)
145100
146- rem set path=%my_original_path%
147- rem call %my_WINPYDIRBASE%\scripts\env.bat
148-
149-
150- REM === Step 10: Freeze environment and generate final lockfiles ===
101+ REM === Freeze environment and generate final lockfiles ===
151102call :log_section Freeze environment and generate lockfiles
152103
153104set " req = %LOCKDIR% requirement.%my_flavor% -%WINPYARCH% bit-%WINPYVERLOCK% _raw.txt"
@@ -188,45 +139,54 @@ copy /Y "%req_lock_web%" "%my_changelog_reqfile%"
188139
189140call :log_section Archive success
190141
191- REM === Step 11: Generate changelog and binaries ===
192- call :log_section Generate changelog and binaries
193-
194- REM Define markdown changelog filenames
195- set " mdn = WinPython%my_flavor% -%my_arch% bit-%WINPYVER2% .md"
196- set " out = WinPython%my_flavor% -%my_arch% bit-%WINPYVER2% _History.md"
197-
198- REM Create markdown package list
199- %target_python_exe% -m wppm -md > " %my_WINPYDIRBASE% \..\%mdn% "
200- copy /Y " %my_WINPYDIRBASE% \..\%mdn% " " %~dp0 changelogs\%mdn% "
142+ REM === Generate changelog and history ===
143+ call :log_section Generate changelog
144+ call :generate_changelog
201145
202- REM Generate historical diff
203- %target_python_exe% -c " from wppm import diff; result = diff.compare_package_indexes('%WINPYVER2% ', searchdir=r'%~dp0 changelogs', flavor=r'%my_flavor% ', architecture=%my_arch% ); open(r'%my_WINPYDIRBASE% \..\%out% ', 'w', encoding='utf-8').write(result)"
204- copy /Y " %my_WINPYDIRBASE% \..\%out% " " %~dp0 changelogs\%out% "
205-
206- REM === Step 13b: Compress distribution to .7z or installer ===
146+ REM === Create installer ===
147+ call :log_section Creating installer
207148set " stem = WinPython%my_arch% -%WINPYVER2%%my_flavor%%my_release_level% "
208149%target_python_exe% -c " from wppm import utils; utils.command_installer_7zip(r'%my_WINPYDIRBASE% ', r'%my_WINPYDIRBASE% \..', r'%stem% ', r'%my_create_installer% ')"
209150
210- REM === Step 12: Final logs and cleanup ===
151+ REM === Archive and cleanup ===
211152call :log_section Final logs and cleanup
212153
213- REM Restore environment
214- set " path = %my_original_path% "
215- call " %my_WINPYDIRBASE% \scripts\env.bat"
216-
217154REM Freeze final package versions to archive
218155%target_python_exe% -m pip freeze > " %my_archive_log% .packages_versions.txt"
219156
220- call :log_section END OF CREATION
221-
222157REM Open log files in Notepad for review
223158start notepad.exe " %my_archive_log% "
224159start notepad.exe " %my_archive_log% .packages_versions.txt"
160+ pause
161+ exit /b
225162
226- REM Restore path again (in case env.bat changed it)
163+ :: ----------------------------------------
164+ :activate_env
165+ cd /D " %~dp0 "
227166set " path = %my_original_path% "
228- pause
229- exit
167+ call " %~1 \scripts\env.bat"
168+ exit /b
169+
170+ :pip_install
171+ call :log_section Installing %~3
172+ call :activate_env " %~1 "
173+ if not " %~2 " == " " (
174+ python -m pip install -r " %~2 " -c " %my_constraints% " --pre --no-index --trusted-host=None --find-links=" %my_find_links% " >> " %my_archive_log% "
175+ ) else (
176+ echo No %~3 specified >> " %my_archive_log% "
177+ )
178+
179+ exit /b
180+
181+ :generate_changelog
182+ REM Create markdown file and diff history
183+ set " mdn = WinPython%my_flavor% -%my_arch% bit-%WINPYVER2% .md"
184+ set " out = WinPython%my_flavor% -%my_arch% bit-%WINPYVER2% _History.md"
185+ %target_python_exe% -m wppm -md > " %my_WINPYDIRBASE% \..\%mdn% "
186+ copy /Y " %my_WINPYDIRBASE% \..\%mdn% " " %~dp0 changelogs\%mdn% "
187+ %target_python_exe% -c " from wppm import diff; result = diff.compare_package_indexes('%WINPYVER2% ', searchdir=r'%~dp0 changelogs', flavor=r'%my_flavor% ', architecture=%my_arch% ); open(r'%my_WINPYDIRBASE% \..\%out% ', 'w', encoding='utf-8').write(result)"
188+ copy /Y " %my_WINPYDIRBASE% \..\%out% " " %~dp0 changelogs\%out% "
189+ exit /b
230190
231191:log_section
232192echo . >> %my_archive_log%
0 commit comments