Skip to content

Commit c47c9e6

Browse files
authored
bpo-44934: Add optional feature AppendPath to Windows MSI installer (GH-27889)
The option must be enabled from the command line
1 parent 9e20ec4 commit c47c9e6

File tree

11 files changed

+107
-6
lines changed

11 files changed

+107
-6
lines changed

Doc/using/windows.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,13 @@ of available options is shown below.
165165
| CompileAll | Compile all ``.py`` files to | 0 |
166166
| | ``.pyc``. | |
167167
+---------------------------+--------------------------------------+--------------------------+
168-
| PrependPath | Add install and Scripts directories | 0 |
169-
| | to :envvar:`PATH` and ``.PY`` to | |
170-
| | :envvar:`PATHEXT` | |
168+
| PrependPath | Prepend install and Scripts | 0 |
169+
| | directories to :envvar:`PATH` and | |
170+
| | add ``.PY`` to :envvar:`PATHEXT` | |
171+
+---------------------------+--------------------------------------+--------------------------+
172+
| AppendPath | Append install and Scripts | 0 |
173+
| | directories to :envvar:`PATH` and | |
174+
| | add ``.PY`` to :envvar:`PATHEXT` | |
171175
+---------------------------+--------------------------------------+--------------------------+
172176
| Shortcuts | Create shortcuts for the interpreter,| 1 |
173177
| | documentation and IDLE if installed. | |

Doc/whatsnew/3.11.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ Other CPython Implementation Changes
200200
have been removed as their values can be derived from ``exc_value``.
201201
(Contributed by Irit Katriel in :issue:`45711`.)
202202

203+
* A new command line option for the Windows installer ``AppendPath`` has beend added.
204+
It behaves similiar to ``PrependPath`` but appends the install and scripts directories
205+
instead of prepending it.
206+
(Contributed by Bastian Neuburger in :issue:`44934`.)
207+
208+
203209
New Modules
204210
===========
205211

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The installer now offers a command-line only option to add the installation directory to the end of :envvar:`PATH` instead of at the start.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ProjectGuid>{12B59A06-37CC-4558-A9C8-DAE922E64EF3}</ProjectGuid>
5+
<SchemaVersion>2.0</SchemaVersion>
6+
<OutputName>appendpath</OutputName>
7+
<OutputType>Package</OutputType>
8+
<SuppressIces>ICE71</SuppressIces>
9+
</PropertyGroup>
10+
<Import Project="..\msi.props" />
11+
<ItemGroup>
12+
<Compile Include="*.wxs" />
13+
</ItemGroup>
14+
<ItemGroup>
15+
<EmbeddedResource Include="*.wxl" />
16+
</ItemGroup>
17+
18+
<Import Project="..\msi.targets" />
19+
</Project>

Tools/msi/appendpath/appendpath.wxs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
3+
<Product Id="*" Language="!(loc.LCID)" Name="!(loc.Title)" Version="$(var.Version)" Manufacturer="!(loc.Manufacturer)" UpgradeCode="$(var.UpgradeCode)">
4+
<Package InstallerVersion="300" Compressed="yes" InstallScope="perUser" Platform="$(var.Platform)" />
5+
6+
<PropertyRef Id="UpgradeTable" />
7+
<PropertyRef Id="REGISTRYKEY" />
8+
9+
<Feature Id="DefaultFeature" AllowAdvertise="no" Title="!(loc.Title)" Description="!(loc.Description)">
10+
<Component Id="AppendPath_CU" Directory="InstallDirectory" Guid="*">
11+
<Condition>NOT ALLUSERS=1</Condition>
12+
<RegistryKey Root="HKCU" Key="[REGISTRYKEY]">
13+
<RegistryValue KeyPath="yes" Key="InstalledFeatures" Name="$(var.OptionalFeatureName)" Value="$(var.Version)" Type="string" />
14+
</RegistryKey>
15+
16+
<CreateFolder Directory="Scripts" />
17+
<RemoveFolder Id="Remove_Scripts_CU" Directory="Scripts" On="uninstall" />
18+
19+
<Environment Id="PATH_CU" Action="set" Name="PATH" Part="last" Value="[InstallDirectory]" />
20+
<Environment Id="SCRIPTS_PATH_CU" Action="set" Name="PATH" Part="last" Value="[Scripts]" />
21+
</Component>
22+
<Component Id="AppendPath_LM" Directory="InstallDirectory" Guid="*">
23+
<Condition>ALLUSERS=1</Condition>
24+
<RegistryKey Root="HKLM" Key="[REGISTRYKEY]">
25+
<RegistryValue KeyPath="yes" Key="InstalledFeatures" Name="$(var.OptionalFeatureName)" Value="$(var.Version)" Type="string" />
26+
</RegistryKey>
27+
28+
<CreateFolder Directory="Scripts" />
29+
<RemoveFolder Id="Remove_Scripts_LM" Directory="Scripts" On="uninstall" />
30+
31+
<Environment Id="PATH_LM" Action="set" Name="PATH" Part="last" Value="[InstallDirectory]" System="yes" />
32+
<Environment Id="SCRIPTS_PATH_LM" Action="set" Name="PATH" Part="last" Value="[Scripts]" System="yes" />
33+
<Environment Id="PY_PATHEXT_LM" Action="set" Name="PATHEXT" Part="last" Value=".PY" System="yes" />
34+
<Environment Id="PYW_PATHEXT_LM" Action="set" Name="PATHEXT" Part="last" Value=".PYW" System="yes" />
35+
</Component>
36+
</Feature>
37+
</Product>
38+
</Wix>
39+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<WixLocalization Culture="en-us" xmlns="http://schemas.microsoft.com/wix/2006/localization">
3+
<String Id="Descriptor">Append to Path</String>
4+
<String Id="ShortDescriptor">AppendPath</String>
5+
<String Id="NoPython">No !(loc.ProductName) installation was detected.</String>
6+
</WixLocalization>

Tools/msi/bundle/Default.wxl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ Select Customize to review current options.</String>
8484
<String Id="ShortcutsLabel">Create shortcuts for installed applications</String>
8585
<String Id="PrependPathLabel">Add Python to &amp;environment variables</String>
8686
<String Id="ShortPrependPathLabel">Add &amp;Python [ShortVersion] to PATH</String>
87+
<String Id="AppendPathLabel">Append Python to &amp;environment variables</String>
88+
<String Id="ShortAppendPathLabel">Append &amp;Python [ShortVersion] to PATH</String>
8789
<String Id="InstallAllUsersLabel">Install for &amp;all users</String>
8890
<String Id="InstallLauncherAllUsersLabel">for &amp;all users (requires elevation)</String>
8991
<String Id="ShortInstallLauncherAllUsersLabel">Install &amp;launcher for all users (recommended)</String>

Tools/msi/bundle/bootstrap/PythonBootstrapperApplication.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ static struct { LPCWSTR regName; LPCWSTR variableName; } OPTIONAL_FEATURES[] = {
205205
{ L"exe", L"Include_exe" },
206206
{ L"lib", L"Include_lib" },
207207
{ L"path", L"PrependPath" },
208+
{ L"appendpath", L"AppendPath" },
208209
{ L"pip", L"Include_pip" },
209210
{ L"tcltk", L"Include_tcltk" },
210211
{ L"test", L"Include_test" },

Tools/msi/bundle/bundle.targets

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<Package Include="..\exe\exe*.wixproj" />
6868
<Package Include="..\lib\lib*.wixproj" />
6969
<Package Include="..\path\path*.wixproj" />
70+
<Package Include="..\appendpath\appendpath*.wixproj" />
7071
<Package Include="..\pip\pip*.wixproj" />
7172
<Package Include="..\tcltk\tcltk*.wixproj" />
7273
<Package Include="..\test\test*.wixproj" />
@@ -104,4 +105,4 @@
104105
</Target>
105106

106107
<Import Project="..\msi.targets" />
107-
</Project>
108+
</Project>

Tools/msi/bundle/bundle.wxs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0"?>
1+
<?xml version="1.0"?>
22
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
33
xmlns:bal="http://schemas.microsoft.com/wix/BalExtension"
44
xmlns:dep="http://schemas.microsoft.com/wix/DependencyExtension">
@@ -87,6 +87,7 @@
8787
<Variable Name="AssociateFiles" Value="1" bal:Overridable="yes" />
8888
<Variable Name="Shortcuts" Value="1" bal:Overridable="yes" />
8989
<Variable Name="PrependPath" Value="0" bal:Overridable="yes" />
90+
<Variable Name="AppendPath" Value="0" bal:Overridable="yes" />
9091
<Variable Name="CompileAll" Value="0" bal:Overridable="yes" />
9192

9293
<Variable Name="SimpleInstall" Value="0" bal:Overridable="yes" />

Tools/msi/bundle/packagegroups/postinstall.wxs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,27 @@
2020
<MsiProperty Name="TARGETDIR" Value="[TargetDir]" />
2121
<MsiProperty Name="OPTIONALFEATURESREGISTRYKEY" Value="[OptionalFeaturesRegistryKey]" />
2222
</MsiPackage>
23+
24+
<MsiPackage Id="appendpath_AllUsers"
25+
SourceFile="appendpath.msi"
26+
Compressed="$(var.CompressMSI)"
27+
DownloadUrl="$(var.DownloadUrl)"
28+
ForcePerMachine="yes"
29+
InstallCondition="InstallAllUsers and AppendPath and not LauncherOnly">
30+
<MsiProperty Name="TARGETDIR" Value="[TargetDir]" />
31+
<MsiProperty Name="OPTIONALFEATURESREGISTRYKEY" Value="[OptionalFeaturesRegistryKey]" />
32+
</MsiPackage>
33+
<MsiPackage Id="appendpath_JustForMe"
34+
SourceFile="appendpath.msi"
35+
Compressed="$(var.CompressMSI)"
36+
DownloadUrl="$(var.DownloadUrl)"
37+
ForcePerMachine="no"
38+
InstallCondition="not InstallAllUsers and AppendPath and not LauncherOnly">
39+
<MsiProperty Name="TARGETDIR" Value="[TargetDir]" />
40+
<MsiProperty Name="OPTIONALFEATURESREGISTRYKEY" Value="[OptionalFeaturesRegistryKey]" />
41+
</MsiPackage>
42+
43+
2344

2445
<?define CompileAllCommand=-E -s -Wi "[TargetDir]\Lib\compileall.py" -f -x "bad_coding|badsyntax|site-packages|py2_|lib2to3\\tests|venv\\scripts" "[TargetDir]\Lib"?>
2546
<ExePackage Id="compileall_AllUsers"
@@ -85,4 +106,4 @@
85106
InstallCondition="not InstallAllUsers and CompileAll and not LauncherOnly" />
86107
</PackageGroup>
87108
</Fragment>
88-
</Wix>
109+
</Wix>

0 commit comments

Comments
 (0)